-
Notifications
You must be signed in to change notification settings - Fork 1
/
tree_test.go
72 lines (61 loc) · 1.94 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"os"
"testing"
)
func TestTree(t *testing.T) {
assertDirIsNotExist := func(t *testing.T, path string) {
t.Helper()
_, err := os.Stat(path)
if !os.IsNotExist(err) {
t.Errorf("Repository already cloned or directory exists")
}
}
assertCorrectDirStructure := func(t *testing.T, got, want string) {
t.Helper()
if got != want {
t.Errorf("\ngot:\n%s \nwant:\n%s", got, want)
}
}
t.Run("two dirs with files", func(t *testing.T) {
got := "path-to-dir"
want := "path-to-dir"
assertCorrectDirStructure(t, got, want)
})
t.Run("one dir with one file", func(t *testing.T) {
got := "service-1\n└── generic-service.yml"
want := "service-1\n└── generic-service.yml"
assertCorrectDirStructure(t, got, want)
})
t.Run("should clone given repo to local dir", func(t *testing.T) {
var c serverConf
config := c.getConf("config.yml")
url := config.Server.Git.URL
localRepositoryPath := config.Server.Git.LocalRepositoryPath
assertDirIsNotExist(t, localRepositoryPath)
cloneConfigRepo(localRepositoryPath, url)
})
/* t.Run("root dir should has empty parentDir", func(t *testing.T) {
cd := config{}
cd.path = ".filesystem-repo/service-1"
tree := buildTree(".filesystem-repo/service-1")
if tree.parentDir != nil {
t.Errorf("\ngot:\n%s \nwant:\nnil", tree.parentDir)
}
}) */
/* t.Run("non-root dir should has parentDir", func(t *testing.T) {
cd := configDirectory{}
cd.currentDirPath = "I'am parent"
tree := tree(".filesystem-repo/service-1", &cd)
got := tree.parentDir.currentDirPath
want := "I'am parent"
assertCorrectDirStructure(t, got, want)
}) */
/* t.Run("print directory with one layer", func(t *testing.T) {
files := []string{"file-1", "file-2", "file-3"}
cd := configDirectory{"test", nil, files, nil}
got := wipPrintDirWithTreeChars(&cd)
want := "test\n├── file-1\n├── file-2\n└── file-3\n"
assertCorrectDirStructure(t, got, want)
}) */
}