From 5c5bc83d5cd31b6e5747b484f8560b02c35133ca Mon Sep 17 00:00:00 2001 From: Thomas Rabaix Date: Tue, 16 Mar 2021 22:13:27 +0000 Subject: [PATCH] feat(ci): restore S3 test --- .github/workflows/go.yml | 8 ++++++++ Makefile | 5 ++++- core/vault/vault_driver_s3_test.go | 31 +++++++++++++++++------------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 54a3552..ba4b5a3 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -8,6 +8,7 @@ on: jobs: build: + environment: qa runs-on: ubuntu-latest services: postgres: @@ -35,6 +36,13 @@ jobs: go get ./... - name: Test + env: + GONODE_TEST_AWS_VAULT_S3_BUCKET: ${{ secrets.GONODE_TEST_AWS_VAULT_S3_BUCKET }} + GONODE_TEST_OFFLINE: ${{ secrets.GONODE_TEST_OFFLINE }} + GONODE_TEST_S3_ACCESS_KEY: ${{ secrets.GONODE_TEST_S3_ACCESS_KEY }} + GONODE_TEST_S3_ENDPOINT: ${{ secrets.GONODE_TEST_S3_ENDPOINT }} + GONODE_TEST_S3_REGION: ${{ secrets.GONODE_TEST_S3_REGION }} + GONODE_TEST_S3_SECRET: ${{ secrets.GONODE_TEST_S3_SECRET }} run: | make test diff --git a/Makefile b/Makefile index 46f2006..630db2e 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ GO_FILES = $(shell find . -type f -name "*.go") GONODE_MODULES = $(shell ls -d ./modules/* | grep -v go) GONODE_CORE = $(shell ls -d ./core/* | grep -v go) GOPATH = $(shell go env GOPATH) +GONODE_TEST_OFFLINE ?= "yes" install: $(call back,glide install) @@ -15,7 +16,9 @@ test: mkdir -p data echo "mode: atomic" > data/coverage.out - GONODE_TEST_OFFLINE=true GOPATH=${GOPATH} go test -v -failfast -covermode=atomic -coverprofile=data/coverage_core.out $(GONODE_CORE) + env + echo ${GONODE_TEST_OFFLINE} + GOPATH=${GOPATH} go test -v -failfast -covermode=atomic -coverprofile=data/coverage_core.out $(GONODE_CORE) GOPATH=${GOPATH} go test -v -failfast -covermode=atomic -coverprofile=data/coverage_modules.out $(GONODE_MODULES) GOPATH=${GOPATH} go test -v -failfast -covermode=atomic -coverpkg ./... -coverprofile=data/coverage_integration.out ./test/modules go vet $(GONODE_CORE) $(GONODE_MODULES) ./test/modules/ diff --git a/core/vault/vault_driver_s3_test.go b/core/vault/vault_driver_s3_test.go index d4a14c0..959eecc 100644 --- a/core/vault/vault_driver_s3_test.go +++ b/core/vault/vault_driver_s3_test.go @@ -13,7 +13,6 @@ import ( "bytes" "fmt" "os" - "syscall" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" @@ -21,10 +20,19 @@ import ( "github.com/aws/aws-sdk-go/service/s3" ) +func getEnv(name, def string) string { + value := os.Getenv(name) + if len(value) == 0 { + value = def + } + + return value +} + // this is just a test to validata how the aws sdk behave func Test_Vault_Basic_S3_Usage(t *testing.T) { - if _, offline := syscall.Getenv("GONODE_TEST_OFFLINE"); offline == true { + if getEnv("GONODE_TEST_OFFLINE", "yes") == "yes" { t.Skip("OFFLINE TEST ONLY") return } @@ -33,15 +41,8 @@ func Test_Vault_Basic_S3_Usage(t *testing.T) { var headResult *s3.HeadObjectOutput var getResult *s3.GetObjectOutput - root := os.Getenv("GONODE_TEST_AWS_VAULT_ROOT") - if len(root) == 0 { - root = "local" - } - - profile := os.Getenv("GONODE_TEST_AWS_PROFILE") - if len(profile) == 0 { - profile = "gonode-test" - } + root := getEnv("GITHUB_RUN_ID", getEnv("GONODE_TEST_AWS_VAULT_ROOT", "local")) + profile := getEnv("GONODE_TEST_AWS_PROFILE", "gonode-test") chainProvider := credentials.NewChainCredentials([]credentials.Provider{ &credentials.EnvProvider{}, @@ -53,6 +54,10 @@ func Test_Vault_Basic_S3_Usage(t *testing.T) { Filename: os.Getenv("GONODE_TEST_AWS_CREDENTIALS_FILE"), Profile: profile, }, + &credentials.StaticProvider{Value: credentials.Value{ + AccessKeyID: getEnv("GONODE_TEST_S3_ACCESS_KEY", ""), + SecretAccessKey: getEnv("GONODE_TEST_S3_SECRET", ""), + }}, }) _, err = chainProvider.Get() @@ -64,8 +69,8 @@ func Test_Vault_Basic_S3_Usage(t *testing.T) { // init vault v := &DriverS3{ Root: root, - Region: "eu-west-1", - EndPoint: "s3-eu-west-1.amazonaws.com", + Region: getEnv("GONODE_TEST_S3_REGION", "eu-west-1"), + EndPoint: getEnv("GONODE_TEST_S3_ENDPOINT", "s3-eu-west-1.amazonaws.com"), Credentials: chainProvider, }