Skip to content

Commit 2e2b872

Browse files
author
Miguel Molina
authored
Merge pull request #165 from nkovacs/vendored
Fix generator when kallax is vendored
2 parents 5b49619 + a6cde56 commit 2e2b872

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

generator/processor.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,12 @@ func removeGoPath(path string) string {
506506
for _, p := range parseutil.DefaultGoPath {
507507
p = toSlash(p + "/src/")
508508
if strings.HasPrefix(path, p) {
509-
return prefix + strings.Replace(path, p, "", -1)
509+
// Directories named "vendor" are only vendor directories
510+
// if they're under $GOPATH/src.
511+
if idx := strings.LastIndex(path, "/vendor/"); idx >= len(p)-1 {
512+
return prefix + path[idx+8:]
513+
}
514+
return prefix + path[len(p):]
510515
}
511516
}
512517
return prefix + path

generator/processor_test.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func (s *ProcessorSuite) TestIsModel() {
356356
Ptr *Bar
357357
NoPtr Bar
358358
Struct Struct
359-
}
359+
}
360360
`
361361
pkg := s.processFixture(src)
362362
m := findModel(pkg, "Foo")
@@ -401,7 +401,7 @@ func (s *ProcessorSuite) TestIsEmbedded() {
401401
C struct {
402402
D int
403403
}
404-
}
404+
}
405405
`
406406
pkg := s.processFixture(src)
407407
m := findModel(pkg, "Foo")
@@ -457,6 +457,41 @@ func TestRemoveGoPath(t *testing.T) {
457457
},
458458
'/',
459459
},
460+
{
461+
"/go/src/foo/go/src/fixtures.AliasString",
462+
"foo/go/src/fixtures.AliasString",
463+
[]string{
464+
"/go",
465+
},
466+
'/',
467+
},
468+
{
469+
"/home/workspace/gopath/src/foo/bar/vendor/gopkg.in/src-d/go-kallax.v1/tests/fixtures.AliasString",
470+
"gopkg.in/src-d/go-kallax.v1/tests/fixtures.AliasString",
471+
[]string{
472+
"/home/foo/go",
473+
"/home/workspace/gopath",
474+
},
475+
'/',
476+
},
477+
{
478+
"/home/vendor/workspace/gopath/src/gopkg.in/src-d/go-kallax.v1/tests/fixtures.AliasString",
479+
"gopkg.in/src-d/go-kallax.v1/tests/fixtures.AliasString",
480+
[]string{
481+
"/home/foo/go",
482+
"/home/vendor/workspace/gopath",
483+
},
484+
'/',
485+
},
486+
{
487+
"/home/vendor/workspace/gopath/src/vendor/gopkg.in/src-d/go-kallax.v1/tests/fixtures.AliasString",
488+
"gopkg.in/src-d/go-kallax.v1/tests/fixtures.AliasString",
489+
[]string{
490+
"/home/foo/go",
491+
"/home/vendor/workspace/gopath",
492+
},
493+
'/',
494+
},
460495
}
461496

462497
for _, c := range cases {

0 commit comments

Comments
 (0)