From 18ffdb433ef7b57c6775517b2f8e867b500bb135 Mon Sep 17 00:00:00 2001 From: Levin Alexander Date: Mon, 5 Oct 2015 22:10:45 +0200 Subject: [PATCH 1/2] Use array of test cases for ProjectPackages --- configuration_test.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/configuration_test.go b/configuration_test.go index f6d70d31..440a68d2 100644 --- a/configuration_test.go +++ b/configuration_test.go @@ -45,20 +45,24 @@ func TestNotifyReleaseStages(t *testing.T) { } func TestProjectPackages(t *testing.T) { + Configure(Configuration{ProjectPackages: []string{"main", "github.com/ConradIrwin/*"}}) - if !Config.isProjectPackage("main") { - t.Error("literal project package doesn't work") - } - if !Config.isProjectPackage("github.com/ConradIrwin/foo") { - t.Error("wildcard project package doesn't work") - } - if Config.isProjectPackage("runtime") { - t.Error("wrong packges being marked in project") - } - if Config.isProjectPackage("github.com/ConradIrwin/foo/bar") { - t.Error("wrong packges being marked in project") + + var testCases = []struct { + Path string + Included bool + }{ + {"main", true}, + {"github.com/ConradIrwin/foo", true}, + {"github.com/ConradIrwin/foo/bar", false}, + {"runtime", false}, } + for _, s := range testCases { + if Config.isProjectPackage(s.Path) != s.Included { + t.Error("literal project package doesn't work") + } + } } type LoggoWrapper struct { From 4022835e079c00fa18a95f53d78c9242dc698029 Mon Sep 17 00:00:00 2001 From: Levin Alexander Date: Mon, 5 Oct 2015 22:13:33 +0200 Subject: [PATCH 2/2] ProjectPackages: more comprehensive tests --- configuration_test.go | 63 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/configuration_test.go b/configuration_test.go index 440a68d2..38a54d07 100644 --- a/configuration_test.go +++ b/configuration_test.go @@ -44,23 +44,76 @@ func TestNotifyReleaseStages(t *testing.T) { } } -func TestProjectPackages(t *testing.T) { +func TestIsProjectPackage(t *testing.T) { - Configure(Configuration{ProjectPackages: []string{"main", "github.com/ConradIrwin/*"}}) + Configure(Configuration{ProjectPackages: []string{ + "main", + "star*", + "example.com/a", + "example.com/b/*", + "example.com/c/*/*", + }}) var testCases = []struct { Path string Included bool }{ + {"", false}, {"main", true}, - {"github.com/ConradIrwin/foo", true}, - {"github.com/ConradIrwin/foo/bar", false}, {"runtime", false}, + + {"star", true}, + {"sta", false}, + {"starred", true}, + {"star/foo", false}, + + {"example.com/a", true}, + + {"example.com/b", false}, + {"example.com/b/", true}, + {"example.com/b/foo", true}, + {"example.com/b/foo/bar", false}, + + {"example.com/c/foo/bar", true}, + {"example.com/c/foo/bar/baz", false}, } for _, s := range testCases { if Config.isProjectPackage(s.Path) != s.Included { - t.Error("literal project package doesn't work") + t.Error("literal project package doesn't work:", s.Path, s.Included) + } + } +} + +func TestStripProjectPackage(t *testing.T) { + + Configure(Configuration{ProjectPackages: []string{ + "main", + "star*", + "example.com/a", + "example.com/b/*", + "example.com/c/*/*", + }}) + + var testCases = []struct { + File string + Stripped string + }{ + {"main.go", "main.go"}, + {"runtime.go", "runtime.go"}, + {"star.go", "star.go"}, + + {"example.com/a/foo.go", "foo.go"}, + + {"example.com/b/foo/bar.go", "foo/bar.go"}, + {"example.com/b/foo.go", "foo.go"}, + + {"example.com/x/a/b/foo.go", "example.com/x/a/b/foo.go"}, + } + + for _, tc := range testCases { + if s := Config.stripProjectPackages(tc.File); s != tc.Stripped { + t.Error("stripProjectPackage did not remove expected path:", tc.File, tc.Stripped, "was:", s) } } }