forked from arsmn/fastgql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 99designs#151 from qdentity/fix-longer-gopath
Fix bug with multiple GOPATH full package name resolving
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package codegen | ||
|
||
import ( | ||
"go/build" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_fullPackageName(t *testing.T) { | ||
origBuildContext := build.Default | ||
defer func() { build.Default = origBuildContext }() | ||
|
||
t.Run("gopath longer than package name", func(t *testing.T) { | ||
build.Default.GOPATH = "/a/src/xxxxxxxxxxxxxxxxxxxxxxxx:/b/src/y" | ||
var got string | ||
ok := assert.NotPanics(t, func() { got = fullPackageName("/b/src/y/foo/bar", "bar") }) | ||
if ok { | ||
assert.Equal(t, "/b/src/y/foo/bar", got) | ||
} | ||
}) | ||
t.Run("stop searching on first hit", func(t *testing.T) { | ||
build.Default.GOPATH = "/a/src/x:/b/src/y" | ||
|
||
var got string | ||
ok := assert.NotPanics(t, func() { got = fullPackageName("/a/src/x/foo/bar", "bar") }) | ||
if ok { | ||
assert.Equal(t, "/a/src/x/foo/bar", got) | ||
} | ||
}) | ||
} |