Merge pull request #65 from dmbreaker/FIX_VENDOR

Remove vendor path from imports. PkgPath() workaround.
This commit is contained in:
Victor Starodub
2016-10-11 00:53:32 +04:00
committed by GitHub
2 changed files with 26 additions and 0 deletions
+10
View File
@@ -199,8 +199,18 @@ func (g *Generator) Run(out io.Writer) error {
return err
}
// fixes vendored paths
func fixPkgPathVendoring(pkgPath string) string {
const vendor = "/vendor/"
if i := strings.LastIndex(pkgPath, vendor); i != -1 {
return pkgPath[i+len(vendor):]
}
return pkgPath
}
// pkgAlias creates and returns and import alias for a given package.
func (g *Generator) pkgAlias(pkgPath string) string {
pkgPath = fixPkgPathVendoring(pkgPath)
if alias := g.imports[pkgPath]; alias != "" {
return alias
}
+16
View File
@@ -47,3 +47,19 @@ func TestJoinFunctionNameParts(t *testing.T) {
}
}
}
func TestFixVendorPath(t *testing.T) {
for i, test := range []struct {
In, Out string
}{
{"", ""},
{"time", "time"},
{"project/vendor/subpackage", "subpackage"},
} {
got := fixPkgPathVendoring(test.In)
if got != test.Out {
t.Errorf("[%d] fixPkgPathVendoring(%s) = %s; want %s", i, test.In, got, test.Out)
}
}
}