You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
package parser |
|
|
|
import ( |
|
"testing" |
|
) |
|
|
|
func TestImportBuildPackage(t *testing.T) { |
|
b := New() |
|
if _, err := b.importBuildPackage("go-common/app/tool/gengo/testdata/fake/dep"); err != nil { |
|
t.Fatal(err) |
|
} |
|
if _, ok := b.buildPackages["go-common/app/tool/gengo/testdata/fake/dep"]; !ok { |
|
t.Errorf("missing expected, but got %v", b.buildPackages) |
|
} |
|
|
|
if len(b.buildPackages) > 1 { |
|
// this would happen if the canonicalization failed to normalize the path |
|
// you'd get a go-common/app/tool/gengo/testdata/fake/dep key too |
|
t.Errorf("missing one, but got %v", b.buildPackages) |
|
} |
|
} |
|
|
|
func TestCanonicalizeImportPath(t *testing.T) { |
|
tcs := []struct { |
|
name string |
|
input string |
|
output string |
|
}{ |
|
{ |
|
name: "passthrough", |
|
input: "github.com/foo/bar", |
|
output: "github.com/foo/bar", |
|
}, |
|
{ |
|
name: "simple", |
|
input: "github.com/foo/vendor/k8s.io/kubernetes/pkg/api", |
|
output: "k8s.io/kubernetes/pkg/api", |
|
}, |
|
{ |
|
name: "deeper", |
|
input: "github.com/foo/bar/vendor/k8s.io/kubernetes/pkg/api", |
|
output: "k8s.io/kubernetes/pkg/api", |
|
}, |
|
} |
|
|
|
for _, tc := range tcs { |
|
actual := canonicalizeImportPath(tc.input) |
|
if string(actual) != tc.output { |
|
t.Errorf("%v: expected %q got %q", tc.name, tc.output, actual) |
|
} |
|
} |
|
}
|
|
|