github.com/ztcjoe93/ucd@v0.1.1/main_test.go (about) 1 package main 2 3 import ( 4 "os" 5 "testing" 6 ) 7 8 func TestRepeatFn(t *testing.T) { 9 str1 := repeat("..", 4) 10 str2 := repeat(".", 2) 11 12 if str1 != "../../../.." { 13 t.Fatalf(`repeat fn does not create 4 sub-paths for str1`) 14 } 15 16 if str2 != "./." { 17 t.Fatalf(`repeat fn does not create 2 sub-paths for str2`) 18 } 19 } 20 21 func TestIsInvalidPath(t *testing.T) { 22 invalidPath := "doanfkjzx/sdfj931/sdfkjal" 23 err := os.Chdir(invalidPath) 24 if err == nil { 25 t.Fatalf(`Path doanfkjzx/sdfj931/sdfkjal exists`) 26 } 27 28 val := isInvalidPath(invalidPath) 29 30 if val != true { 31 t.Fatalf(`InvalidPath returns true`) 32 } 33 } 34 35 func TestPrependStrSlice(t *testing.T) { 36 sl := []string{"apple", "banana"} 37 38 sl = prependStrSlice(sl, "cookie") 39 if len(sl) != 3 { 40 t.Fatalf(`Slice of string is not incremented`) 41 } 42 43 if sl[0] != "cookie" { 44 t.Fatalf(`cookie is not prepended to slice`) 45 } 46 }