-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
68 lines (60 loc) · 2.21 KB
/
example_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
package goldsert_test
import (
"testing"
"github.com/jimeh/go-goldsert"
)
type MyStruct struct {
FooBar string `json:"foo_bar,omitempty" yaml:"fooBar,omitempty" xml:"Foo_Bar,omitempty"`
Bar string `json:"-" yaml:"-" xml:"-"`
baz string
}
// TestExampleMyStructMarshaling reads/writes the following golden files:
//
// testdata/TestExampleMyStructMarshaling/goldsert_json.golden
// testdata/TestExampleMyStructMarshaling/goldsert_yaml.golden
// testdata/TestExampleMyStructMarshaling/goldsert_xml.golden
//
func TestExampleMyStructMarshaling(t *testing.T) {
myStruct := &MyStruct{FooBar: "Hello World!"}
goldsert.JSONMarshaling(t, myStruct)
goldsert.YAMLMarshaling(t, myStruct)
goldsert.XMLMarshaling(t, myStruct)
}
// TestExampleMyStructMarshalingP reads/writes the following golden files:
//
// testdata/TestExampleMyStructMarshalingP/goldsert_json.golden
// testdata/TestExampleMyStructMarshalingP/goldsert_yaml.golden
// testdata/TestExampleMyStructMarshalingP/goldsert_xml.golden
//
func TestExampleMyStructMarshalingP(t *testing.T) {
myStruct := &MyStruct{FooBar: "Hello World!", Bar: "Oops", baz: "nope!"}
want := &MyStruct{FooBar: "Hello World!"}
goldsert.JSONMarshalingP(t, myStruct, want)
goldsert.YAMLMarshalingP(t, myStruct, want)
goldsert.XMLMarshalingP(t, myStruct, want)
}
// TestExampleMyStructMarshalingTabular reads/writes the following golden files:
//
// testdata/TestExampleMyStructMarshalingTabular/empty/goldsert_json.golden
// testdata/TestExampleMyStructMarshalingTabular/empty/goldsert_yaml.golden
// testdata/TestExampleMyStructMarshalingTabular/empty/goldsert_xml.golden
// testdata/TestExampleMyStructMarshalingTabular/full/goldsert_json.golden
// testdata/TestExampleMyStructMarshalingTabular/full/goldsert_yaml.golden
// testdata/TestExampleMyStructMarshalingTabular/full/goldsert_xml.golden
//
func TestExampleMyStructMarshalingTabular(t *testing.T) {
tests := []struct {
name string
obj *MyStruct
}{
{name: "empty", obj: &MyStruct{}},
{name: "full", obj: &MyStruct{FooBar: "Hello World!"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
goldsert.JSONMarshaling(t, tt.obj)
goldsert.YAMLMarshaling(t, tt.obj)
goldsert.XMLMarshaling(t, tt.obj)
})
}
}