Skip to content

remove use of deprecated github.com/bmizerany/assert package #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 33 additions & 24 deletions fluent/fluent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"testing"
"time"

"github.com/bmizerany/assert"
"github.com/tinylib/msgp/msgp"
)

Expand Down Expand Up @@ -162,13 +161,21 @@ func (d *testDialer) waitForNextDialing(accept bool, delayReads bool) *Conn {
return conn
}

// asserEqual asserts that actual and expected are equivalent, and otherwise
// marks the test as failed (t.Error). It uses reflect.DeepEqual internally.
func assertEqual(t *testing.T, actual, expected interface{}) {
t.Helper()
if !reflect.DeepEqual(actual, expected) {
t.Errorf("got: '%+v', expected: '%+v'", actual, expected)
}
}

// assertReceived is used below by test cases to assert the content written to a *Conn
// matches an expected string. This is generally used in conjunction with
// Conn.waitForNextWrite().
func assertReceived(t *testing.T, rcv []byte, expected string) {
if string(rcv) != expected {
t.Fatalf("got %s, expect %s", string(rcv), expected)
}
t.Helper()
assertEqual(t, string(rcv), expected)
}

// Conn extends net.Conn to add channels used to synchronise across goroutines, eg.
Expand Down Expand Up @@ -272,13 +279,13 @@ func (c *Conn) Close() error {

func Test_New_itShouldUseDefaultConfigValuesIfNoOtherProvided(t *testing.T) {
f, _ := New(Config{})
assert.Equal(t, f.Config.FluentPort, defaultPort)
assert.Equal(t, f.Config.FluentHost, defaultHost)
assert.Equal(t, f.Config.Timeout, defaultTimeout)
assert.Equal(t, f.Config.WriteTimeout, defaultWriteTimeout)
assert.Equal(t, f.Config.BufferLimit, defaultBufferLimit)
assert.Equal(t, f.Config.FluentNetwork, defaultNetwork)
assert.Equal(t, f.Config.FluentSocketPath, defaultSocketPath)
assertEqual(t, f.Config.FluentPort, defaultPort)
assertEqual(t, f.Config.FluentHost, defaultHost)
assertEqual(t, f.Config.Timeout, defaultTimeout)
assertEqual(t, f.Config.WriteTimeout, defaultWriteTimeout)
assertEqual(t, f.Config.BufferLimit, defaultBufferLimit)
assertEqual(t, f.Config.FluentNetwork, defaultNetwork)
assertEqual(t, f.Config.FluentSocketPath, defaultSocketPath)
}

func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
Expand All @@ -302,8 +309,8 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
return
}
defer f.Close()
assert.Equal(t, f.Config.FluentNetwork, network)
assert.Equal(t, f.Config.FluentSocketPath, socketFile)
assertEqual(t, f.Config.FluentNetwork, network)
assertEqual(t, f.Config.FluentSocketPath, socketFile)

socketFile = "/tmp/fluent-logger-golang-xxx.sock"
network = "unixxxx"
Expand All @@ -322,13 +329,13 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {

func Test_New_itShouldUseConfigValuesFromArguments(t *testing.T) {
f, _ := New(Config{FluentPort: 6666, FluentHost: "foobarhost"})
assert.Equal(t, f.Config.FluentPort, 6666)
assert.Equal(t, f.Config.FluentHost, "foobarhost")
assertEqual(t, f.Config.FluentPort, 6666)
assertEqual(t, f.Config.FluentHost, "foobarhost")
}

func Test_New_itShouldUseConfigValuesFromMashalAsJSONArgument(t *testing.T) {
f, _ := New(Config{MarshalAsJSON: true})
assert.Equal(t, f.Config.MarshalAsJSON, true)
assertEqual(t, f.Config.MarshalAsJSON, true)
}

func Test_MarshalAsMsgpack(t *testing.T) {
Expand Down Expand Up @@ -431,9 +438,7 @@ func TestJsonConfig(t *testing.T) {
t.Error(err)
}

if !reflect.DeepEqual(expect, got) {
t.Errorf("got %v, except %v", got, expect)
}
assertEqual(t, got, expect)
}

func TestPostWithTime(t *testing.T) {
Expand Down Expand Up @@ -643,11 +648,11 @@ func TestNoPanicOnAsyncClose(t *testing.T) {
if testcase.shouldError {
f.Close()
}
e := f.EncodeAndPostData("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
err = f.EncodeAndPostData("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
if testcase.shouldError {
assert.Equal(t, fmt.Errorf("fluent#appendBuffer: Logger already closed"), e)
assertEqual(t, err, fmt.Errorf("fluent#appendBuffer: Logger already closed"))
} else {
assert.Equal(t, nil, e)
assertEqual(t, err, nil)
}
})
}
Expand Down Expand Up @@ -755,10 +760,14 @@ func TestSyncWriteAfterCloseFails(t *testing.T) {
err = f.PostWithTime("tag_name", time.Unix(1482493050, 0), map[string]string{"foo": "buzz"})

// The event submission must fail,
assert.NotEqual(t, err, nil);
if err == nil {
t.Error("expected an error")
}

// and also must keep Fluentd closed.
assert.NotEqual(t, f.closed, false);
if f.closed != true {
t.Error("expected Fluentd to be kept closed")
}
}()

conn := d.waitForNextDialing(true, false)
Expand Down
16 changes: 2 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ module github.com/fluent/fluent-logger-golang

go 1.23.5

require (
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869
github.com/tinylib/msgp v1.3.0
)
require github.com/tinylib/msgp v1.3.0

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