Skip to content
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

Remove switching between block and flow log styles #39

Merged
merged 3 commits into from
Sep 13, 2024
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/FerretDB/wire

go 1.22
go 1.23

toolchain go1.22.6
toolchain go1.23.1

require (
github.com/stretchr/testify v1.9.0
Expand Down
7 changes: 2 additions & 5 deletions msg_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ type MsgBody interface {

fmt.Stringer

// StringBlock returns an indented string representation for logging.
StringBlock() string

// StringFlow returns an unindented string representation for logging.
StringFlow() string
// StringIndent returns an indented string representation for logging.
StringIndent() string

// check performs deep (and slow) validity check.
check() error
Expand Down
13 changes: 4 additions & 9 deletions op_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,14 @@ func (msg *OpMsg) logMessage(logFunc func(v any) string) string {
return logFunc(m)
}

// String returns a string representation for logging.
// String returns an string representation for logging.
func (msg *OpMsg) String() string {
return msg.logMessage(wirebson.LogMessage)
}

// StringBlock returns an indented string representation for logging.
func (msg *OpMsg) StringBlock() string {
return msg.logMessage(wirebson.LogMessageBlock)
}

// StringFlow returns an unindented string representation for logging.
func (msg *OpMsg) StringFlow() string {
return msg.logMessage(wirebson.LogMessageFlow)
// StringIndent returns an indented string representation for logging.
func (msg *OpMsg) StringIndent() string {
return msg.logMessage(wirebson.LogMessageIndent)
}

// check interfaces
Expand Down
93 changes: 75 additions & 18 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",
m: `
b: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand All @@ -62,7 +62,9 @@ var msgTestCases = []testCase{
"Kind": 0,
"Document": {
"buildInfo": 1,
"lsid": {"id": Binary(uuid:oxnytKF1QMe456OjLsJWvg==)},
"lsid": {
"id": Binary(uuid:oxnytKF1QMe456OjLsJWvg==),
},
"$db": "admin",
},
},
Expand Down Expand Up @@ -126,7 +128,7 @@ var msgTestCases = []testCase{
}},
},
command: "version",
m: `
b: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand All @@ -140,7 +142,12 @@ var msgTestCases = []testCase{
"allocator": "tcmalloc",
"javascriptEngine": "mozjs",
"sysInfo": "deprecated",
"versionArray": [5, 0, 0, 0],
"versionArray": [
5,
0,
0,
0,
],
"openssl": {
"running": "OpenSSL 1.1.1f 31 Mar 2020",
"compiled": "OpenSSL 1.1.1f 31 Mar 2020",
Expand All @@ -160,7 +167,11 @@ var msgTestCases = []testCase{
"bits": 64,
"debug": false,
"maxBsonObjectSize": 16777216,
"storageEngines": ["devnull", "ephemeralForTest", "wiredTiger"],
"storageEngines": [
"devnull",
"ephemeralForTest",
"wiredTiger",
],
"ok": 1.0,
},
},
Expand Down Expand Up @@ -210,7 +221,7 @@ var msgTestCases = []testCase{
},
},
command: "insert",
m: `
b: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand All @@ -220,7 +231,9 @@ var msgTestCases = []testCase{
"Document": {
"insert": "actor",
"ordered": true,
"writeConcern": {"w": "majority"},
"writeConcern": {
"w": "majority",
},
"$db": "monila",
},
},
Expand Down Expand Up @@ -302,7 +315,7 @@ var msgTestCases = []testCase{
}},
},
command: "insert",
m: `
b: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand All @@ -311,7 +324,12 @@ var msgTestCases = []testCase{
"Kind": 0,
"Document": {
"insert": "values",
"documents": [{"v": NaN, "_id": ObjectID(6377f213757c0babdebc2f6a)}],
"documents": [
{
"v": NaN,
"_id": ObjectID(6377f213757c0babdebc2f6a),
},
],
"ordered": true,
"$db": "test",
},
Expand Down Expand Up @@ -371,19 +389,28 @@ var msgTestCases = []testCase{
},
},
command: "insert",
m: `
b: `
{
"FlagBits": "[]",
"Checksum": int64(0),
"Sections": [
{
"Kind": 0,
"Document": {"insert": "TestInsertSimple", "ordered": true, "$db": "testinsertsimple"},
"Document": {
"insert": "TestInsertSimple",
"ordered": true,
"$db": "testinsertsimple",
},
},
{
"Kind": 1,
"Identifier": "documents",
"Documents": [{"_id": ObjectID(637cfad88dc3cecde38e1e6b), "v": -0.0}],
"Documents": [
{
"_id": ObjectID(637cfad88dc3cecde38e1e6b),
"v": -0.0,
},
],
},
],
}`,
Expand Down Expand Up @@ -448,17 +475,29 @@ var msgTestCases = []testCase{
checksum: 1737537506,
},
command: "insert",
m: `
b: `
{
"FlagBits": "[checksumPresent]",
"Checksum": int64(1737537506),
"Sections": [
{
"Kind": 1,
"Identifier": "documents",
"Documents": [{"_id": ObjectID(638cec46aa778bf370105429), "a": 3.0}],
"Documents": [
{
"_id": ObjectID(638cec46aa778bf370105429),
"a": 3.0,
},
],
},
{
"Kind": 0,
"Document": {
"insert": "foo",
"ordered": true,
"$db": "test",
},
},
{"Kind": 0, "Document": {"insert": "foo", "ordered": true, "$db": "test"}},
],
}`,
},
Expand Down Expand Up @@ -545,7 +584,7 @@ var msgTestCases = []testCase{
checksum: 2932997361,
},
command: "update",
m: `
b: `
{
"FlagBits": "[checksumPresent]",
"Checksum": int64(2932997361),
Expand All @@ -554,10 +593,28 @@ var msgTestCases = []testCase{
"Kind": 1,
"Identifier": "updates",
"Documents": [
{"q": {"a": 20.0}, "u": {"$inc": {"a": 1.0}}, "multi": false, "upsert": false},
{
"q": {
"a": 20.0,
},
"u": {
"$inc": {
"a": 1.0,
},
},
"multi": false,
"upsert": false,
},
],
},
{"Kind": 0, "Document": {"update": "foo", "ordered": true, "$db": "test"}},
{
"Kind": 0,
"Document": {
"update": "foo",
"ordered": true,
"$db": "test",
},
},
],
}`,
},
Expand Down
13 changes: 4 additions & 9 deletions op_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,14 @@ func (query *OpQuery) logMessage(logFunc func(v any) string) string {
return logFunc(m)
}

// String returns a string representation for logging.
// String returns an string representation for logging.
func (query *OpQuery) String() string {
return query.logMessage(wirebson.LogMessage)
}

// StringBlock returns an indented string representation for logging.
func (query *OpQuery) StringBlock() string {
return query.logMessage(wirebson.LogMessageBlock)
}

// StringFlow returns an unindented string representation for logging.
func (query *OpQuery) StringFlow() string {
return query.logMessage(wirebson.LogMessageFlow)
// StringIndent returns an indented string representation for logging.
func (query *OpQuery) StringIndent() string {
return query.logMessage(wirebson.LogMessageIndent)
}

// check interfaces
Expand Down
30 changes: 22 additions & 8 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,
},
m: `
b: `
{
"Flags": "[]",
"FullCollectionName": "admin.$cmd",
Expand All @@ -69,17 +69,24 @@ var queryTestCases = []testCase{
"Query": {
"ismaster": true,
"client": {
"driver": {"name": "nodejs", "version": "4.0.0-beta.6"},
"driver": {
"name": "nodejs",
"version": "4.0.0-beta.6",
},
"os": {
"type": "Darwin",
"name": "darwin",
"architecture": "x64",
"version": "20.6.0",
},
"platform": "Node.js v14.17.3, LE (unified)|Node.js v14.17.3, LE (unified)",
"application": {"name": "mongosh 1.0.1"},
"application": {
"name": "mongosh 1.0.1",
},
},
"compression": ["none"],
"compression": [
"none",
],
"loadBalanced": false,
},
}`,
Expand Down Expand Up @@ -122,7 +129,7 @@ var queryTestCases = []testCase{
),
returnFieldsSelector: nil,
},
m: `
b: `
{
"Flags": "[]",
"FullCollectionName": "admin.$cmd",
Expand All @@ -131,17 +138,24 @@ var queryTestCases = []testCase{
"Query": {
"ismaster": true,
"client": {
"driver": {"name": "nodejs", "version": "4.0.0-beta.6"},
"driver": {
"name": "nodejs",
"version": "4.0.0-beta.6",
},
"os": {
"type": "Darwin",
"name": "darwin",
"architecture": "x64",
"version": "20.6.0",
},
"platform": "Node.js v14.17.3, LE (unified)|Node.js v14.17.3, LE (unified)",
"application": {"name": "mongosh 1.0.1"},
"application": {
"name": "mongosh 1.0.1",
},
},
"compression": ["none"],
"compression": [
"none",
],
"loadBalanced": false,
},
}`,
Expand Down
13 changes: 4 additions & 9 deletions op_reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,14 @@ func (reply *OpReply) logMessage(logFunc func(v any) string) string {
return logFunc(m)
}

// String returns a string representation for logging.
// String returns an string representation for logging.
func (reply *OpReply) String() string {
return reply.logMessage(wirebson.LogMessage)
}

// StringBlock returns an indented string representation for logging.
func (reply *OpReply) StringBlock() string {
return reply.logMessage(wirebson.LogMessageBlock)
}

// StringFlow returns an unindented string representation for logging.
func (reply *OpReply) StringFlow() string {
return reply.logMessage(wirebson.LogMessageFlow)
// StringIndent returns an indented string representation for logging.
func (reply *OpReply) StringIndent() string {
return reply.logMessage(wirebson.LogMessageIndent)
}

// check interfaces
Expand Down
Loading
Loading