Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor tests for stripProjectPackages #24

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 68 additions & 11 deletions configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,78 @@ 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")
func TestIsProjectPackage(t *testing.T) {

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},
{"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},
}
if Config.isProjectPackage("runtime") {
t.Error("wrong packges being marked in project")

for _, s := range testCases {
if Config.isProjectPackage(s.Path) != s.Included {
t.Error("literal project package doesn't work:", s.Path, s.Included)
}
}
if Config.isProjectPackage("github.com/ConradIrwin/foo/bar") {
t.Error("wrong packges being marked in project")
}

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"},

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if these test cases should be included (they would fail right now)

{"example.com/c/foo/bar.go", "foo/bar.go"}, 
{"example.com/c/foo/bar/baz.go", "foo/bar/baz.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)
}
}
}

type LoggoWrapper struct {
Expand Down