corso/src/internal/tester/storage.go
Keepers 03642c517f
standardize deleteContainer func in exch api (#2246)
## Description

Minor refactor that came up while hunting bugs.
For the life of me, I cannot find the reason for
read/write counts being off in event incrementals.

## Does this PR need a docs update or release note?

- [x]  No 

## Type of change

- [x] 🧹 Tech Debt/Cleanup

## Issue(s)

* #2022

## Test Plan

- [x] 💪 Manual
- [x] 💚 E2E
2023-01-30 19:24:44 +00:00

50 lines
1.3 KiB
Go

package tester
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/alcionai/corso/src/pkg/credentials"
"github.com/alcionai/corso/src/pkg/storage"
)
const testRepoRootPrefix = "corso_integration_test/"
var AWSStorageCredEnvs = []string{
credentials.AWSAccessKeyID,
credentials.AWSSecretAccessKey,
credentials.AWSSessionToken,
}
// NewPrefixedS3Storage returns a storage.Storage object initialized with environment
// variables used for integration tests that use S3. The prefix for the storage
// path will be unique.
// Uses t.TempDir() to generate a unique config storage and caching directory for this
// test. Suites that need to identify this value can retrieve it again from the common
// configs.
func NewPrefixedS3Storage(t *testing.T) storage.Storage {
now := LogTimeOfTest(t)
cfg, err := readTestConfig()
require.NoError(t, err, "configuring storage from test file")
prefix := testRepoRootPrefix + t.Name() + "-" + now
t.Logf("testing at s3 bucket [%s] prefix [%s]", cfg[TestCfgBucket], prefix)
st, err := storage.NewStorage(
storage.ProviderS3,
storage.S3Config{
Bucket: cfg[TestCfgBucket],
Prefix: prefix,
},
storage.CommonConfig{
Corso: credentials.GetCorso(),
KopiaCfgDir: t.TempDir(),
},
)
require.NoError(t, err, "creating storage")
return st
}