github.com/mh-cbon/glide@v0.0.0-20160602131809-5865b8e8ded6/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 os.Chdir(filepath.Join(td, "a/b/c")) 38 res, err := Vendor() 39 if err != nil { 40 t.Errorf("Failed to resolve vendor directory: %s", err) 41 } 42 expect := filepath.Join(td, "a", "vendor") 43 if res != expect { 44 t.Errorf("Failed to find vendor: expected %s got %s", expect, res) 45 } 46 os.Chdir(wd) 47 } 48 func TestGlide(t *testing.T) { 49 wd, _ := os.Getwd() 50 td, err := filepath.Abs(testdata) 51 if err != nil { 52 t.Fatal(err) 53 } 54 os.Chdir(filepath.Join(td, "a/b/c")) 55 res, err := Glide() 56 if err != nil { 57 t.Errorf("Failed to resolve vendor directory: %s", err) 58 } 59 expect := filepath.Join(td, "a", "glide.yaml") 60 if res != expect { 61 t.Errorf("Failed to find vendor: expected %s got %s", expect, res) 62 } 63 os.Chdir(wd) 64 }