Skip to content

Commit

Permalink
Tests and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Sep 21, 2024
1 parent 0181458 commit e7d08ff
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ linters-settings:
settings:
shadow:
strict: true
staticcheck:
checks:
- all

linters:
disable-all: true
enable:
# TODO https://github.com/FerretDB/wire/issues/4
- govet
- staticcheck

issues:
max-issues-per-linter: 0
Expand Down
14 changes: 7 additions & 7 deletions op_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var msgTestCases = []testCase{
}},
},
command: "buildInfo",
b: `
si: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand Down Expand Up @@ -128,7 +128,7 @@ var msgTestCases = []testCase{
}},
},
command: "version",
b: `
si: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand Down Expand Up @@ -221,7 +221,7 @@ var msgTestCases = []testCase{
},
},
command: "insert",
b: `
si: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand Down Expand Up @@ -315,7 +315,7 @@ var msgTestCases = []testCase{
}},
},
command: "insert",
b: `
si: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand Down Expand Up @@ -389,7 +389,7 @@ var msgTestCases = []testCase{
},
},
command: "insert",
b: `
si: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand Down Expand Up @@ -475,7 +475,7 @@ var msgTestCases = []testCase{
checksum: 1737537506,
},
command: "insert",
b: `
si: `
{
"FlagBits": "[checksumPresent]",
"Checksum": int64(1737537506),
Expand Down Expand Up @@ -584,7 +584,7 @@ var msgTestCases = []testCase{
checksum: 2932997361,
},
command: "update",
b: `
si: `
{
"FlagBits": "[checksumPresent]",
"Checksum": int64(2932997361),
Expand Down
4 changes: 2 additions & 2 deletions op_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var queryTestCases = []testCase{
),
returnFieldsSelector: nil,
},
b: `
si: `
{
"Flags": "[]",
"FullCollectionName": "admin.$cmd",
Expand Down Expand Up @@ -129,7 +129,7 @@ var queryTestCases = []testCase{
),
returnFieldsSelector: nil,
},
b: `
si: `
{
"Flags": "[]",
"FullCollectionName": "admin.$cmd",
Expand Down
4 changes: 2 additions & 2 deletions op_reply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var replyTestCases = []testCase{
"ok", float64(1),
),
},
b: `
si: `
{
"ResponseFlags": "[AwaitCapable]",
"CursorID": int64(0),
Expand Down Expand Up @@ -112,7 +112,7 @@ var replyTestCases = []testCase{
"ok", float64(1),
),
},
b: `
si: `
{
"ResponseFlags": "[AwaitCapable]",
"CursorID": int64(0),
Expand Down
5 changes: 3 additions & 2 deletions wire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"os"
"path/filepath"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -70,7 +71,7 @@ type testCase struct {
msgHeader *MsgHeader
msgBody MsgBody
command string // only for OpMsg
b string
si string
err string // unwrapped
}

Expand Down Expand Up @@ -127,7 +128,7 @@ func testMessages(t *testing.T, testCases []testCase) {
require.NotNil(t, msgHeader)
require.NotNil(t, msgBody)
assert.NotEmpty(t, msgHeader.String())
assert.Equal(t, testutil.Unindent(tc.b), msgBody.StringIndent())
assert.Equal(t, strings.ReplaceAll(testutil.Unindent(tc.si), `"`, "`"), msgBody.StringIndent())
assert.NotEmpty(t, msgBody.String())

require.NoError(t, msgBody.check())
Expand Down
12 changes: 8 additions & 4 deletions wirebson/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func TestLogging(t *testing.T) {
"nan_weird": NaN(111111111111000000000000000111100000000000011110000000000000001),
"i32": 42,
"i64": int64(42),
}`, `"`, "`"),
}`, `"`, "`",
),
m: "{`f64`: 42.0, `inf`: +Inf, `neg_inf`: -Inf, `zero`: 0.0, `neg_zero`: -0.0, `nan`: NaN, " +
"`nan_weird`: NaN(111111111111000000000000000111100000000000011110000000000000001), " +
"`i32`: 42, `i64`: int64(42)}",
Expand All @@ -122,7 +123,8 @@ func TestLogging(t *testing.T) {
"id": ObjectID(420000000000000000000000),
"bool": true,
"time": 2023-03-06T09:14:42.123Z,
}`, `"`, "`"),
}`, `"`, "`",
),
m: "{`null`: null, `id`: ObjectID(420000000000000000000000), `bool`: true, `time`: 2023-03-06T09:14:42.123Z}",
},
{
Expand Down Expand Up @@ -162,7 +164,8 @@ func TestLogging(t *testing.T) {
"qux",
],
],
}`, `"`, "`"),
}`, `"`, "`",
),
m: "{`doc`: {`foo`: `bar`, `baz`: {`qux`: `quux`}}, `doc_raw`: RawDocument<1>, `doc_empty`: {}, `array`: [`foo`, `bar`, [`baz`, `qux`]]}",
},
{
Expand Down Expand Up @@ -212,7 +215,8 @@ func TestLogging(t *testing.T) {
],
},
],
}`, `"`, "`"),
}`, `"`, "`",
),
m: "{`f`: [{`f`: [{`f`: [{`f`: [{`f`: [{`f`: [{`f`: [{`f`: [{`f`: [{`f`: [null]}]}]}]}]}]}]}]}]}]}",
},
{
Expand Down

0 comments on commit e7d08ff

Please sign in to comment.