Skip to content

Commit bbf5da3

Browse files
committed
remove use of deprecated github.com/bmizerany/assert package
The github.com/bmizerany/assert module has been deprecated and is no longer maintained. In addition, the dependency brings various indirect dependencies with it; module github.com/fluent/fluent-logger-golang go 1.19 require ( github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 github.com/tinylib/msgp v1.1.6 ) require ( github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/philhofer/fwd v1.1.1 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect ) The assertion package itself also looks to have some issues. For example, it's not marked as a `t.Helper()`, and while it includes the location of the error in the output, the failures are prefixed with the location of the assertion itself, which is somewhat confusing: === RUN Test_New_itShouldUseDefaultConfigValuesIfNoOtherProvided assert.go:15: /Users/thajeztah/go/src/github.com/fluent/fluent-logger-golang/fluent/fluent_test.go:275 assert.go:62: ! Unexpected: <24224> --- FAIL: Test_New_itShouldUseDefaultConfigValuesIfNoOtherProvided (0.00s) === RUN Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified assert.go:15: /Users/thajeztah/go/src/github.com/fluent/fluent-logger-golang/fluent/fluent_test.go:306 assert.go:62: ! Unexpected: <"unix"> --- FAIL: Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified (0.00s) === RUN Test_New_itShouldUseConfigValuesFromArguments assert.go:15: /Users/thajeztah/go/src/github.com/fluent/fluent-logger-golang/fluent/fluent_test.go:327 assert.go:62: ! Unexpected: <6666> --- FAIL: Test_New_itShouldUseConfigValuesFromArguments (0.00s) === RUN Test_New_itShouldUseConfigValuesFromMashalAsJSONArgument assert.go:15: /Users/thajeztah/go/src/github.com/fluent/fluent-logger-golang/fluent/fluent_test.go:333 assert.go:62: ! Unexpected: <true> --- FAIL: Test_New_itShouldUseConfigValuesFromMashalAsJSONArgument (0.00s) === CONT TestNoPanicOnAsyncClose/Channel_closed_before_write assert.go:15: /Users/thajeztah/go/src/github.com/fluent/fluent-logger-golang/fluent/fluent_test.go:653 === CONT TestNoPanicOnAsyncClose/Channel_not_closed_at_all assert.go:15: /Users/thajeztah/go/src/github.com/fluent/fluent-logger-golang/fluent/fluent_test.go:655 === CONT TestNoPanicOnAsyncClose/Channel_closed_before_write assert.go:62: ! Unexpected: <&errors.errorString{s:"fluent#appendBuffer: Logger already closed"}> === CONT TestNoPanicOnAsyncClose/Channel_not_closed_at_all assert.go:62: ! Unexpected: <<nil>> While a good assertion library can help (for example by printing a rich diff output if a struct does not match), a look at how it's used shows that most cases are comparing primitive types (int, string, bool). This patch swaps the library for a local `assertEqual()` utility. With this patch, test-failures look like the example below: === RUN Test_New_itShouldUseDefaultConfigValuesIfNoOtherProvided fluent_test.go:281: got: '24224', expected: '24224' fluent_test.go:282: got: '127.0.0.1', expected: '127.0.0.1' fluent_test.go:283: got: '3s', expected: '3s' fluent_test.go:284: got: '0s', expected: '0s' fluent_test.go:285: got: '8192', expected: '8192' fluent_test.go:286: got: 'tcp', expected: 'tcp' fluent_test.go:287: got: '', expected: '' --- FAIL: Test_New_itShouldUseDefaultConfigValuesIfNoOtherProvided (0.00s) === RUN Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified fluent_test.go:312: got: 'unix', expected: 'unix' fluent_test.go:313: got: '/tmp/fluent-logger-golang.sock', expected: '/tmp/fluent-logger-golang.sock' --- FAIL: Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified (0.00s) === RUN Test_New_itShouldUseConfigValuesFromArguments fluent_test.go:333: got: '6666', expected: '6666' fluent_test.go:334: got: 'foobarhost', expected: 'foobarhost' --- FAIL: Test_New_itShouldUseConfigValuesFromArguments (0.00s) === RUN Test_New_itShouldUseConfigValuesFromMashalAsJSONArgument fluent_test.go:339: got: 'true', expected: 'true' --- FAIL: Test_New_itShouldUseConfigValuesFromMashalAsJSONArgument (0.00s) === RUN TestJsonConfig fluent_test.go:441: got: '{FluentPort:8888 FluentHost:localhost FluentNetwork:tcp FluentSocketPath:/var/tmp/fluent.sock Timeout:3µs WriteTimeout:6µs BufferLimit:10 RetryWait:5 MaxRetry:3 MaxRetryWait:0 TagPrefix:fluent Async:false ForceStopAsyncSend:false AsyncResultCallback:<nil> AsyncConnect:false MarshalAsJSON:true AsyncReconnectInterval:0 SubSecondPrecision:false RequestAck:false TlsInsecureSkipVerify:false}', expected: '{FluentPort:8888 FluentHost:localhost FluentNetwork:tcp FluentSocketPath:/var/tmp/fluent.sock Timeout:3µs WriteTimeout:6µs BufferLimit:10 RetryWait:5 MaxRetry:3 MaxRetryWait:0 TagPrefix:fluent Async:false ForceStopAsyncSend:false AsyncResultCallback:<nil> AsyncConnect:false MarshalAsJSON:true AsyncReconnectInterval:0 SubSecondPrecision:false RequestAck:false TlsInsecureSkipVerify:false}' --- FAIL: TestJsonConfig (0.00s) === CONT TestPostWithTime/without_Async fluent_test.go:177: got: '["acme.tag_name",1482493046,{"foo":"bar"},{}]', expected: '["acme.tag_name",1482493046,{"foo":"bar"},{}]' fluent_test.go:177: got: '["acme.tag_name",1482493050,{"fluentd":"is awesome"},{}]', expected: '["acme.tag_name",1482493050,{"fluentd":"is awesome"},{}]' fluent_test.go:177: got: '["acme.tag_name",1634263200,{"welcome":"to use"},{}]', expected: '["acme.tag_name",1634263200,{"welcome":"to use"},{}]' === CONT TestPostWithTime/with_Async fluent_test.go:177: got: '["acme.tag_name",1482493046,{"foo":"bar"},{}]', expected: '["acme.tag_name",1482493046,{"foo":"bar"},{}]' fluent_test.go:177: got: '["acme.tag_name",1482493050,{"fluentd":"is awesome"},{}]', expected: '["acme.tag_name",1482493050,{"fluentd":"is awesome"},{}]' fluent_test.go:177: got: '["acme.tag_name",1634263200,{"welcome":"to use"},{}]', expected: '["acme.tag_name",1634263200,{"welcome":"to use"},{}]' === CONT TestReconnectAndResendAfterTransientFailure/with_Async fluent_test.go:177: got: '["tag_name",1482493046,{"foo":"bar"},{}]', expected: '["tag_name",1482493046,{"foo":"bar"},{}]' === CONT TestReconnectAndResendAfterTransientFailure/without_Async fluent_test.go:177: got: '["tag_name",1482493046,{"foo":"bar"},{}]', expected: '["tag_name",1482493046,{"foo":"bar"},{}]' fluent_test.go:177: got: '["tag_name",1482493050,{"fluentd":"is awesome"},{}]', expected: '["tag_name",1482493050,{"fluentd":"is awesome"},{}]' === CONT TestReconnectAndResendAfterTransientFailure/with_Async fluent_test.go:177: got: '["tag_name",1482493050,{"fluentd":"is awesome"},{}]', expected: '["tag_name",1482493050,{"fluentd":"is awesome"},{}]' === CONT TestNoPanicOnAsyncClose/Channel_closed_before_write fluent_test.go:657: got: 'fluent#appendBuffer: Logger already closed', expected: 'fluent#appendBuffer: Logger already closed' === CONT TestNoPanicOnAsyncClose/Channel_not_closed_at_all fluent_test.go:659: got: '<nil>', expected: '<nil>' The list of dependencies have also been reduced with this patch: module github.com/fluent/fluent-logger-golang go 1.19 require github.com/tinylib/msgp v1.1.6 require github.com/philhofer/fwd v1.1.1 // indirect Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 30d6825 commit bbf5da3

