@@ -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 ) {
@@ -303,8 +310,8 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
303
310
return
304
311
}
305
312
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 )
308
315
309
316
socketFile = "/tmp/fluent-logger-golang-xxx.sock"
310
317
network = "unixxxx"
@@ -324,13 +331,13 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
324
331
325
332
func Test_New_itShouldUseConfigValuesFromArguments (t * testing.T ) {
326
333
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" )
329
336
}
330
337
331
338
func Test_New_itShouldUseConfigValuesFromMashalAsJSONArgument (t * testing.T ) {
332
339
f , _ := New (Config {MarshalAsJSON : true })
333
- assert . Equal (t , f .Config .MarshalAsJSON , true )
340
+ assertEqual (t , f .Config .MarshalAsJSON , true )
334
341
}
335
342
336
343
func Test_MarshalAsMsgpack (t * testing.T ) {
@@ -432,9 +439,7 @@ func TestJsonConfig(t *testing.T) {
432
439
t .Error (err )
433
440
}
434
441
435
- if ! reflect .DeepEqual (expect , got ) {
436
- t .Errorf ("got %v, except %v" , got , expect )
437
- }
442
+ assertEqual (t , got , expect )
438
443
}
439
444
440
445
func TestPostWithTime (t * testing.T ) {
@@ -650,9 +655,9 @@ func TestNoPanicOnAsyncClose(t *testing.T) {
650
655
}
651
656
err = f .EncodeAndPostData ("tag_name" , time .Unix (1482493046 , 0 ), map [string ]string {"foo" : "bar" })
652
657
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" ))
654
659
} else {
655
- assert . Equal (t , nil , err )
660
+ assertEqual (t , err , nil )
656
661
}
657
662
})
658
663
}
@@ -760,10 +765,14 @@ func TestSyncWriteAfterCloseFails(t *testing.T) {
760
765
err = f .PostWithTime ("tag_name" , time .Unix (1482493050 , 0 ), map [string ]string {"foo" : "buzz" })
761
766
762
767
// The event submission must fail,
763
- assert .NotEqual (t , err , nil )
768
+ if err == nil {
769
+ t .Error ("expected an error" )
770
+ }
764
771
765
772
// 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
+ }
767
776
}()
768
777
769
778
conn := d .waitForNextDialing (true , false )
0 commit comments