@@ -16,7 +16,6 @@ import (
1616 "testing"
1717 "time"
1818
19- "github.com/bmizerany/assert"
2019 "github.com/tinylib/msgp/msgp"
2120)
2221
@@ -165,13 +164,21 @@ func (d *testDialer) waitForNextDialing(accept bool, delayReads bool) *Conn {
165164 return conn
166165}
167166
167+ // asserEqual asserts that actual and expected are equivalent, and otherwise
168+ // marks the test as failed (t.Error). It uses reflect.DeepEqual internally.
169+ func assertEqual (t * testing.T , actual , expected interface {}) {
170+ t .Helper ()
171+ if ! reflect .DeepEqual (actual , expected ) {
172+ t .Errorf ("got: '%+v', expected: '%+v'" , actual , expected )
173+ }
174+ }
175+
168176// assertReceived is used below by test cases to assert the content written to a *Conn
169177// matches an expected string. This is generally used in conjunction with
170178// Conn.waitForNextWrite().
171179func assertReceived (t * testing.T , rcv []byte , expected string ) {
172- if string (rcv ) != expected {
173- t .Fatalf ("got %s, expect %s" , string (rcv ), expected )
174- }
180+ t .Helper ()
181+ assertEqual (t , string (rcv ), expected )
175182}
176183
177184// Conn extends net.Conn to add channels used to synchronise across goroutines, eg.
@@ -280,13 +287,13 @@ func (c *Conn) Close() error {
280287
281288func Test_New_itShouldUseDefaultConfigValuesIfNoOtherProvided (t * testing.T ) {
282289 f , _ := New (Config {})
283- assert . Equal (t , f .Config .FluentPort , defaultPort )
284- assert . Equal (t , f .Config .FluentHost , defaultHost )
285- assert . Equal (t , f .Config .Timeout , defaultTimeout )
286- assert . Equal (t , f .Config .WriteTimeout , defaultWriteTimeout )
287- assert . Equal (t , f .Config .BufferLimit , defaultBufferLimit )
288- assert . Equal (t , f .Config .FluentNetwork , defaultNetwork )
289- assert . Equal (t , f .Config .FluentSocketPath , defaultSocketPath )
290+ assertEqual (t , f .Config .FluentPort , defaultPort )
291+ assertEqual (t , f .Config .FluentHost , defaultHost )
292+ assertEqual (t , f .Config .Timeout , defaultTimeout )
293+ assertEqual (t , f .Config .WriteTimeout , defaultWriteTimeout )
294+ assertEqual (t , f .Config .BufferLimit , defaultBufferLimit )
295+ assertEqual (t , f .Config .FluentNetwork , defaultNetwork )
296+ assertEqual (t , f .Config .FluentSocketPath , defaultSocketPath )
290297}
291298
292299func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified (t * testing.T ) {
@@ -310,8 +317,8 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
310317 return
311318 }
312319 defer f .Close ()
313- assert . Equal (t , f .Config .FluentNetwork , network )
314- assert . Equal (t , f .Config .FluentSocketPath , socketFile )
320+ assertEqual (t , f .Config .FluentNetwork , network )
321+ assertEqual (t , f .Config .FluentSocketPath , socketFile )
315322
316323 socketFile = "/tmp/fluent-logger-golang-xxx.sock"
317324 network = "unixxxx"
@@ -330,13 +337,13 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
330337
331338func Test_New_itShouldUseConfigValuesFromArguments (t * testing.T ) {
332339 f , _ := New (Config {FluentPort : 6666 , FluentHost : "foobarhost" })
333- assert . Equal (t , f .Config .FluentPort , 6666 )
334- assert . Equal (t , f .Config .FluentHost , "foobarhost" )
340+ assertEqual (t , f .Config .FluentPort , 6666 )
341+ assertEqual (t , f .Config .FluentHost , "foobarhost" )
335342}
336343
337344func Test_New_itShouldUseConfigValuesFromMashalAsJSONArgument (t * testing.T ) {
338345 f , _ := New (Config {MarshalAsJSON : true })
339- assert . Equal (t , f .Config .MarshalAsJSON , true )
346+ assertEqual (t , f .Config .MarshalAsJSON , true )
340347}
341348
342349func Test_MarshalAsMsgpack (t * testing.T ) {
@@ -439,9 +446,7 @@ func TestJsonConfig(t *testing.T) {
439446 t .Error (err )
440447 }
441448
442- if ! reflect .DeepEqual (expect , got ) {
443- t .Errorf ("got %v, except %v" , got , expect )
444- }
449+ assertEqual (t , got , expect )
445450}
446451
447452func TestPostWithTime (t * testing.T ) {
@@ -654,11 +659,11 @@ func TestNoPanicOnAsyncClose(t *testing.T) {
654659 if testcase .shouldError {
655660 f .Close ()
656661 }
657- e : = f .EncodeAndPostData ("tag_name" , time .Unix (1482493046 , 0 ), map [string ]string {"foo" : "bar" })
662+ err = f .EncodeAndPostData ("tag_name" , time .Unix (1482493046 , 0 ), map [string ]string {"foo" : "bar" })
658663 if testcase .shouldError {
659- assert . Equal (t , fmt .Errorf ("fluent#appendBuffer: Logger already closed" ), e )
664+ assertEqual (t , err , fmt .Errorf ("fluent#appendBuffer: Logger already closed" ))
660665 } else {
661- assert . Equal (t , nil , e )
666+ assertEqual (t , err , nil )
662667 }
663668 })
664669 }
0 commit comments