Skip to content

Commit 1429197

Browse files
authored
Merge branch 'master' into refactor_potential_races
2 parents 1f759a4 + e82787e commit 1429197

File tree

4 files changed

+43
-33
lines changed

4 files changed

+43
-33
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,15 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [ubuntu, macos, windows]
17-
golang: ['1.13', '1.16', '1.17']
18-
# currently, we cannot run non-x86_64 machines on Github Actions cloud env.
17+
golang: ['1.23', '1.24']
18+
# currently, we cannot run non-x86_64 machines on GitHub Actions cloud env.
1919
runs-on: ${{ matrix.os }}-latest
2020
name: CI golang ${{ matrix.golang }} on ${{ matrix.os }}
2121
steps:
22-
- uses: actions/checkout@v2
23-
- uses: actions/setup-go@v2
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-go@v5
2424
with:
2525
go-version: ${{ matrix.golang }}
26-
- name: Change GO11MODULES
27-
run: go env -w GO111MODULE=auto
28-
- name: Install requirements
29-
run: |
30-
go get github.com/bmizerany/assert
31-
go get github.com/philhofer/fwd
32-
go get github.com/tinylib/msgp
3326
- name: Test
3427
run: go test -v ./fluent
28+
shell: bash

fluent/fluent_test.go

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"testing"
1717
"time"
1818

19-
"github.com/bmizerany/assert"
2019
"github.com/tinylib/msgp/msgp"
2120
)
2221

@@ -165,13 +164,21 @@ func (d *testDialer) waitForNextDialing(accept bool, delayReads bool) *Conn {
165164
return conn
166165
}
167166

167+
// asserEqual asserts that actual and expected are equivalent, and otherwise
168+
// marks the test as failed (t.Error). It uses reflect.DeepEqual internally.
169+
func assertEqual(t *testing.T, actual, expected interface{}) {
170+
t.Helper()
171+
if !reflect.DeepEqual(actual, expected) {
172+
t.Errorf("got: '%+v', expected: '%+v'", actual, expected)
173+
}
174+
}
175+
168176
// assertReceived is used below by test cases to assert the content written to a *Conn
169177
// matches an expected string. This is generally used in conjunction with
170178
// Conn.waitForNextWrite().
171179
func assertReceived(t *testing.T, rcv []byte, expected string) {
172-
if string(rcv) != expected {
173-
t.Fatalf("got %s, expect %s", string(rcv), expected)
174-
}
180+
t.Helper()
181+
assertEqual(t, string(rcv), expected)
175182
}
176183

177184
// Conn extends net.Conn to add channels used to synchronise across goroutines, eg.
@@ -280,13 +287,13 @@ func (c *Conn) Close() error {
280287

281288
func Test_New_itShouldUseDefaultConfigValuesIfNoOtherProvided(t *testing.T) {
282289
f, _ := New(Config{})
283-
assert.Equal(t, f.Config.FluentPort, defaultPort)
284-
assert.Equal(t, f.Config.FluentHost, defaultHost)
285-
assert.Equal(t, f.Config.Timeout, defaultTimeout)
286-
assert.Equal(t, f.Config.WriteTimeout, defaultWriteTimeout)
287-
assert.Equal(t, f.Config.BufferLimit, defaultBufferLimit)
288-
assert.Equal(t, f.Config.FluentNetwork, defaultNetwork)
289-
assert.Equal(t, f.Config.FluentSocketPath, defaultSocketPath)
290+
assertEqual(t, f.Config.FluentPort, defaultPort)
291+
assertEqual(t, f.Config.FluentHost, defaultHost)
292+
assertEqual(t, f.Config.Timeout, defaultTimeout)
293+
assertEqual(t, f.Config.WriteTimeout, defaultWriteTimeout)
294+
assertEqual(t, f.Config.BufferLimit, defaultBufferLimit)
295+
assertEqual(t, f.Config.FluentNetwork, defaultNetwork)
296+
assertEqual(t, f.Config.FluentSocketPath, defaultSocketPath)
290297
}
291298

292299
func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
@@ -310,8 +317,8 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
310317
return
311318
}
312319
defer f.Close()
313-
assert.Equal(t, f.Config.FluentNetwork, network)
314-
assert.Equal(t, f.Config.FluentSocketPath, socketFile)
320+
assertEqual(t, f.Config.FluentNetwork, network)
321+
assertEqual(t, f.Config.FluentSocketPath, socketFile)
315322

316323
socketFile = "/tmp/fluent-logger-golang-xxx.sock"
317324
network = "unixxxx"
@@ -330,13 +337,13 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
330337

331338
func Test_New_itShouldUseConfigValuesFromArguments(t *testing.T) {
332339
f, _ := New(Config{FluentPort: 6666, FluentHost: "foobarhost"})
333-
assert.Equal(t, f.Config.FluentPort, 6666)
334-
assert.Equal(t, f.Config.FluentHost, "foobarhost")
340+
assertEqual(t, f.Config.FluentPort, 6666)
341+
assertEqual(t, f.Config.FluentHost, "foobarhost")
335342
}
336343

337344
func Test_New_itShouldUseConfigValuesFromMashalAsJSONArgument(t *testing.T) {
338345
f, _ := New(Config{MarshalAsJSON: true})
339-
assert.Equal(t, f.Config.MarshalAsJSON, true)
346+
assertEqual(t, f.Config.MarshalAsJSON, true)
340347
}
341348

342349
func Test_MarshalAsMsgpack(t *testing.T) {
@@ -439,9 +446,7 @@ func TestJsonConfig(t *testing.T) {
439446
t.Error(err)
440447
}
441448

442-
if !reflect.DeepEqual(expect, got) {
443-
t.Errorf("got %v, except %v", got, expect)
444-
}
449+
assertEqual(t, got, expect)
445450
}
446451

447452
func TestPostWithTime(t *testing.T) {
@@ -654,11 +659,11 @@ func TestNoPanicOnAsyncClose(t *testing.T) {
654659
if testcase.shouldError {
655660
f.Close()
656661
}
657-
e := f.EncodeAndPostData("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
662+
err = f.EncodeAndPostData("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
658663
if testcase.shouldError {
659-
assert.Equal(t, fmt.Errorf("fluent#appendBuffer: Logger already closed"), e)
664+
assertEqual(t, err, fmt.Errorf("fluent#appendBuffer: Logger already closed"))
660665
} else {
661-
assert.Equal(t, nil, e)
666+
assertEqual(t, err, nil)
662667
}
663668
})
664669
}

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module github.com/fluent/fluent-logger-golang
2+
3+
go 1.23.5
4+
5+
require github.com/tinylib/msgp v1.3.0
6+
7+
require github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c h1:dAMKvw0MlJT1GshSTtih8C2gDs04w8dReiOGXrGLNoY=
2+
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM=
3+
github.com/tinylib/msgp v1.3.0 h1:ULuf7GPooDaIlbyvgAxBV/FI7ynli6LZ1/nVUNu+0ww=
4+
github.com/tinylib/msgp v1.3.0/go.mod h1:ykjzy2wzgrlvpDCRc4LA8UXy6D8bzMSuAF3WD57Gok0=

0 commit comments

Comments
 (0)