Skip to content

Commit

Permalink
Tweak wirebson tests (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Dec 25, 2024
1 parent b5b86d0 commit 53d662e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 24 deletions.
33 changes: 22 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
---
run:
timeout: 3m
linters:
disable-all: true
enable:
# TODO https://github.com/FerretDB/wire/issues/4
- asciicheck
- gci
- goimports
- govet
- staticcheck

# https://golangci-lint.run/usage/linters/
linters-settings:
# asciicheck
gci:
sections:
- standard
- default
- prefix(github.com/FerretDB/wire)
skip-generated: false
goimports:
local-prefixes: github.com/FerretDB/wire
govet:
enable-all: true
settings:
shadow:
strict: true
staticcheck:
checks:
- all

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

issues:
max-issues-per-linter: 0
max-same-issues: 0

exclude-use-default: false
exclude-rules: []

run:
timeout: 3m
2 changes: 1 addition & 1 deletion bits.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const flagsSize = 4

func (flags flags) strings(bitStringer func(flagBit) string) []string {
res := make([]string, 0, 2)
for shift := 0; shift < 32; shift++ {
for shift := range 32 {
bit := flags >> shift
if bit&1 == 1 {
res = append(res, bitStringer(1<<shift))
Expand Down
2 changes: 2 additions & 0 deletions op_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
)

// CheckNaNs set to true returns an error if float64 NaN value is present in wire messages.
//
// TODO https://github.com/FerretDB/wire/issues/73
var CheckNaNs bool

// OpMsg is the main wire protocol message type.
Expand Down
4 changes: 2 additions & 2 deletions op_reply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var replyTestCases = []testCase{
"maxBsonObjectSize", int32(16777216),
"maxMessageSizeBytes", int32(48000000),
"maxWriteBatchSize", int32(100000),
"localTime", time.Date(2021, time.July, 24, 12, 54, 41, 571000000, time.UTC).Local(),
"localTime", time.Date(2021, time.July, 24, 12, 54, 41, 571000000, time.UTC),
"logicalSessionTimeoutMinutes", int32(30),
"connectionId", int32(28),
"minWireVersion", int32(0),
Expand Down Expand Up @@ -103,7 +103,7 @@ var replyTestCases = []testCase{
"maxBsonObjectSize", int32(16777216),
"maxMessageSizeBytes", int32(48000000),
"maxWriteBatchSize", int32(100000),
"localTime", time.Date(2021, time.July, 24, 12, 54, 41, 592000000, time.UTC).Local(),
"localTime", time.Date(2021, time.July, 24, 12, 54, 41, 592000000, time.UTC),
"logicalSessionTimeoutMinutes", int32(30),
"connectionId", int32(29),
"minWireVersion", int32(0),
Expand Down
2 changes: 1 addition & 1 deletion wire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func lastErr(err error) error {
}
}

var lastUpdate = time.Date(2020, 2, 15, 9, 34, 33, 0, time.UTC).Local()
var lastUpdate = time.Date(2020, 2, 15, 9, 34, 33, 0, time.UTC)

//nolint:vet // for readability
type testCase struct {
Expand Down
18 changes: 9 additions & 9 deletions wirebson/bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package wirebson

import (
"encoding/hex"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -42,8 +43,6 @@ type decodeTestCase struct {
name string
raw RawDocument

oldOk bool

findRawErr error
findRawL int
decodeErr error
Expand Down Expand Up @@ -272,12 +271,12 @@ var normalTestCases = []normalTestCase{
),
"binary", MustArray(
Binary{Subtype: BinaryUser, B: []byte{0x42}},
Binary{Subtype: BinaryGeneric, B: []byte{}},
Binary{},
),
"bool", MustArray(true, false),
"datetime", MustArray(
time.Date(2021, 7, 27, 9, 35, 42, 123000000, time.UTC).Local(),
time.Time{}.Local(),
time.Date(2021, 7, 27, 9, 35, 42, 123000000, time.UTC),
time.Time{},
),
"document", MustArray(
MustDocument("foo", ""),
Expand Down Expand Up @@ -581,7 +580,8 @@ var normalTestCases = []normalTestCase{
raw: RawDocument{
0x18, 0x00, 0x00, 0x00,
0x13, 0x66, 0x00,
0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
},
doc: MustDocument(
Expand Down Expand Up @@ -677,7 +677,6 @@ var decodeTestCases = []decodeTestCase{
0x00, // end of document
0x00, // extra byte
},
oldOk: true,
findRawL: 5,
decodeErr: ErrDecodeInvalidInput,
},
Expand Down Expand Up @@ -776,6 +775,7 @@ func TestNormal(t *testing.T) {
t.Run("DecodeDeepEncode", func(t *testing.T) {
doc, err := tc.raw.DecodeDeep()
require.NoError(t, err)
assert.Equal(t, tc.doc, doc)

ls := doc.LogValue().Resolve().String()
assert.NotContains(t, ls, "panicked")
Expand All @@ -784,9 +784,9 @@ func TestNormal(t *testing.T) {
assert.NotEmpty(t, doc.LogMessage())
assert.Equal(t, strings.ReplaceAll(testutil.Unindent(tc.mi), `"`, "`"), doc.LogMessageIndent())

raw, err := doc.Encode()
raw, err := tc.doc.Encode()
require.NoError(t, err)
assert.Equal(t, tc.raw, raw)
assert.Equal(t, tc.raw, raw, "actual:\n"+hex.Dump(raw))
})
})
}
Expand Down

0 comments on commit 53d662e

Please sign in to comment.