You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: connection_test.go
    path of file: ./repos/FerretDB/integration/users
    
    the code of the file until where you have to start completion: // Copyright 2021 FerretDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package users

import (
	"context"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
	"go.mongodb.org/mongo-driver/x/mongo/driver/topology"

	"github.com/FerretDB/FerretDB/integration"
	"github.com/FerretDB/FerretDB/integration/setup"
	"github.com/FerretDB/FerretDB/internal/util/testutil/testtb"
)

func TestAuthentication(t *testing.T) {
	t.Parallel()

	s := setup.SetupWithOpts(t, nil)
	ctx := s.Ctx
	collection := s.Collection
	db := collection.Database()

	testCases := map[string]struct { //nolint:vet // for readability
		username       string
		password       string
		updatePassword string   // if true, the password will be updated to this one after the us
    
func TestAuthenticationEnableNewAuthPLAIN(t *testing.T) {
	setup.SkipForMongoDB(t, "PLAIN mechanism is not supported by MongoDB")

	t.Parallel()

	s := setup.SetupWithOpts(t, nil)
	ctx, cName, db := s.Ctx, s.Collection.Name(), s.Collection.Database()

	err := db.RunCommand(ctx, bson.D{
		{"createUser", "plain-user"},
		{"roles", bson.A{}},
		{"pwd", "correct"},
		{"mechanisms", bson.A{"PLAIN"}},
	}).Err()
	require.NoError(t, err, "cannot create user")

	err = db.RunCommand(ctx, bson.D{
		{"createUser", "scram-user"},
		{"roles", bson.A{}},
		{"pwd", "correct"},
		{"mechanisms", bson.A{"SCRAM-SHA-1", "SCRAM-SHA-256"}},
	}).Err()
	require.NoError(t, err, "cannot create user")

	testCases := map[string]struct {
		username  string
		password  string
		mechanism string

		err *mongo.CommandError
	}{
		"Success": {
			username:  "plain-user",
			password:  "correct",
			mechanism: "PLAIN",
		},
		"BadPassword": {
			username:  "plain-user",
			password:  "wrong",
			mechanism: "PLAIN",
			err: &mongo.CommandError{
				Code:    18,
				Name:    "AuthenticationFailed",
				Message: "Authentication failed",
			},
		},
		"NonExistentUser": {
			username:  "not-found-user",
			password:  "something",
			mechanism: "PLAIN",
			err: &mongo.CommandError{
				Code:    18,
				Name:    "AuthenticationFailed",
				Message: "Authentication failed",
			},
		},
		"NonPLAINUser": {
			username:  "scram-user",
			password:  "correct",
			mechanism: "PLAIN",
			err: &mongo.CommandError{
				Code:    334,
				Name:    "ErrMechanismUnavailable",
				Message: "Unable to use PLAIN based authentication for user without any PLAIN credentials registered",
			},
		},
	}

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

			credential := options.Credential{
				AuthMechanism: tc.mechanism,
				AuthSource:    db.Name(),
				Username:      tc.username,
				Password:      tc.password,
			}

			opts := options.Client().ApplyURI(s.MongoDBURI).SetAuth(credential)

			client, err := mongo.Connect(ctx, opts)
			require.NoError(t, err, "cannot connect to MongoDB")

			t.Cleanup(func() {
				require.NoError(t, client.Disconnect(ctx))
			})

			c := client.Database(db.Name()).Collection(cName)
			_, err = c.InsertOne(ctx, bson.D{{"ping", "pong"}})

			if tc.err != nil {
				integration.AssertEqualCommandError(t, *tc.err, err)
				return
			}

			require.NoError(t, err, "cannot insert document")
		})
	}
}