github.com/comcast/canticle@v0.0.0-20161108184242-c53cface56e8/canticles/pkg_test.go (about) 1 package canticles 2 3 import ( 4 "os" 5 "reflect" 6 "testing" 7 ) 8 9 func TestPackageIsRemote(t *testing.T) { 10 imp := "github.comcast.com/viper-cog/canticle" 11 if !IsRemote(imp) { 12 t.Errorf("Import %s not marked as remote", imp) 13 } 14 15 imp = "io" 16 if IsRemote(imp) { 17 t.Errorf("Import %s marked as remote", imp) 18 } 19 20 } 21 22 func TestPackageRemoteImports(t *testing.T) { 23 pkg := &Package{ 24 Imports: []string{ 25 "github.comcast.com/viper-cog/canticle/canticle", 26 "github.comcast.com/viper-cog/canticle/test", 27 "io", 28 "fmt", 29 }, 30 TestImports: []string{ 31 "testing", 32 "github.comcast.com/viper-cog/assert", 33 }, 34 } 35 36 expected := []string{ 37 "github.comcast.com/viper-cog/canticle/canticle", 38 "github.comcast.com/viper-cog/canticle/test", 39 } 40 imps := pkg.RemoteImports(false) 41 if !reflect.DeepEqual(imps, expected) { 42 t.Errorf("Package remote imports: %v != %v", expected, imps) 43 } 44 45 imps = pkg.RemoteImports(true) 46 expected = []string{ 47 "github.comcast.com/viper-cog/canticle/canticle", 48 "github.comcast.com/viper-cog/canticle/test", 49 "github.comcast.com/viper-cog/assert", 50 } 51 if !reflect.DeepEqual(imps, expected) { 52 t.Errorf("Package remote imports: %v != %v", expected, imps) 53 } 54 } 55 56 func TestLoadPackage(t *testing.T) { 57 pkgPath := "github.com/Comcast/Canticle/cant" 58 gp, err := EnvGoPath() 59 if err != nil { 60 t.Fatalf("Could not load gopath %s", err.Error()) 61 } 62 pkg, err := LoadPackage(pkgPath, gp) 63 if err != nil { 64 t.Errorf("Error %s loading package information for valid package", err.Error()) 65 } 66 if pkg == nil { 67 t.Errorf("Loaded pkg not as expected") 68 return 69 } 70 71 if pkg.ImportPath != pkgPath { 72 t.Errorf("Loaded incorrect package, got %s != %s", pkg.ImportPath, pkgPath) 73 } 74 75 pkgPath = "nothere.comcast.com/nothere" 76 pkg, err = LoadPackage(pkgPath, os.ExpandEnv("$GOPATH")) 77 if err == nil { 78 t.Errorf("No error loading invalid package") 79 } 80 if pkg != nil { 81 t.Errorf("Loaded pkg not as expected") 82 return 83 } 84 85 }