forked from skx/puppet-summary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
static_test.go
86 lines (74 loc) · 1.62 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
//
// Simple testing of our embedded resource.
//
package main
import (
"io/ioutil"
"strings"
"testing"
)
//
// Test that we have one embedded resource.
//
func TestResourceCount(t *testing.T) {
out := getResources()
if len(out) != 12 {
t.Errorf("We expected 12 resources but found %d.", 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.")
}
}