@@ -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 ) {
@@ -302,8 +309,8 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
302309 return
303310 }
304311 defer f .Close ()
305- assert . Equal (t , f .Config .FluentNetwork , network )
306- assert . Equal (t , f .Config .FluentSocketPath , socketFile )
312+ assertEqual (t , f .Config .FluentNetwork , network )
313+ assertEqual (t , f .Config .FluentSocketPath , socketFile )
307314
308315 socketFile = "/tmp/fluent-logger-golang-xxx.sock"
309316 network = "unixxxx"
@@ -322,13 +329,13 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
322329
323330func Test_New_itShouldUseConfigValuesFromArguments (t * testing.T ) {
324331 f , _ := New (Config {FluentPort : 6666 , FluentHost : "foobarhost" })
325- assert . Equal (t , f .Config .FluentPort , 6666 )
326- assert . Equal (t , f .Config .FluentHost , "foobarhost" )
332+ assertEqual (t , f .Config .FluentPort , 6666 )
333+ assertEqual (t , f .Config .FluentHost , "foobarhost" )
327334}
328335
329336func Test_New_itShouldUseConfigValuesFromMashalAsJSONArgument (t * testing.T ) {
330337 f , _ := New (Config {MarshalAsJSON : true })
331- assert . Equal (t , f .Config .MarshalAsJSON , true )
338+ assertEqual (t , f .Config .MarshalAsJSON , true )
332339}
333340
334341func Test_MarshalAsMsgpack (t * testing.T ) {
@@ -431,9 +438,7 @@ func TestJsonConfig(t *testing.T) {
431438 t .Error (err )
432439 }
433440
434- if ! reflect .DeepEqual (expect , got ) {
435- t .Errorf ("got %v, except %v" , got , expect )
436- }
441+ assertEqual (t , got , expect )
437442}
438443
439444func TestPostWithTime (t * testing.T ) {
@@ -643,11 +648,11 @@ func TestNoPanicOnAsyncClose(t *testing.T) {
643648 if testcase .shouldError {
644649 f .Close ()
645650 }
646- e : = f .EncodeAndPostData ("tag_name" , time .Unix (1482493046 , 0 ), map [string ]string {"foo" : "bar" })
651+ err = f .EncodeAndPostData ("tag_name" , time .Unix (1482493046 , 0 ), map [string ]string {"foo" : "bar" })
647652 if testcase .shouldError {
648- assert . Equal (t , fmt .Errorf ("fluent#appendBuffer: Logger already closed" ), e )
653+ assertEqual (t , err , fmt .Errorf ("fluent#appendBuffer: Logger already closed" ))
649654 } else {
650- assert . Equal (t , nil , e )
655+ assertEqual (t , err , nil )
651656 }
652657 })
653658 }
@@ -755,10 +760,14 @@ func TestSyncWriteAfterCloseFails(t *testing.T) {
755760 err = f .PostWithTime ("tag_name" , time .Unix (1482493050 , 0 ), map [string ]string {"foo" : "buzz" })
756761
757762 // The event submission must fail,
758- assert .NotEqual (t , err , nil );
763+ if err == nil {
764+ t .Error ("expected an error" )
765+ }
759766
760767 // and also must keep Fluentd closed.
761- assert .NotEqual (t , f .closed , false );
768+ if f .closed != true {
769+ t .Error ("expected Fluentd to be kept closed" )
770+ }
762771 }()
763772
764773 conn := d .waitForNextDialing (true , false )
0 commit comments