github.com/code-visible/golang@v0.0.0-20240214000051-0f9c587b0b32/utils/fs_test.go (about) 1 package utils 2 3 import ( 4 "os" 5 "testing" 6 ) 7 8 func TestMustDir(t *testing.T) { 9 if MustDir("fs.go") == nil { 10 t.Fail() 11 } 12 if MustDir("..") != nil { 13 t.Fail() 14 } 15 } 16 17 func TestCountGoFiles(t *testing.T) { 18 list, err := ListGoFiles("../utils", true) 19 if err != nil { 20 t.Error(err) 21 } 22 if len(list) != 2 { 23 t.Fail() 24 } 25 list, err = ListGoFiles("../utils", false) 26 if err != nil { 27 t.Error(err) 28 } 29 if len(list) != 1 { 30 t.Fail() 31 } 32 } 33 34 func TestListDirs(t *testing.T) { 35 _ = os.Chdir("../testdata") 36 list := ListDirs("multifiles", true) 37 if len(list) != 1 { 38 t.Fail() 39 } 40 }