-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
static_test.go
117 lines (100 loc) · 2.24 KB
/
static_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
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
//
// Simple testing of our embedded resource.
//
package main
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)
//
// Test that we have one embedded resource.
//
func TestResourceCount(t *testing.T) {
expected := 0
// We're going to compare what is embedded with
// what is on-disk.
//
// We could just hard-wire the count, but that
// would require updating the count every time
// we add/remove a new resource
err := filepath.Walk("data",
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
expected++
}
return nil
})
if err != nil {
t.Errorf("failed to find resources beneath data/ %s", err.Error())
}
// ARBITRARY!
if expected < 10 {
t.Fatalf("we expected more than 10 files beneath data/")
}
out := getResources()
if len(out) != expected {
t.Errorf("We expected %d resources but found %d.", expected, len(out))
}
}
//
// Test that each of our resources is identical to the master
// version.
//
func TestResourceMatches(t *testing.T) {
//
// For each resource
//
all := getResources()
for _, entry := range all {
//
// Get the data from our embedded copy
//
data, err := getResource(entry.Filename)
if err != nil {
t.Errorf("Loading our resource failed:%s", entry.Filename)
}
//
// Get the data from our master-copy.
//
master, err := ioutil.ReadFile(entry.Filename)
if err != nil {
t.Errorf("Loading our master-resource failed:%s", entry.Filename)
}
//
// Test the lengths match
//
if len(master) != len(data) {
t.Errorf("Embedded and real resources have different sizes.")
}
//
// Test the data-matches
//
if string(master) != string(data) {
t.Errorf("Embedded and real resources have different content.")
}
}
}
//
// Test that a missing resource is handled.
//
func TestMissingResource(t *testing.T) {
//
// Get the data from our embedded copy
//
data, err := getResource("moi/kissa")
if data != nil {
t.Errorf("We expected to find no data, but got some.")
}
if err == nil {
t.Errorf("We expected an error loading a missing resource, but got none.")
}
if !strings.Contains(err.Error(), "failed to find resource") {
t.Errorf("Error message differed from expectations.")
}
}