@@ -142,7 +142,7 @@ func TestEqual_No_Match(t *testing.T) {
142142 got := golden .Assert (& mt , "other string" )
143143 assert .False (t , got )
144144 assert .Contains (t , mt .msg , "Not equal:" )
145- assert .False (t , mt .failed ) // In case of assert failure, FailNow is not called
145+ assert .True (t , mt .failed )
146146}
147147
148148func TestRequest (t * testing.T ) {
@@ -156,6 +156,38 @@ func TestRequest(t *testing.T) {
156156 golden .Request (t , http .DefaultClient , req , http .StatusBadRequest )
157157}
158158
159+ func TestProcessJSON (t * testing.T ) {
160+ const (
161+ data1 = `{"name": "someone", "age": 41, "active": true}`
162+ data2 = `{"name": "someone", "age": 42, "active": true}`
163+ )
164+
165+ fh := & golden.FileHandler {
166+ FileName : golden .TestNameToFilePath ,
167+ ShouldRecreate : func (t golden.T ) bool { return true },
168+ Equal : golden .EqualWithDiff ,
169+ ProcessContent : golden .PrettyJSON ,
170+ }
171+
172+ t .Cleanup (func () { assert .NoError (t , os .RemoveAll ("./testdata/TestSomeJSON" ), "failed to remove testdata" ) })
173+ mt1 := mockT {name : "TestSomeJSON" }
174+ assert .True (t , fh .Assert (& mt1 , data1 ))
175+ assert .Empty (t , mt1 .msg )
176+ assert .False (t , mt1 .failed )
177+
178+ fh .ShouldRecreate = func (t golden.T ) bool { return false }
179+ mt2 := mockT {name : "TestSomeJSON" }
180+ assert .True (t , fh .Assert (& mt2 , data1 ))
181+ assert .Empty (t , mt2 .msg )
182+ assert .False (t , mt2 .failed )
183+
184+ mt3 := mockT {name : "TestSomeJSON" }
185+ assert .False (t , fh .Assert (& mt3 , data2 ))
186+ assert .Contains (t , mt3 .msg , `- "age": 41,` )
187+ assert .Contains (t , mt3 .msg , `+ "age": 42,` )
188+ assert .True (t , mt3 .failed )
189+ }
190+
159191func assertResult (t * testing.T , tt test , mt * mockT ) {
160192 t .Helper ()
161193 assert .Empty (t , mt .msg )
@@ -172,8 +204,11 @@ type mockT struct {
172204 msg string
173205}
174206
175- func (m * mockT ) Name () string { return m .name }
176- func (m * mockT ) Logf (f string , args ... interface {}) { fmt .Printf (f , args ... ) }
177- func (m * mockT ) Errorf (f string , args ... interface {}) { m .msg += "\n " + fmt .Sprintf (f , args ... ) }
178- func (m * mockT ) FailNow () { m .failed = true }
179- func (m * mockT ) Helper () {}
207+ func (m * mockT ) Name () string { return m .name }
208+ func (m * mockT ) Logf (f string , args ... interface {}) { fmt .Printf (f , args ... ) }
209+ func (m * mockT ) FailNow () { m .failed = true }
210+ func (m * mockT ) Helper () {}
211+ func (m * mockT ) Errorf (f string , args ... interface {}) {
212+ m .failed = true
213+ m .msg += "\n " + fmt .Sprintf (f , args ... )
214+ }
0 commit comments