@@ -10,6 +10,9 @@ import (
1010 "github.com/stretchr/testify/require"
1111)
1212
13+ // The tests in this file are examples from the README and the package-level Go
14+ // documentation.
15+
1316type MyStruct struct {
1417 Foo string `json:"foo,omitempty"`
1518}
@@ -21,10 +24,7 @@ func TestExampleMyStruct(t *testing.T) {
2124 got , err := json .Marshal (& MyStruct {Foo : "Bar" })
2225 require .NoError (t , err )
2326
24- if golden .Update () {
25- golden .Set (t , got )
26- }
27- want := golden .Get (t )
27+ want := golden .Do (t , got )
2828
2929 assert .Equal (t , want , got )
3030}
@@ -46,10 +46,7 @@ func TestExampleMyStructTabular(t *testing.T) {
4646 got , err := json .Marshal (tt .obj )
4747 require .NoError (t , err )
4848
49- if golden .Update () {
50- golden .Set (t , got )
51- }
52- want := golden .Get (t )
49+ want := golden .Do (t , got )
5350
5451 assert .Equal (t , want , got )
5552 })
@@ -64,13 +61,11 @@ func TestExampleMyStructP(t *testing.T) {
6461 gotJSON , _ := json .Marshal (& MyStruct {Foo : "Bar" })
6562 gotXML , _ := xml .Marshal (& MyStruct {Foo : "Bar" })
6663
67- if golden .Update () {
68- golden .SetP (t , "json" , gotJSON )
69- golden .SetP (t , "xml" , gotXML )
70- }
64+ wantJSON := golden .DoP (t , "json" , gotJSON )
65+ wantXML := golden .DoP (t , "xml" , gotXML )
7166
72- assert .Equal (t , golden . GetP ( t , "json" ) , gotJSON )
73- assert .Equal (t , golden . GetP ( t , "xml" ) , gotXML )
67+ assert .Equal (t , wantJSON , gotJSON )
68+ assert .Equal (t , wantXML , gotXML )
7469}
7570
7671// TestExampleMyStructTabularP reads/writes the following golden file:
@@ -92,13 +87,11 @@ func TestExampleMyStructTabularP(t *testing.T) {
9287 gotJSON , _ := json .Marshal (tt .obj )
9388 gotXML , _ := xml .Marshal (tt .obj )
9489
95- if golden .Update () {
96- golden .SetP (t , "json" , gotJSON )
97- golden .SetP (t , "xml" , gotXML )
98- }
90+ wantJSON := golden .DoP (t , "json" , gotJSON )
91+ wantXML := golden .DoP (t , "xml" , gotXML )
9992
100- assert .Equal (t , golden . GetP ( t , "json" ) , gotJSON )
101- assert .Equal (t , golden . GetP ( t , "xml" ) , gotXML )
93+ assert .Equal (t , wantJSON , gotJSON )
94+ assert .Equal (t , wantXML , gotXML )
10295 })
10396 }
10497}
0 commit comments