forked from naoina/kocha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_test.go
51 lines (47 loc) · 1.11 KB
/
resource_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
package kocha
import (
"io/ioutil"
"reflect"
"testing"
)
func Test_AddResource(t *testing.T) {
if len(includedResources) != 0 {
t.Errorf("Expect length is 0, but %v", len(includedResources))
}
AddResource("testname", "testdata")
if len(includedResources) != 1 {
t.Errorf("Expect length is 1, but %v", len(includedResources))
}
rc, ok := includedResources["testname"]
if !ok {
t.Errorf("Expect testname exists, but not exists")
}
actual := string(rc.data)
expected := "testdata"
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
}
func Test_resource_Open(t *testing.T) {
rc := &resource{[]byte("testdata1")}
rs := rc.Open()
buf1, err := ioutil.ReadAll(rs)
if err != nil {
t.Fatal(err)
}
actual := string(buf1)
expected := "testdata1"
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
rs = rc.Open()
buf2, err := ioutil.ReadAll(rs)
if err != nil {
t.Fatal(err)
}
actual = string(buf2)
expected = "testdata1"
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
}