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: states_test.go
    path of file: ./repos/magistrala/twins/mongodb
    
    the code of the file until where you have to start completion: // Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package mongodb_test

import (
	"context"
	"fmt"
	"testing"
	"time"

	"github.com/absmach/magistrala/twins"
	"github.com/absmach/magistrala/twins/mongodb"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
)

func TestStateSave(t *testing.T) {
	client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(addr))
	require.Nil(t, err, fmt.Sprintf("Creating new MongoDB client expected to succeed: %s.\n", err))

	db := client.Database(testDB)
	repo := mongodb.NewStateRepository(db)

	twid, err := idProvider.ID()
	assert.Nil(t, err, fmt.Sprintf("got unexpec
    
func TestStatesRetrieveAll(t *testing.T) {
	client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(addr))
	require.Nil(t, err, fmt.Sprintf("Creating new MongoDB client expected to succeed: %s.\n", err))

	db := client.Database(testDB)
	_, err = db.Collection("states").DeleteMany(context.Background(), bson.D{})
	require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))

	repo := mongodb.NewStateRepository(db)

	twid, err := idProvider.ID()
	assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))

	n := uint64(10)
	for i := uint64(0); i < n; i++ {
		st := twins.State{
			TwinID:  twid,
			ID:      int64(i),
			Created: time.Now(),
		}

		err = repo.Save(context.Background(), st)
		require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
	}

	cases := map[string]struct {
		twid   string
		limit  uint64
		offset uint64
		size   uint64
		total  uint64
	}{
		"retrieve all states with existing twin": {
			twid:   twid,
			offset: 0,
			limit:  n,
			size:   n,
			total:  n,
		},
		"retrieve subset of states with existing twin": {
			twid:   twid,
			offset: 0,
			limit:  n / 2,
			size:   n / 2,
			total:  n,
		},
		"retrieve states with non-existing twin": {
			twid:   wrongValue,
			offset: 0,
			limit:  n,
			size:   0,
			total:  0,
		},
	}

	for desc, tc := range cases {
		page, err := repo.RetrieveAll(context.Background(), tc.offset, tc.limit, tc.twid)
		size := uint64(len(page.States))
		assert.Equal(t, tc.size, size, fmt.Sprintf("%s: expected %d got %d\n", desc, tc.size, size))
		assert.Equal(t, tc.total, page.Total, fmt.Sprintf("%s: expected %d got %d\n", desc, tc.total, page.Total))
		assert.Nil(t, err, fmt.Sprintf("%s: expected no error got %d\n", desc, err))
	}
}