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 name: CI
on: on:
push: push:
branches: [main] branches: ['**']
pull_request: pull_request:
branches: [main] branches: [main]
permissions:
# required to retrieve AWS credentials
id-token: write
# required to retrieve repository
contents: read
jobs: jobs:
Run-All: Run-All:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -32,5 +38,15 @@ jobs:
- name: Run gofmt - name: Run gofmt
run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
- run: echo "Running {{ github.repository }} deployment unit tests." - name: Configure AWS credentials from Test account
- run: go test ./... 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. // helper for aggregating aws connection details.
func makeS3Config() storage.S3Config { func makeS3Config() storage.S3Config {
ak := os.Getenv("AWS_ACCESS_KEY_ID") ak := os.Getenv(storage.AWS_ACCESS_KEY_ID)
if len(accessKey) > 0 { if len(accessKey) > 0 {
ak = accessKey ak = accessKey
} }
@ -122,7 +122,7 @@ func makeS3Config() storage.S3Config {
Bucket: bucket, Bucket: bucket,
Endpoint: endpoint, Endpoint: endpoint,
Prefix: prefix, Prefix: prefix,
SecretKey: os.Getenv("AWS_SECRET_ACCESS_KEY"), SecretKey: os.Getenv(storage.AWS_SECRET_ACCESS_KEY),
SessionToken: os.Getenv("AWS_SESSION_TOKEN"), SessionToken: os.Getenv(storage.AWS_SESSION_TOKEN),
} }
} }

View File

@ -2,15 +2,22 @@ package repository_test
import ( import (
"context" "context"
"os"
"testing" "testing"
"time"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/pkg/repository" "github.com/alcionai/corso/pkg/repository"
"github.com/alcionai/corso/pkg/storage" "github.com/alcionai/corso/pkg/storage"
) )
// ---------------
// unit tests
// ---------------
type RepositorySuite struct { type RepositorySuite struct {
suite.Suite suite.Suite
} }
@ -42,7 +49,7 @@ func (suite *RepositorySuite) TestInitialize() {
} }
// repository.Connect involves end-to-end communication with kopia, therefore this only // 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() { func (suite *RepositorySuite) TestConnect() {
table := []struct { table := []struct {
name string 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 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 ( const (
keyS3AccessKey = "s3_accessKey" keyS3AccessKey = "s3_accessKey"
keyS3Bucket = "s3_bucket" keyS3Bucket = "s3_bucket"