Rewrite test so it tests the right thing.
Since both return values are now checked explicitly, remove check that
the concatinated package path matches the original input, since it
won't always (the point of this function is to normalize input).
diff --git a/util/normalizename_test.go b/util/normalizename_test.go
index 8f2c0f5..a4fdac5 100644
--- a/util/normalizename_test.go
+++ b/util/normalizename_test.go
@@ -5,18 +5,44 @@
)
func TestNormalizeName(t *testing.T) {
- packages := map[string]string{
- "github.com/Masterminds/cookoo/web/io/foo": "github.com/Masterminds/cookoo",
- `github.com\Masterminds\cookoo\web\io\foo`: "github.com/Masterminds/cookoo",
- "golang.org/x/crypto/ssh": "golang.org/x/crypto",
- "incomplete/example": "incomplete/example",
- "net": "net",
+ packages := []struct {
+ input string
+ root string
+ extra string
+ }{
+ {
+ input: "github.com/Masterminds/cookoo/web/io/foo",
+ root: "github.com/Masterminds/cookoo",
+ extra: "web/io/foo",
+ },
+ {
+ input: `github.com\Masterminds\cookoo\web\io\foo`,
+ root: "github.com/Masterminds/cookoo",
+ extra: "web/io/foo",
+ },
+ {
+ input: "golang.org/x/crypto/ssh",
+ root: "golang.org/x/crypto",
+ extra: "ssh",
+ },
+ {
+ input: "incomplete/example",
+ root: "incomplete/example",
+ extra: "",
+ },
+ {
+ input: "net",
+ root: "net",
+ extra: "",
+ },
}
- for start, expected := range packages {
- if finish, extra := NormalizeName(start); expected != finish {
- t.Errorf("Expected '%s', got '%s'", expected, finish)
- } else if start != finish && start != finish+"/"+extra {
- t.Errorf("Expected %s to end with %s", finish, extra)
+ for _, test := range packages {
+ root, extra := NormalizeName(test.input)
+ switch {
+ case root != test.root:
+ t.Errorf("%s: Expected root '%s', got '%s'", test.input, test.root, root)
+ case extra != test.extra:
+ t.Errorf("%s: Expected extra '%s', got '%s'", test.input, test.extra, extra)
}
}
}