-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.go
75 lines (61 loc) · 1.44 KB
/
testing.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
package main
import (
"path/filepath"
"testing"
)
// the dir to make for tests
const TestDir = "testground"
// path of file to create and its permission
type PairPathPerm struct {
Path string
Perm int
}
// prefix a path with test directory path
func inTestDir(path string) string {
return filepath.Join(TestDir, path)
}
// compare two exe slices and return true if they are the same
func equalExeList(t *testing.T, listA []Exe, listB []Exe) (equal bool) {
t.Helper()
if len(listA) != len(listB) {
return false
}
for i := range listA {
if listA[i].Name != listB[i].Name {
return false
} else if listA[i].Path != listB[i].Path {
return false
}
}
return true
}
// compare two lists of errors
func equalErrorList(t *testing.T, listA []error, listB []error) (equal bool) {
t.Helper()
if len(listA) != len(listB) {
return false
}
for i := range listA {
if listA[i] != nil && listB[i] != nil {
// as none of them is nil compare error string
if listA[i].Error() != listB[i].Error() {
return false
}
} else {
// otherwise just compare type since one of them
if listA[i] != listB[i] {
return false
}
}
}
return true
}
// print out an error with expected and gotten values
func errorExpGot(t *testing.T, expected, gotten interface{}, isErr bool) {
t.Helper()
if isErr {
t.Error("\nExpectedErr:", expected, "\nGottenErr:", gotten)
} else {
t.Error("\nExpected:", expected, "\nGotten:", gotten)
}
}