-
Notifications
You must be signed in to change notification settings - Fork 2
/
import_common_test.go
89 lines (78 loc) · 1.51 KB
/
import_common_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package goef
import (
"bytes"
"io/ioutil"
"os"
"testing"
"github.com/siongui/goef/mytestpkg"
)
func isInArray(array []string, item string) bool {
for _, i := range array {
if i == item {
return true
}
}
return false
}
func CommonImportTest(t *testing.T) {
a1, err := ioutil.ReadFile("testdir/hello.txt")
if err != nil {
t.Error(err)
return
}
a2, err := ioutil.ReadFile("testdir/backtick.txt")
if err != nil {
t.Error(err)
return
}
a3, err := ioutil.ReadFile("testdir/subdir/hello2.txt")
if err != nil {
t.Error(err)
return
}
b, err := mytestpkg.ReadFile("hello.txt")
if err != nil {
t.Error(err)
return
}
if !bytes.Equal(a1, b) {
t.Error("hello.txt content not correct")
return
}
b, err = mytestpkg.ReadFile("backtick.txt")
if err != nil {
t.Error(err)
return
}
if !bytes.Equal(a2, b) {
t.Error("backtick.txt content not correct")
return
}
b, err = mytestpkg.ReadFile("subdir/hello2.txt")
if err != nil {
t.Error(err)
return
}
if !bytes.Equal(a3, b) {
t.Error("subdir/hello2.txt content not correct")
return
}
_, err = mytestpkg.ReadFile("hello3.txt")
if err != os.ErrNotExist {
t.Error("hello3.txt should not exit!")
return
}
filenames := mytestpkg.MapKeys()
if !isInArray(filenames, "hello.txt") {
t.Error("hello.txt not in MapKeys")
return
}
if !isInArray(filenames, "backtick.txt") {
t.Error("backtick.txt not in MapKeys")
return
}
if !isInArray(filenames, "subdir/hello2.txt") {
t.Error("subdir/hello2.txt not in MapKeys")
return
}
}