github.com/upyun/upx@v0.4.7-0.20240419023638-b184a7cb7c10/tree_test.go (about) 1 package upx 2 3 import ( 4 "fmt" 5 "strings" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestTree(t *testing.T) { 12 base := ROOT + "/ls" 13 dirs, files := []string{}, []string{} 14 15 func() { 16 SetUp() 17 Upx("mkdir", base) 18 Upx("cd", base) 19 20 for i := 0; i < 11; i++ { 21 Upx("mkdir", fmt.Sprintf("dir%d", i)) 22 dirs = append(dirs, fmt.Sprintf("dir%d", i)) 23 } 24 25 CreateFile("FILE") 26 for i := 0; i < 5; i++ { 27 Upx("put", "FILE", fmt.Sprintf("FILE%d", i)) 28 files = append(files, fmt.Sprintf("FILE%d", i)) 29 } 30 }() 31 32 defer func() { 33 TearDown() 34 }() 35 36 tree1, err := Upx("tree") 37 assert.NoError(t, err) 38 tree1s := string(tree1) 39 arr := strings.Split(tree1s, "\n") 40 assert.Equal(t, len(arr), len(dirs)+len(files)+4) 41 pwd, _ := Upx("pwd") 42 assert.Equal(t, arr[0]+"\n", string(pwd)) 43 assert.Equal(t, arr[len(arr)-3], "") 44 assert.Equal(t, arr[len(arr)-2], fmt.Sprintf("%d directories, %d files", len(dirs), len(files))) 45 46 tree2, err := Upx("tree", base) 47 assert.NoError(t, err) 48 assert.Equal(t, string(tree2), string(tree1)) 49 }