<commit_before>package storage

import (
	"context"
	"testing"
	"time"

	"golang.org/x/oauth2"
)

func getDefaultStorageClientConfig() (clientConfig storageClientConfig) {
	return storageClientConfig{
		disableHTTP2:        true,
		maxConnsPerHost:     10,
		maxIdleConnsPerHost: 100,
		tokenSrc:            oauth2.StaticTokenSource(&oauth2.Token{}),
		timeOut:             800 * time.Millisecond,
		maxRetryDuration:    30 * time.Second,
		retryMultiplier:     2,
	}
}

func invokeAndVerifyStorageHandle(t *testing.T, sc storageClientConfig) {
	handleCreated, err := NewStorageHandle(context.Background(), sc)

	if err != nil {
		t.Errorf("Handle creation failure")
	}
	if handleCreated == nil {
		t.Fatalf("Storage handle is null")
	}
	if nil == handleCreated.client {
		t.Fatalf("Storage client handle is null")
	}
}

func TestNewStorageHandleHttp2Disabled(t *testing.T) {
	sc := getDefaultStorageClientConfig() // by default http2 disabled

	invokeAndVerifyStorageHandle(t, sc)
}

func TestNewStorageHandleHttp2Enabled(t *testing.T) {
	sc := getDefaultStorageClientConfig()
	sc.disableHTTP2 = false

	invokeAndVerifyStorageHandle(t, sc)
}

func TestNewStorageHandleWithZeroMaxConnsPerHost(t *testing.T) {
	sc := getDefaultStorageClientConfig()
	sc.maxConnsPerHost = 0

	invokeAndVerifyStorageHandle(t, sc)
}<commit_msg>Added the test using OgleMock<commit_after>package storage

import (
	"context"
	"testing"
	"time"

	"github.com/fsouza/fake-gcs-server/fakestorage"
	. "github.com/jacobsa/ogletest"
	"golang.org/x/oauth2"
)

const validBucketName string = "will-be-present-in-fake-server"
const invalidBucketName string = "will-not-be-present-in-fake-server"

func TestStorageHandle(t *testing.T) { RunTests(t) }

type StorageHandleTest struct {
}

func init() { RegisterTestSuite(&StorageHandleTest{}) }

func createFakeServer() (fakeServer *fakestorage.Server, err error) {
	fakeServer, err = fakestorage.NewServerWithOptions(fakestorage.Options{
		InitialObjects: []fakestorage.Object{
			{
				ObjectAttrs: fakestorage.ObjectAttrs{
					BucketName: validBucketName,
				},
			},
		},
		Host: "127.0.0.1",
		Port: 8081,
	})
	return
}

func (t *StorageHandleTest) TestBucketHandleWhenBucketExists() {
	server, err := createFakeServer()
	AssertEq(nil, err)
	defer server.Stop()

	fakeClient := server.Client()
	fakeStorageClient := &storageClient{client: fakeClient}
	bucketHandle, err := fakeStorageClient.BucketHandle(validBucketName)

	AssertEq(nil, err)
	AssertNe(nil, bucketHandle)
}

func (t *StorageHandleTest) TestBucketHandleWhenBucketDoesNotExist() {
	server, err := createFakeServer()
	AssertEq(nil, err)
	defer server.Stop()

	fakeClient := server.Client()
	fakeStorageClient := &storageClient{client: fakeClient}
	bucketHandle, err := fakeStorageClient.BucketHandle(invalidBucketName)

	AssertNe(nil, err)
	AssertEq(nil, bucketHandle)
}

func getDefaultStorageClientConfig() (clientConfig storageClientConfig) {
	return storageClientConfig{
		disableHTTP2:        true,
		maxConnsPerHost:     10,
		maxIdleConnsPerHost: 100,
		tokenSrc:            oauth2.StaticTokenSource(&oauth2.Token{}),
		timeOut:             800 * time.Millisecond,
		maxRetryDuration:    30 * time.Second,
		retryMultiplier:     2,
	}
}

func (t *StorageHandleTest) invokeAndVerifyStorageHandle(sc storageClientConfig) {
	handleCreated, err := NewStorageHandle(context.Background(), sc)
	AssertEq(nil, err)
	AssertNe(nil, handleCreated)
}

func (t *StorageHandleTest) TestNewStorageHandleHttp2Disabled() {
	sc := getDefaultStorageClientConfig() // by default http2 disabled

	t.invokeAndVerifyStorageHandle(sc)
}

func (t *StorageHandleTest) TestNewStorageHandleHttp2Enabled() {
	sc := getDefaultStorageClientConfig()
	sc.disableHTTP2 = false

	t.invokeAndVerifyStorageHandle(sc)
}

func (t *StorageHandleTest) TestNewStorageHandleWithZeroMaxConnsPerHost() {
	sc := getDefaultStorageClientConfig()
	sc.maxConnsPerHost = 0

	t.invokeAndVerifyStorageHandle(sc)
}
{'fraction_non_alphanumeric': 0.10928408803440424, 'fraction_numerical': 0.01264862130027827, 'mean_word_length': 5.226771653543307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '1199663', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1292, 'n_words': 249}