@@ -13,7 +13,6 @@ import (
1313 "testing"
1414 "time"
1515
16- "github.com/bmizerany/assert"
1716 "github.com/tinylib/msgp/msgp"
1817)
1918
@@ -162,13 +161,21 @@ func (d *testDialer) waitForNextDialing(accept bool, delayReads bool) *Conn {
162161 return conn
163162}
164163
164+ // asserEqual asserts that actual and expected are equivalent, and otherwise
165+ // marks the test as failed (t.Error). It uses reflect.DeepEqual internally.
166+ func assertEqual (t * testing.T , actual , expected interface {}) {
167+ t .Helper ()
168+ if ! reflect .DeepEqual (actual , expected ) {
169+ t .Errorf ("got: '%+v', expected: '%+v'" , actual , expected )
170+ }
171+ }
172+
165173// assertReceived is used below by test cases to assert the content written to a *Conn
166174// matches an expected string. This is generally used in conjunction with
167175// Conn.waitForNextWrite().
168176func assertReceived (t * testing.T , rcv []byte , expected string ) {
169- if string (rcv ) != expected {
170- t .Fatalf ("got %s, expect %s" , string (rcv ), expected )
171- }
177+ t .Helper ()
178+ assertEqual (t , string (rcv ), expected )
172179}
173180
174181// Conn extends net.Conn to add channels used to synchronise across goroutines, eg.
@@ -272,13 +279,13 @@ func (c *Conn) Close() error {
272279
273280func Test_New_itShouldUseDefaultConfigValuesIfNoOtherProvided (t * testing.T ) {
274281 f , _ := New (Config {})
275- assert . Equal (t , f .Config .FluentPort , defaultPort )
276- assert . Equal (t , f .Config .FluentHost , defaultHost )
277- assert . Equal (t , f .Config .Timeout , defaultTimeout )
278- assert . Equal (t , f .Config .WriteTimeout , defaultWriteTimeout )
279- assert . Equal (t , f .Config .BufferLimit , defaultBufferLimit )
280- assert . Equal (t , f .Config .FluentNetwork , defaultNetwork )
281- assert . Equal (t , f .Config .FluentSocketPath , defaultSocketPath )
282+ assertEqual (t , f .Config .FluentPort , defaultPort )
283+ assertEqual (t , f .Config .FluentHost , defaultHost )
284+ assertEqual (t , f .Config .Timeout , defaultTimeout )
285+ assertEqual (t , f .Config .WriteTimeout , defaultWriteTimeout )
286+ assertEqual (t , f .Config .BufferLimit , defaultBufferLimit )
287+ assertEqual (t , f .Config .FluentNetwork , defaultNetwork )
288+ assertEqual (t , f .Config .FluentSocketPath , defaultSocketPath )
282289}
283290
284291func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified (t * testing.T ) {
@@ -303,8 +310,8 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
303310 return
304311 }
305312 defer f .Close ()
306- assert . Equal (t , f .Config .FluentNetwork , network )
307- assert . Equal (t , f .Config .FluentSocketPath , socketFile )
313+ assertEqual (t , f .Config .FluentNetwork , network )
314+ assertEqual (t , f .Config .FluentSocketPath , socketFile )
308315
309316 socketFile = "/tmp/fluent-logger-golang-xxx.sock"
310317 network = "unixxxx"
@@ -324,13 +331,13 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
324331
325332func Test_New_itShouldUseConfigValuesFromArguments (t * testing.T ) {
326333 f , _ := New (Config {FluentPort : 6666 , FluentHost : "foobarhost" })
327- assert . Equal (t , f .Config .FluentPort , 6666 )
328- assert . Equal (t , f .Config .FluentHost , "foobarhost" )
334+ assertEqual (t , f .Config .FluentPort , 6666 )
335+ assertEqual (t , f .Config .FluentHost , "foobarhost" )
329336}
330337
331338func Test_New_itShouldUseConfigValuesFromMashalAsJSONArgument (t * testing.T ) {
332339 f , _ := New (Config {MarshalAsJSON : true })
333- assert . Equal (t , f .Config .MarshalAsJSON , true )
340+ assertEqual (t , f .Config .MarshalAsJSON , true )
334341}
335342
336343func Test_MarshalAsMsgpack (t * testing.T ) {
@@ -432,9 +439,7 @@ func TestJsonConfig(t *testing.T) {
432439 t .Error (err )
433440 }
434441
435- if ! reflect .DeepEqual (expect , got ) {
436- t .Errorf ("got %v, except %v" , got , expect )
437- }
442+ assertEqual (t , got , expect )
438443}
439444
440445func TestPostWithTime (t * testing.T ) {
@@ -650,9 +655,9 @@ func TestNoPanicOnAsyncClose(t *testing.T) {
650655 }
651656 err = f .EncodeAndPostData ("tag_name" , time .Unix (1482493046 , 0 ), map [string ]string {"foo" : "bar" })
652657 if tc .shouldError {
653- assert . Equal (t , fmt .Errorf ("fluent#appendBuffer: Logger already closed" ), err )
658+ assertEqual (t , err , fmt .Errorf ("fluent#appendBuffer: Logger already closed" ))
654659 } else {
655- assert . Equal (t , nil , err )
660+ assertEqual (t , err , nil )
656661 }
657662 })
658663 }
@@ -760,10 +765,14 @@ func TestSyncWriteAfterCloseFails(t *testing.T) {
760765 err = f .PostWithTime ("tag_name" , time .Unix (1482493050 , 0 ), map [string ]string {"foo" : "buzz" })
761766
762767 // The event submission must fail,
763- assert .NotEqual (t , err , nil )
768+ if err == nil {
769+ t .Error ("expected an error" )
770+ }
764771
765772 // and also must keep Fluentd closed.
766- assert .NotEqual (t , f .closed , false )
773+ if f .closed != true {
774+ t .Error ("expected Fluentd to be kept closed" )
775+ }
767776 }()
768777
769778 conn := d .waitForNextDialing (true , false )
0 commit comments