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

Implement dropUser command #3866

Merged
merged 19 commits into from
Dec 20, 2023
Prev Previous commit
Next Next commit
wip
  • Loading branch information
henvic committed Dec 19, 2023
commit c16280371d1e851d60b8d9558dbf2f865dad2bf3
16 changes: 4 additions & 12 deletions integration/users/drop_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/FerretDB/FerretDB/integration"
"github.com/FerretDB/FerretDB/integration/setup"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/must"
"github.com/FerretDB/FerretDB/internal/util/testutil"
)
Expand Down Expand Up @@ -61,7 +60,6 @@ func TestDropUser(t *testing.T) {
err *mongo.CommandError
altMessage string
expected bson.D
skip string
}{
"NotFound": {
payload: bson.D{
Expand All @@ -78,20 +76,14 @@ func TestDropUser(t *testing.T) {
{"dropUser", "a_user"},
},
expected: bson.D{
{
"ok", float64(1),
},
{"ok", float64(1)},
},
},
}

for name, tc := range testCases {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
}

t.Parallel()

var res bson.D
Expand All @@ -111,14 +103,14 @@ func TestDropUser(t *testing.T) {
testutil.AssertEqual(t, expected, actual)

payload := integration.ConvertDocument(t, tc.payload)
assertUserNotFound(ctx, t, users, db.Name(), payload)
assertUserNotFound(ctx, t, users, db.Name(), must.NotFail(payload.Get("dropUser")).(string))
})
}
}

// assertUserNotFound checks it the user doesn't exist in the admin.system.users collection.
func assertUserNotFound(ctx context.Context, t testing.TB, users *mongo.Collection, dbName string, payload *types.Document) {
func assertUserNotFound(ctx context.Context, t testing.TB, users *mongo.Collection, dbName, username string) {
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
t.Helper()
err := users.FindOne(ctx, bson.D{{"user", must.NotFail(payload.Get("dropUser"))}}).Err()
err := users.FindOne(ctx, bson.D{{"user", username}}).Err()
require.Equal(t, mongo.ErrNoDocuments, err, `should return "no documents" error`)
}
Loading