local_parse_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package parser
  2. import (
  3. "testing"
  4. )
  5. func TestImportBuildPackage(t *testing.T) {
  6. b := New()
  7. if _, err := b.importBuildPackage("go-common/app/tool/gengo/testdata/fake/dep"); err != nil {
  8. t.Fatal(err)
  9. }
  10. if _, ok := b.buildPackages["go-common/app/tool/gengo/testdata/fake/dep"]; !ok {
  11. t.Errorf("missing expected, but got %v", b.buildPackages)
  12. }
  13. if len(b.buildPackages) > 1 {
  14. // this would happen if the canonicalization failed to normalize the path
  15. // you'd get a go-common/app/tool/gengo/testdata/fake/dep key too
  16. t.Errorf("missing one, but got %v", b.buildPackages)
  17. }
  18. }
  19. func TestCanonicalizeImportPath(t *testing.T) {
  20. tcs := []struct {
  21. name string
  22. input string
  23. output string
  24. }{
  25. {
  26. name: "passthrough",
  27. input: "github.com/foo/bar",
  28. output: "github.com/foo/bar",
  29. },
  30. {
  31. name: "simple",
  32. input: "github.com/foo/vendor/k8s.io/kubernetes/pkg/api",
  33. output: "k8s.io/kubernetes/pkg/api",
  34. },
  35. {
  36. name: "deeper",
  37. input: "github.com/foo/bar/vendor/k8s.io/kubernetes/pkg/api",
  38. output: "k8s.io/kubernetes/pkg/api",
  39. },
  40. }
  41. for _, tc := range tcs {
  42. actual := canonicalizeImportPath(tc.input)
  43. if string(actual) != tc.output {
  44. t.Errorf("%v: expected %q got %q", tc.name, tc.output, actual)
  45. }
  46. }
  47. }