-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests_utils.go
144 lines (103 loc) · 3.04 KB
/
tests_utils.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package onearchiver
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
)
func getTestMocksAsset(_filePath string) string {
currentDir, err := os.Getwd()
if err != nil {
log.Panicf("\nunable to fetch the current directory: %s\n", currentDir)
}
resultPath := fmt.Sprintf("%s/tests/mocks/", currentDir)
resultPath = fmt.Sprintf("%s%s", resultPath, _filePath)
if exist := exists(resultPath); !exist {
log.Panicf("\nthe 'mocks' asset not found: %s\n", resultPath)
}
return resultPath
}
func newTestMocksAsset(_filePath string) string {
currentDir, err := os.Getwd()
if err != nil {
log.Panicf("\nunable to fetch the current directory: %s\n", currentDir)
}
resultPath := fmt.Sprintf("%s/tests/mocks/", currentDir)
resultPath = fmt.Sprintf("%s%s", resultPath, _filePath)
return resultPath
}
func newTempMocksAsset(_filePath string) string {
currentDir, err := os.Getwd()
if err != nil {
log.Panicf("\nunable to fetch the current directory: %s\nerror: %+v\n", currentDir, err)
}
resultPath := fmt.Sprintf("%s/tests/mocks-build/", currentDir)
if exist := isDirectory(resultPath); !exist {
_, err := os.Create(resultPath)
if err != nil {
log.Panicf("\n'mocks-build' directory not found: %s\nerror: %+v\n", resultPath, err)
}
}
resultPath = fmt.Sprintf("%s%s", resultPath, _filePath)
return resultPath
}
func newTempMocksDir(_dirPath string, resetDir bool) string {
currentDir, err := os.Getwd()
if err != nil {
log.Panicf("\nunable to fetch the current directory: %s\nerror: %+v\n", currentDir, err)
}
resultPath := filepath.Join(currentDir, "tests/mocks-build", _dirPath)
if resetDir {
err := os.RemoveAll(resultPath)
if err != nil {
log.Panic(err)
}
if exist := isDirectory(resultPath); !exist {
err = os.MkdirAll(resultPath, os.ModePerm)
if err != nil {
log.Panicf("\ntemp mocks directory not found: %s\nerror: %+v\n", resultPath, err)
}
}
}
if exist := isDirectory(resultPath); !exist {
err := os.MkdirAll(resultPath, os.ModePerm)
if err != nil {
log.Panicf("\ntemp mocks directory not found: %s\nerror: %+v\n", resultPath, err)
}
}
return resultPath
}
func listUnpackedDirectory(destination string) []string {
var filePathList []filePathListSortInfo
err := filepath.Walk(destination, func(path string, info os.FileInfo, err error) error {
if destination == path {
return nil
}
var pathSplitted [2]string
if !info.IsDir() {
pathSplitted = [2]string{filepath.Dir(path), filepath.Base(path)}
} else {
path = fixDirSlash(true, path)
_dir := filepath.Dir(path)
pathSplitted = [2]string{_dir, ""}
}
filePathList = append(filePathList, filePathListSortInfo{
IsDir: info.IsDir(),
FullPath: path,
splittedPaths: pathSplitted,
})
return nil
})
if err != nil {
log.Fatal(err)
}
_sortPath(&filePathList, OrderDirAsc)
var itemsArr []string
for _, x := range filePathList {
_path := strings.Replace(x.FullPath, destination, "", -1)
_path = strings.TrimLeft(_path, "/")
itemsArr = append(itemsArr, _path)
}
return itemsArr
}