<commit_before>package algoliasearch

import (
	"sync"
	"testing"
	"time"
)

func deleteClientKey(t *testing.T, c Client, key string) {
	_, err := c.DeleteUserKey(key)
	if err != nil {
		t.Fatalf("deleteClientKey: Cannot delete key: %s", err)
	}
}

func waitClientKey(t *testing.T, c Client, keyID string, f func(k Key) bool) {
	retries := 10

	for r := 0; r < retries; r++ {
		key, err := c.GetUserKey(keyID)

		if err == nil && (f == nil || f(key)) {
			return
		}
		time.Sleep(1 * time.Second)
	}
<commit_msg>Add Client test cases for index operations<commit_after>package algoliasearch

import (
	"sync"
	"testing"
	"time"
)

func TestClientOperations(t *testing.T) {
	c, i := initClientAndIndex(t, "TestClientOperations")

	objectID := addOneObject(t, c, i)

	// Test CopyIndex
	{
		res, err := c.CopyIndex("TestClientOperations", "TestClientOperations_copy")
		if err != nil {
			t.Fatalf("TestClientOperations: Cannot copy the index: %s", err)
		}

		waitTask(t, i, res.TaskID)
	}

	// Test MoveIndex
	i = c.InitIndex("TestClientOperations_copy")
	{
		res, err := c.MoveIndex("TestClientOperations_copy", "TestClientOperations_move")
		if err != nil {
			t.Fatalf("TestClientOperations: Cannot move the index: %s", err)
		}

		waitTask(t, i, res.TaskID)
	}

	// Test ClearIndex
	i = c.InitIndex("TestClientOperations_move")
	{
		res, err := c.ClearIndex("TestClientOperations_move")
		if err != nil {
			t.Fatalf("TestClear: Cannot clear the index: %s, err")
		}

		waitTask(t, i, res.TaskID)

		_, err = i.GetObject(objectID, nil)
		if err == nil || err.Error() != "{\"message\":\"ObjectID does not exist\",\"status\":404}\n" {
			t.Fatalf("TestClientOperations: Object %s should be deleted after clear: %s", objectID, err)
		}
	}

	// Test DeleteIndex
	{
		_, err := c.DeleteIndex("TestClientOperations_move")
		if err != nil {
			t.Fatalf("TestClientOperations: Cannot delete the moved index: %s", err)
		}
	}
}

func deleteClientKey(t *testing.T, c Client, key string) {
	_, err := c.DeleteUserKey(key)
	if err != nil {
		t.Fatalf("deleteClientKey: Cannot delete key: %s", err)
	}
}

func waitClientKey(t *testing.T, c Client, keyID string, f func(k Key) bool) {
	retries := 10

	for r := 0; r < retries; r++ {
		key, err := c.GetUserKey(keyID)

		if err == nil && (f == nil || f(key)) {
			return
		}
		time.Sleep(1 * time.Second)
	}

{'fraction_non_alphanumeric': 0.15728900255754474, 'fraction_numerical': 0.004688832054560955, 'mean_word_length': 3.789795918367347, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7529542', 'n_tokens_mistral': 927, 'n_tokens_neox': 876, 'n_words': 230}