<commit_before>package server_test

import (
	"context"
	"crypto/sha256"
	"encoding/hex"
	"errors"
	"io/ioutil"
	"net/http/httptest"
	"testing"
	"time"

	"github.com/google/go-cmp/cmp"

	"github.com/kopia/kopia/internal/auth"
	"github.com/kopia/kopia/internal/repotesting"
	"github.com/kopia/kopia/internal/server"
	"github.com/kopia/kopia/internal/testlogging"
	"github.com/kopia/kopia/repo"
	"github.com/kopia/kopia/repo/content"
	"github.com/kopia/kopia/repo/manifest"
	"github.com/kopia/kopia/repo/object"
	"github.com/kopia/kopia/snapshot"
)

const (
	testUsername = "foo"
	testHostname = "bar"
	testPassword = "<PASSWORD>"
	testPathname = "/tmp/path"
)

// nolint:thelper
func startServer(ctx context.Context, t *testing.T) *repo.APIServerInfo {
	var env repotesting.Environment

	env.Setup(t)
	t.Cleanup(func() { env.Close(ctx, t) })

	s, err := server.New(ctx, server.Options{
		ConfigFile:      env.ConfigFile(),
		Authorizer:      auth.LegacyAuthorizerForUser,
		Authenticator:   auth.AuthenticateSingleUser(testUsername+"@"+testHostname, testPassword),
		RefreshInterval: 1 * time.Minute,
	})

	s.SetRepository(ctx, env.Repository)
<commit_msg>server: test flake fix (#839)<commit_after>package server_test

import (
	"context"
	"crypto/sha256"
	"encoding/hex"
	"errors"
	"io/ioutil"
	"net/http/httptest"
	"testing"
	"time"

	"github.com/google/go-cmp/cmp"

	"github.com/kopia/kopia/internal/auth"
	"github.com/kopia/kopia/internal/repotesting"
	"github.com/kopia/kopia/internal/server"
	"github.com/kopia/kopia/internal/testlogging"
	"github.com/kopia/kopia/repo"
	"github.com/kopia/kopia/repo/content"
	"github.com/kopia/kopia/repo/manifest"
	"github.com/kopia/kopia/repo/object"
	"github.com/kopia/kopia/snapshot"
)

const (
	testUsername = "foo"
	testHostname = "bar"
	testPassword = "<PASSWORD>"
	testPathname = "/tmp/path"
)

// nolint:thelper
func startServer(ctx context.Context, t *testing.T) *repo.APIServerInfo {
	var env repotesting.Environment

	env.Setup(t)
	t.Cleanup(func() { env.Close(ctx, t) })

	s, err := server.New(ctx, server.Options{
		ConfigFile:      env.ConfigFile(),
		Authorizer:      auth.LegacyAuthorizerForUser,
		Authenticator:   auth.AuthenticateSingleUser(testUsername+"@"+testHostname, testPassword),
		RefreshInterval: 1 * time.Minute,
	})

	s.SetRepository(ctx, env.Repository)

	// ensure we disconnect the repository before shutting down the server.
	t.Cleanup(func() { s.SetRepository(ctx, nil) })

{'fraction_non_alphanumeric': 0.1518987341772152, 'fraction_numerical': 0.00449162923642303, 'mean_word_length': 4.632183908045977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3842535', 'n_tokens_mistral': 1019, 'n_tokens_neox': 944, 'n_words': 137}