<commit_before>package cts

import (
	"fmt"
	"os"
	"os/user"
	"strings"
	"testing"
	"time"

	"github.com/algolia/algoliasearch-client-go/algolia/search"
	"github.com/stretchr/testify/require"
)

func InitSearchClient1AndIndex(t *testing.T) (*search.Client, *search.Index, string) {
	c := InitSearchClient1(t)
	canonicalName := GenerateCanonicalPrefixName()
	indexName := canonicalName + "_" + t.Name()
	indexName = strings.Replace(indexName, "/", "_", -1)
	indexName = strings.Replace(indexName, " ", "_", -1)
	i := c.InitIndex(indexName)
	return c, i, indexName
}

func InitSearchClient1(t *testing.T) *search.Client {
	return initSearchClientWith(t, "ALGOLIA_APPLICATION_ID_1", "ALGOLIA_ADMIN_KEY_1")
}

func InitSearchClient2(t *testing.T) *search.Client {
	return initSearchClientWith(t, "ALGOLIA_APPLICATION_ID_2", "ALGOLIA_ADMIN_KEY_2")
}

func InitSearchClientMCM(t *testing.T) *search.Client {
	return initSearchClientWith(t, "ALGOLIA_APPLICATION_ID_MCM", "ALGOLIA_ADMIN_KEY_MCM")
}

func initSearchClientWith(t *testing.T, appIDEnvVar, apiKeyEnvVar string) *search.Client {
	appID, key := GetTestingCredentials(t, appIDEnvVar, apiKeyEnvVar)
	c := search.NewClient(appID, key)
	go deleteOldIndices(c)
	return c
}

func GetTestingCredentials(t *testing.T, appIDEnvVar, apiKeyEnvVar string) (string, string) {
	appID := os.Getenv(appIDEnvVar)
	key := os.Getenv(apiKeyEnvVar)
	require.NotEmpty(t, appID)
	require.NotEmpty(t, key)
	return appID, key
}

func GenerateCanonicalPrefixName() string {
	var instanceName string

	if build := os.Getenv("TRAVIS_JOB_NUMBER"); build != "" {
		instanceName = build
	} else {
		if user, err := user.Current(); err == nil {
			instanceName = user.Username<commit_msg>changed: ensure debug logs in tests are clean<commit_after>package cts

import (
	"fmt"
	"os"
	"os/user"
	"strings"
	"testing"
	"time"

	"github.com/algolia/algoliasearch-client-go/algolia/search"
	"github.com/stretchr/testify/require"
)

func InitSearchClient1AndIndex(t *testing.T) (*search.Client, *search.Index, string) {
	c := InitSearchClient1(t)
	canonicalName := GenerateCanonicalPrefixName()
	indexName := canonicalName + "_" + t.Name()
	indexName = strings.Replace(indexName, "/", "_", -1)
	indexName = strings.Replace(indexName, " ", "_", -1)
	i := c.InitIndex(indexName)
	return c, i, indexName
}

func InitSearchClient1(t *testing.T) *search.Client {
	return initSearchClientWith(t, "ALGOLIA_APPLICATION_ID_1", "ALGOLIA_ADMIN_KEY_1")
}

func InitSearchClient2(t *testing.T) *search.Client {
	return initSearchClientWith(t, "ALGOLIA_APPLICATION_ID_2", "ALGOLIA_ADMIN_KEY_2")
}

func InitSearchClientMCM(t *testing.T) *search.Client {
	return initSearchClientWith(t, "ALGOLIA_APPLICATION_ID_MCM", "ALGOLIA_ADMIN_KEY_MCM")
}

func initSearchClientWith(t *testing.T, appIDEnvVar, apiKeyEnvVar string) *search.Client {
	appID, key := GetTestingCredentials(t, appIDEnvVar, apiKeyEnvVar)
	c := search.NewClient(appID, key)
	deleteOldIndices(c)
	return c
}

func GetTestingCredentials(t *testing.T, appIDEnvVar, apiKeyEnvVar string) (string, string) {
	appID := os.Getenv(appIDEnvVar)
	key := os.Getenv(apiKeyEnvVar)
	require.NotEmpty(t, appID)
	require.NotEmpty(t, key)
	return appID, key
}

func GenerateCanonicalPrefixName() string {
	var instanceName string

	if build := os.Getenv("TRAVIS_JOB_NUMBER"); build != "" {
		instanceName = build
	} else {
		if user, err := user.Current(); err == nil {
			instanceName = user.Username
{'fraction_non_alphanumeric': 0.1337394836089353, 'fraction_numerical': 0.005802146794313896, 'mean_word_length': 5.854870775347912, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6302798', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1287, 'n_words': 243}