@@ -13,7 +13,6 @@ import (
13
13
"testing"
14
14
"time"
15
15
16
- "github.com/bmizerany/assert"
17
16
"github.com/tinylib/msgp/msgp"
18
17
)
19
18
@@ -162,13 +161,21 @@ func (d *testDialer) waitForNextDialing(accept bool, delayReads bool) *Conn {
162
161
return conn
163
162
}
164
163
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
+
165
173
// assertReceived is used below by test cases to assert the content written to a *Conn
166
174
// matches an expected string. This is generally used in conjunction with
167
175
// Conn.waitForNextWrite().
168
176
func 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 )
172
179
}
173
180
174
181
// Conn extends net.Conn to add channels used to synchronise across goroutines, eg.
@@ -272,13 +279,13 @@ func (c *Conn) Close() error {
272
279
273
280
func Test_New_itShouldUseDefaultConfigValuesIfNoOtherProvided (t * testing.T ) {
274
281
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 )
282
289
}
283
290
284
291
func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified (t * testing.T ) {
@@ -302,8 +309,8 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
302
309
return
303
310
}
304
311
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 )
307
314
308
315
socketFile = "/tmp/fluent-logger-golang-xxx.sock"
309
316
network = "unixxxx"
@@ -322,13 +329,13 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
322
329
323
330
func Test_New_itShouldUseConfigValuesFromArguments (t * testing.T ) {
324
331
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" )
327
334
}
328
335
329
336
func Test_New_itShouldUseConfigValuesFromMashalAsJSONArgument (t * testing.T ) {
330
337
f , _ := New (Config {MarshalAsJSON : true })
331
- assert . Equal (t , f .Config .MarshalAsJSON , true )
338
+ assertEqual (t , f .Config .MarshalAsJSON , true )
332
339
}
333
340
334
341
func Test_MarshalAsMsgpack (t * testing.T ) {
@@ -431,9 +438,7 @@ func TestJsonConfig(t *testing.T) {
431
438
t .Error (err )
432
439
}
433
440
434
- if ! reflect .DeepEqual (expect , got ) {
435
- t .Errorf ("got %v, except %v" , got , expect )
436
- }
441
+ assertEqual (t , got , expect )
437
442
}
438
443
439
444
func TestPostWithTime (t * testing.T ) {
@@ -643,11 +648,11 @@ func TestNoPanicOnAsyncClose(t *testing.T) {
643
648
if testcase .shouldError {
644
649
f .Close ()
645
650
}
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" })
647
652
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" ))
649
654
} else {
650
- assert . Equal (t , nil , e )
655
+ assertEqual (t , err , nil )
651
656
}
652
657
})
653
658
}
@@ -755,10 +760,14 @@ func TestSyncWriteAfterCloseFails(t *testing.T) {
755
760
err = f .PostWithTime ("tag_name" , time .Unix (1482493050 , 0 ), map [string ]string {"foo" : "buzz" })
756
761
757
762
// The event submission must fail,
758
- assert .NotEqual (t , err , nil );
763
+ if err == nil {
764
+ t .Error ("expected an error" )
765
+ }
759
766
760
767
// 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
+ }
762
771
}()
763
772
764
773
conn := d .waitForNextDialing (true , false )
0 commit comments