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