github.com/invisiblethreat/glide@v0.12.3/path/path_test.go (about) 1 package path 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 ) 8 9 const testdata = "../testdata/path" 10 11 func TestGlideWD(t *testing.T) { 12 wd := filepath.Join(testdata, "a/b/c") 13 found, err := GlideWD(wd) 14 if err != nil { 15 t.Errorf("Failed to get Glide directory: %s", err) 16 } 17 18 if found != filepath.Join(testdata, "a") { 19 t.Errorf("Expected %s to match %s", found, filepath.Join(wd, "a")) 20 } 21 22 // This should fail 23 wd = "/No/Such/Dir" 24 found, err = GlideWD(wd) 25 if err == nil { 26 t.Errorf("Expected to get an error on a non-existent directory, not %s", found) 27 } 28 29 } 30 31 func TestVendor(t *testing.T) { 32 td, err := filepath.Abs(testdata) 33 if err != nil { 34 t.Fatal(err) 35 } 36 wd, _ := os.Getwd() 37 38 os.Chdir(filepath.Join(td, "a/b/c")) 39 res, err := Vendor() 40 if err != nil { 41 t.Errorf("Failed to resolve vendor directory: %s", err) 42 } 43 expect := filepath.Join(td, "a", "vendor") 44 if res != expect { 45 t.Errorf("Failed to find vendor: expected %s got %s", expect, res) 46 } 47 48 os.Chdir(filepath.Join(td, "x/y/z")) 49 res, err = Vendor() 50 if err != nil { 51 t.Errorf("Failed to resolve vendor directory: %s", err) 52 } 53 expect = filepath.Join(td, "x", "symlinked_vendor") 54 if res != expect { 55 t.Errorf("Failed to find vendor: expected %s got %s", expect, res) 56 } 57 58 os.Chdir(wd) 59 } 60 func TestGlide(t *testing.T) { 61 wd, _ := os.Getwd() 62 td, err := filepath.Abs(testdata) 63 if err != nil { 64 t.Fatal(err) 65 } 66 os.Chdir(filepath.Join(td, "a/b/c")) 67 res, err := Glide() 68 if err != nil { 69 t.Errorf("Failed to resolve vendor directory: %s", err) 70 } 71 expect := filepath.Join(td, "a", "glide.yaml") 72 if res != expect { 73 t.Errorf("Failed to find vendor: expected %s got %s", expect, res) 74 } 75 os.Chdir(wd) 76 }