2017-05-05 08:06:27 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2017-05-14 10:27:15 +00:00
|
|
|
"strings"
|
2017-05-05 08:06:27 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFindExistingPackage(t *testing.T) {
|
|
|
|
path := findPackage("github.com/spf13/cobra")
|
|
|
|
if path == "" {
|
|
|
|
t.Fatal("findPackage didn't find the existing package")
|
|
|
|
}
|
|
|
|
if !hasGoPathPrefix(path) {
|
2017-05-05 08:09:59 +00:00
|
|
|
t.Fatalf("%q is not in GOPATH, but must be", path)
|
2017-05-05 08:06:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func hasGoPathPrefix(path string) bool {
|
|
|
|
for _, srcPath := range srcPaths {
|
2017-05-14 10:27:15 +00:00
|
|
|
if strings.HasPrefix(path, srcPath) {
|
2017-05-05 08:06:27 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|