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: associations_many2many_test.go
    path of file: ./repos/gorm/tests
    
    the code of the file until where you have to start completion: package tests_test

import (
	"fmt"
	"sync"
	"testing"

	"gorm.io/gorm"
	"gorm.io/gorm/clause"
	. "gorm.io/gorm/utils/tests"
)

func TestMany2ManyAssociation(t *testing.T) {
	user := *GetUser("many2many", Config{Languages: 2})

	if err := DB.Create(&user).Error; err != nil {
		t.Fatalf("errors happened when create: %v", err)
	}

	CheckUser(t, user, user)

	// Find
	var user2 User
	DB.Find(&user2, "id = ?", user.ID)
	DB.Model(&user2).Association("Languages").Find(&user2.Languages)

	CheckUser(t, user2, user)

	// Count
	AssertAssociationCount(t, user, "Languages", 2, "")

	// Append
	language := Language{Code: "language-many2many-append", Name: "language-many2many-append"}
	DB.Create(&language)

	if err := DB.Model(&user2).Association("Languages").Append(&language); err != nil {

    
func TestSingleTableMany2ManyAssociation(t *testing.T) {
	user := *GetUser("many2many", Config{Friends: 2})

	if err := DB.Create(&user).Error; err != nil {
		t.Fatalf("errors happened when create: %v", err)
	}

	CheckUser(t, user, user)

	// Find
	var user2 User
	DB.Find(&user2, "id = ?", user.ID)
	DB.Model(&user2).Association("Friends").Find(&user2.Friends)

	CheckUser(t, user2, user)

	// Count
	AssertAssociationCount(t, user, "Friends", 2, "")

	// Append
	friend := *GetUser("friend", Config{})

	if err := DB.Model(&user2).Association("Friends").Append(&friend); err != nil {
		t.Fatalf("Error happened when append account, got %v", err)
	}

	user.Friends = append(user.Friends, &friend)
	CheckUser(t, user2, user)

	AssertAssociationCount(t, user, "Friends", 3, "AfterAppend")

	friends := []*User{GetUser("friend-append-1", Config{}), GetUser("friend-append-2", Config{})}

	if err := DB.Model(&user2).Association("Friends").Append(&friends); err != nil {
		t.Fatalf("Error happened when append friend, got %v", err)
	}

	user.Friends = append(user.Friends, friends...)

	CheckUser(t, user2, user)

	AssertAssociationCount(t, user, "Friends", 5, "AfterAppendSlice")

	// Replace
	friend2 := *GetUser("friend-replace-2", Config{})

	if err := DB.Model(&user2).Association("Friends").Replace(&friend2); err != nil {
		t.Fatalf("Error happened when append friend, got %v", err)
	}

	user.Friends = []*User{&friend2}
	CheckUser(t, user2, user)

	AssertAssociationCount(t, user2, "Friends", 1, "AfterReplace")

	// Delete
	if err := DB.Model(&user2).Association("Friends").Delete(&User{}); err != nil {
		t.Fatalf("Error happened when delete friend, got %v", err)
	}
	AssertAssociationCount(t, user2, "Friends", 1, "after delete non-existing data")

	if err := DB.Model(&user2).Association("Friends").Delete(&friend2); err != nil {
		t.Fatalf("Error happened when delete Friends, got %v", err)
	}
	AssertAssociationCount(t, user2, "Friends", 0, "after delete")

	// Prepare Data for Clear
	if err := DB.Model(&user2).Association("Friends").Append(&friend); err != nil {
		t.Fatalf("Error happened when append Friends, got %v", err)
	}

	AssertAssociationCount(t, user2, "Friends", 1, "after prepare data")

	// Clear
	if err := DB.Model(&user2).Association("Friends").Clear(); err != nil {
		t.Errorf("Error happened when clear Friends, got %v", err)
	}

	AssertAssociationCount(t, user2, "Friends", 0, "after clear")
}