Skip to content

Commit

Permalink
Merge pull request #136 from nkovacs/vendored-package-fix
Browse files Browse the repository at this point in the history
Fix importing of vendored packages
  • Loading branch information
joefitzgerald authored Jul 19, 2019
2 parents 35e91c8 + 4b91f4b commit f85ca4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion generator/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package generator

import (
"fmt"
"go/build"
"go/types"
"log"
"path/filepath"
"reflect"
"strings"

Expand All @@ -19,11 +21,19 @@ func (f *Fake) loadPackages(c Cacher, workingDir string) error {
log.Printf("loaded %v packages from cache\n", len(f.Packages))
return nil
}
importPath := f.TargetPackage
if !filepath.IsAbs(importPath) {
bp, err := build.Import(f.TargetPackage, workingDir, build.FindOnly)
if err != nil {
return err
}
importPath = bp.ImportPath
}
p, err := packages.Load(&packages.Config{
Mode: packages.NeedName | packages.NeedFiles | packages.NeedImports | packages.NeedDeps | packages.NeedTypes,
Dir: workingDir,
Tests: true,
}, f.TargetPackage)
}, importPath)
if err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions integration/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration_test

import (
"fmt"
"go/build"
"io/ioutil"
"log"
"os"
Expand All @@ -22,6 +23,7 @@ func runTests(useGopath bool, t *testing.T, when spec.G, it spec.S) {
baseDir string
relativeDir string
originalGopath string
originalBuildGopath string
originalGo111module string
testDir string
copyDirFunc func()
Expand All @@ -44,11 +46,14 @@ func runTests(useGopath bool, t *testing.T, when spec.G, it spec.S) {
os.Setenv("GO111MODULE", "on")
}
originalGopath = os.Getenv("GOPATH")
originalBuildGopath = build.Default.GOPATH
var err error
testDir, err = ioutil.TempDir("", "counterfeiter-integration")
Expect(err).NotTo(HaveOccurred())
if useGopath {
os.Setenv("GOPATH", testDir)
// build.Default only reads the GOPATH env variable once on init
build.Default.GOPATH = testDir
} else {
os.Unsetenv("GOPATH")
}
Expand Down Expand Up @@ -103,6 +108,7 @@ func runTests(useGopath bool, t *testing.T, when spec.G, it spec.S) {
} else {
os.Unsetenv("GOPATH")
}
build.Default.GOPATH = originalBuildGopath
if baseDir == "" {
return
}
Expand Down

0 comments on commit f85ca4b

Please sign in to comment.