-
Notifications
You must be signed in to change notification settings - Fork 2
/
exhibit_test.go
74 lines (57 loc) · 1.5 KB
/
exhibit_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
package exhibit_test
import (
"bytes"
"encoding/xml"
. "github.com/toshaf/exhibit"
"testing"
)
func TestSimpleApprovedValue(t *testing.T) {
Exhibit.A(TextString("hi"), t)
}
func TestTextDifferingOnlyByNewlines(t *testing.T) {
s := bytes.NewBufferString("one\ntwo\nthree\n")
Exhibit.A(TextReader(s), t)
}
func TestMultipleExhibits(t *testing.T) {
Exhibit.A(TextString("This is the content of exhibit A"), t)
Exhibit.B(TextString("This is the content of exhibit B"), t)
}
type Person struct {
Name string
Age int
}
type People []Person
func (people People) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
name := xml.Name{Space: "", Local: "People"}
enc.EncodeToken(xml.StartElement{Name: name})
for _, person := range people {
enc.Encode(person)
}
enc.EncodeToken(xml.EndElement{Name: name})
return nil
}
var people = People{
{"Ann", 38},
{"Bob", 65},
{"Jeff", 103},
}
func TestSomeJson(t *testing.T) {
Exhibit.A(JSONObj(people), t)
}
func TestSomeXml(t *testing.T) {
Exhibit.A(XMLObj(people), t)
}
func TestRawXml(t *testing.T) {
xml, _ := xml.MarshalIndent(people, "", " ")
Exhibit.A(XMLFormatted(xml), t)
}
// The order and layout of the exhibit file that supports
// this test is non what you'd get from json.Indent()
// The idea is to test for semantically equivalent JSON
// payloads, not exact string matches
func TestJsonTolerance(t *testing.T) {
Exhibit.A(JSONObj(people), t)
}
func TestNamedExhibit(t *testing.T) {
Exhibit.Named("conf/people.conf", JSONObj(people), t)
}