-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtesting_utils.go
executable file
·93 lines (85 loc) · 2.22 KB
/
testing_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
package jin
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
)
// WriteFile is NOT FOR PUBLIC USAGE.
// This function is created for test-case creation automation
// Please do not change any thing. And do not use them.
func writeFile(filedir string, buffer []byte) {
err := ioutil.WriteFile(filedir, buffer, 0666)
if err != nil {
fmt.Printf("File Write Error:%v\n", err)
}
}
// ReadFile is NOT FOR PUBLIC USAGE.
// This function is created for test-case creation automation
// Please do not change any thing. And do not use them.
func readFile(dir string) []byte {
buff, err := ioutil.ReadFile(dir)
if err != nil {
fmt.Printf("Read File Error:%v\n", err)
return nil
}
return buff
}
// ExecuteNode is NOT FOR PUBLIC USAGE.
// This function is created for test-case creation automation
// Please do not change any thing. And do not use them.
func executeBin(first string, args ...string) (string, error) {
cmd := exec.Command(first, args...)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
return out.String(), err
}
return out.String(), nil
}
// Dir is NOT FOR PUBLIC USAGE.
// This function is created for test-case creation automation
// Please do not change any thing. And do not use them.
func getFileNames(dir string) []string {
files := make([]string, 0, 100)
err := filepath.Walk(dir, func(path string, _ os.FileInfo, err error) error {
if err != nil {
return err
}
files = append(files, strings.TrimPrefix(path, dir))
return nil
})
if err != nil {
fmt.Println("Error walking true path", err)
}
return files[1:]
}
// GetCurrentDir is NOT FOR PUBLIC USAGE.
// This function is created for test-case creation automation
// Please do not change any thing. And do not use them.
func getCurrentDir() string {
wd, _ := os.Getwd()
return wd
}
// Sep is NOT FOR PUBLIC USAGE.
// This function is created for test-case creation automation
// Please do not change any thing. And do not use them.
func sep() string {
return string(os.PathSeparator)
}
// string array comparison function
func stringArrayEqual(arr1, arr2 []string) bool {
if len(arr1) != len(arr2) {
return false
}
for i, e1 := range arr1 {
if e1 != arr2[i] {
return false
}
}
return true
}