initial repo init integration test (#90) (#96)

Implements an integration test in the repository that runs an end-
to-end test of an s3 repo initialization through kopia.
This commit is contained in:
Keepers 2022-05-31 18:32:26 -06:00 committed by GitHub
parent eaf6018996
commit 596a4cc37b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 100 additions and 7 deletions

View File

@ -1,10 +1,16 @@
name: CI
on:
push:
branches: [main]
branches: ['**']
pull_request:
branches: [main]
permissions:
# required to retrieve AWS credentials
id-token: write
# required to retrieve repository
contents: read
jobs:
Run-All:
runs-on: ubuntu-latest
@ -32,5 +38,15 @@ jobs:
- name: Run gofmt
run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
- run: echo "Running {{ github.repository }} deployment unit tests."
- run: go test ./...
- name: Configure AWS credentials from Test account
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::951767375776:role/corso-testing-role
role-session-name: integration-testing
aws-region: us-east-1
- run: echo "Running ${{ github.repository }} deployment unit tests at ${{ env.TIME_OF_TEST }}."
- name: Deployment Tests
env:
INTEGRATION_TESTING: true
run: go test ./...

View File

@ -113,7 +113,7 @@ func connectS3Cmd(cmd *cobra.Command, args []string) {
// helper for aggregating aws connection details.
func makeS3Config() storage.S3Config {
ak := os.Getenv("AWS_ACCESS_KEY_ID")
ak := os.Getenv(storage.AWS_ACCESS_KEY_ID)
if len(accessKey) > 0 {
ak = accessKey
}
@ -122,7 +122,7 @@ func makeS3Config() storage.S3Config {
Bucket: bucket,
Endpoint: endpoint,
Prefix: prefix,
SecretKey: os.Getenv("AWS_SECRET_ACCESS_KEY"),
SessionToken: os.Getenv("AWS_SESSION_TOKEN"),
SecretKey: os.Getenv(storage.AWS_SECRET_ACCESS_KEY),
SessionToken: os.Getenv(storage.AWS_SESSION_TOKEN),
}
}

View File

@ -2,15 +2,22 @@ package repository_test
import (
"context"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/alcionai/corso/pkg/repository"
"github.com/alcionai/corso/pkg/storage"
)
// ---------------
// unit tests
// ---------------
type RepositorySuite struct {
suite.Suite
}
@ -42,7 +49,7 @@ func (suite *RepositorySuite) TestInitialize() {
}
// repository.Connect involves end-to-end communication with kopia, therefore this only
// tests expected error cases from
// tests expected error cases
func (suite *RepositorySuite) TestConnect() {
table := []struct {
name string
@ -64,3 +71,65 @@ func (suite *RepositorySuite) TestConnect() {
})
}
}
// ---------------
// integration tests
// ---------------
type RepositoryIntegrationSuite struct {
suite.Suite
}
func TestRepositoryIntegrationSuite(t *testing.T) {
runIntegrationTests := os.Getenv("INTEGRATION_TESTING")
if runIntegrationTests != "true" {
t.Skip()
}
suite.Run(t, new(RepositoryIntegrationSuite))
}
// ensure all required env values are populated
func (suite *RepositoryIntegrationSuite) SetupSuite() {
s3Envs := []string{
storage.AWS_ACCESS_KEY_ID,
storage.AWS_SECRET_ACCESS_KEY,
storage.AWS_SESSION_TOKEN,
}
for _, env := range s3Envs {
require.NotZerof(suite.T(), os.Getenv(env), "env var [%s] must be populated for integration testing", env)
}
}
func (suite *RepositoryIntegrationSuite) TestInitialize() {
ctx := context.Background()
timeOfTest := time.Now().UTC().Format("2016-01-02T15:04:05")
suite.T().Logf("TestInitialize() run at: %s", timeOfTest)
table := []struct {
prefix string
account repository.Account
storage storage.Storage
errCheck assert.ErrorAssertionFunc
}{
{
prefix: "init-s3-" + timeOfTest,
storage: storage.NewStorage(
storage.ProviderS3,
storage.S3Config{
AccessKey: os.Getenv(storage.AWS_ACCESS_KEY_ID),
Bucket: "test-corso-repo-init",
Prefix: "init-s3-" + timeOfTest,
SecretKey: os.Getenv(storage.AWS_SECRET_ACCESS_KEY),
SessionToken: os.Getenv(storage.AWS_SESSION_TOKEN),
},
),
errCheck: assert.NoError,
},
}
for _, test := range table {
suite.T().Run(test.prefix, func(t *testing.T) {
_, err := repository.Initialize(ctx, test.account, test.storage)
test.errCheck(suite.T(), err)
})
}
}

View File

@ -9,6 +9,14 @@ type S3Config struct {
SessionToken string
}
// envvar consts
const (
AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID"
AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY"
AWS_SESSION_TOKEN = "AWS_SESSION_TOKEN"
)
// config key consts
const (
keyS3AccessKey = "s3_accessKey"
keyS3Bucket = "s3_bucket"