File tree

3 files changed

+35
-57
lines changed

3 files changed

+35
-57
lines changed

fluent/fluent_test.go

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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().
168176
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)
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

273280
func 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

284291
func 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

323330
func 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

329336
func 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

334341
func 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

439444
func 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)

go.mod

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@ module github.com/fluent/fluent-logger-golang
22

33
go 1.23.5
44

5-
require (
6-
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869
7-
github.com/tinylib/msgp v1.3.0
8-
)
5+
require github.com/tinylib/msgp v1.3.0
96

10-
require (
11-
github.com/davecgh/go-spew v1.1.1 // indirect
12-
github.com/kr/pretty v0.3.1 // indirect
13-
github.com/kr/text v0.2.0 // indirect
14-
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect
15-
github.com/pmezard/go-difflib v1.0.0 // indirect
16-
github.com/rogpeppe/go-internal v1.9.0 // indirect
17-
github.com/stretchr/testify v1.10.0 // indirect
18-
gopkg.in/yaml.v3 v3.0.1 // indirect
19-
)
7+
require github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect

go.sum

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
2-
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
3-
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
4-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6-
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
7-
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
8-
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
9-
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
101
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c h1:dAMKvw0MlJT1GshSTtih8C2gDs04w8dReiOGXrGLNoY=
112
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM=
12-
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
13-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15-
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
16-
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
17-
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
18-
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
193
github.com/tinylib/msgp v1.3.0 h1:ULuf7GPooDaIlbyvgAxBV/FI7ynli6LZ1/nVUNu+0ww=
204
github.com/tinylib/msgp v1.3.0/go.mod h1:ykjzy2wzgrlvpDCRc4LA8UXy6D8bzMSuAF3WD57Gok0=
21-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
22-
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
23-
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)