Skip to content

Commit

Permalink
code review remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
henvic committed Mar 5, 2024
1 parent 0173295 commit efd071b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 42 deletions.
1 change: 0 additions & 1 deletion integration/commands_administration_test.go
Expand Up @@ -252,7 +252,6 @@ func TestCommandsAdministrationListDatabases(t *testing.T) {
}

for name, tc := range testCases {
tc, name := tc, name
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion integration/create_test.go
Expand Up @@ -333,7 +333,6 @@ func TestCreateCappedCommandInvalidSpec(t *testing.T) {
},
},
} {
tc, name := tc, name
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
17 changes: 8 additions & 9 deletions integration/hello_command_test.go
Expand Up @@ -133,8 +133,6 @@ func TestHelloWithSupportedMechs(t *testing.T) {
}

for name, tc := range testCases {
tc, name := tc, name

t.Run(name, func(t *testing.T) {
t.Parallel()

Expand All @@ -156,13 +154,6 @@ func TestHelloWithSupportedMechs(t *testing.T) {

actual := ConvertDocument(t, res)

if tc.mechs != nil {
mechanisms := must.NotFail(actual.Get("saslSupportedMechs"))
assert.True(t, mechanisms.(*types.Array).ContainsAll(tc.mechs))
} else {
assert.False(t, actual.Has("saslSupportedMechs"))
}

assert.Equal(t, must.NotFail(actual.Get("isWritablePrimary")), true)
assert.Equal(t, must.NotFail(actual.Get("maxBsonObjectSize")), int32(16777216))
assert.Equal(t, must.NotFail(actual.Get("maxMessageSizeBytes")), int32(48000000))
Expand All @@ -174,6 +165,14 @@ func TestHelloWithSupportedMechs(t *testing.T) {
assert.Equal(t, must.NotFail(actual.Get("maxWireVersion")), int32(21))
assert.Equal(t, must.NotFail(actual.Get("readOnly")), false)
assert.Equal(t, must.NotFail(actual.Get("ok")), float64(1))

if tc.mechs == nil {
assert.False(t, actual.Has("saslSupportedMechs"))
return
}

mechanisms := must.NotFail(actual.Get("saslSupportedMechs"))
assert.True(t, mechanisms.(*types.Array).ContainsAll(tc.mechs))
})
}
}
1 change: 0 additions & 1 deletion integration/query_test.go
Expand Up @@ -728,7 +728,6 @@ func TestQueryCommandLimitPushDown(t *testing.T) {
limitPushdown: noPushdown,
},
} {
tc, name := tc, name
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion integration/setup/helpers.go
Expand Up @@ -89,7 +89,7 @@ func FailsForMongoDB(tb testtb.TB, reason string) testtb.TB {

// SkipForMongoDB skips the current test for MongoDB.
//
// Use [FailsForMongoDB] in new code.
// Deprecated: Use [FailsForMongoDB] in new code.
func SkipForMongoDB(tb testtb.TB, reason string) {
tb.Helper()

Expand Down
34 changes: 6 additions & 28 deletions integration/users/usersinfo_test.go
Expand Up @@ -532,7 +532,6 @@ func TestUsersinfo(t *testing.T) {
}

for name, tc := range testCases {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -575,28 +574,23 @@ func TestUsersinfo(t *testing.T) {

require.True(t, (tc.hasUser == nil) != (tc.expected == nil))

payload := integration.ConvertDocument(t, tc.payload)

if tc.showCredentials != nil {
cred, ok := actualUser.Get("credentials")
assert.Nil(t, ok, "credentials not found")
cred := must.NotFail(actualUser.Get("credentials")).(*types.Document)

for _, typ := range tc.showCredentials {
switch typ {
case "PLAIN":
assertPlainCredentials(t, "PLAIN", cred.(*types.Document))
assertPlainCredentials(t, "PLAIN", cred)
case "SCRAM-SHA-1":
assertSCRAMSHA1Credentials(t, "SCRAM-SHA-1", cred.(*types.Document))
assertSCRAMSHA1Credentials(t, "SCRAM-SHA-1", cred)
case "SCRAM-SHA-256":
assertSCRAMSHA256Credentials(t, "SCRAM-SHA-256", cred.(*types.Document))
assertSCRAMSHA256Credentials(t, "SCRAM-SHA-256", cred)
}
}
} else {
assert.False(t, actualUser.Has("credentials"))
}

if payload.Has("mechanisms") {
assertUsersinfoMechanisms(t, payload, actualUser)
if len(tc.showCredentials) == 0 {
assert.False(t, actualUser.Has("credentials"))
}

foundUsers[must.NotFail(actualUser.Get("_id")).(string)] = struct{}{}
Expand All @@ -623,19 +617,3 @@ func TestUsersinfo(t *testing.T) {
})
}
}

func assertUsersinfoMechanisms(t *testing.T, payload, user *types.Document) {
payloadMechanisms := must.NotFail(payload.Get("mechanisms")).(*types.Array)

if payloadMechanisms.Contains("PLAIN") {
assertPlainCredentials(t, "PLAIN", must.NotFail(user.Get("credentials")).(*types.Document))
}

if payloadMechanisms.Contains("SCRAM-SHA-1") {
assertSCRAMSHA1Credentials(t, "SCRAM-SHA-1", must.NotFail(user.Get("credentials")).(*types.Document))
}

if payloadMechanisms.Contains("SCRAM-SHA-256") {
assertSCRAMSHA256Credentials(t, "SCRAM-SHA-256", must.NotFail(user.Get("credentials")).(*types.Document))
}
}
1 change: 0 additions & 1 deletion internal/handler/handlerparams/typecode_test.go
Expand Up @@ -51,7 +51,6 @@ func TestHasSameTypeElements(t *testing.T) {
same: true,
},
} {
tc, name := tc, name
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit efd071b

Please sign in to comment.