From e2e5fe169a90219fa400241f251deccc1afeb073 Mon Sep 17 00:00:00 2001 From: marpio Date: Fri, 30 Aug 2019 21:38:06 +0200 Subject: [PATCH] Enable Azure storage and stasher tests in drone (#1281) * enable azure ci tests * add import --- .drone.yml | 4 ++++ pkg/stash/with_azureblob_test.go | 24 ++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index d97ee86e7..8363d5669 100644 --- a/.drone.yml +++ b/.drone.yml @@ -48,6 +48,10 @@ steps: from_secret: GCS_SERVICE_ACCOUNT GCS_PROJECT_ID: from_secret: GOOGLE_CLOUD_PROJECT + ATHENS_AZURE_ACCOUNT_NAME: + from_secret: ATHENS_AZURE_ACCOUNT_NAME + ATHENS_AZURE_ACCOUNT_KEY: + from_secret: ATHENS_AZURE_ACCOUNT_KEY when: branch: - master diff --git a/pkg/stash/with_azureblob_test.go b/pkg/stash/with_azureblob_test.go index fabf38a1e..08a724126 100644 --- a/pkg/stash/with_azureblob_test.go +++ b/pkg/stash/with_azureblob_test.go @@ -12,6 +12,7 @@ import ( "github.com/gomods/athens/pkg/config" "github.com/gomods/athens/pkg/storage" "github.com/gomods/athens/pkg/storage/mem" + "github.com/technosophos/moniker" "golang.org/x/sync/errgroup" ) @@ -19,7 +20,8 @@ import ( // and it will ensure that saving to modules at the same time // is done synchronously so that only the first module gets saved. func TestWithAzureBlob(t *testing.T) { - cfg := getAzureTestConfig() + containerName := randomContainerName(os.Getenv("DRONE_PULL_REQUEST")) + cfg := getAzureTestConfig(containerName) if cfg == nil { t.SkipNow() } @@ -82,14 +84,28 @@ func (ms *mockAzureBlobStasher) Stash(ctx context.Context, mod, ver string) (str return "", fmt.Errorf("second time error") } -func getAzureTestConfig() *config.AzureBlobConfig { +func getAzureTestConfig(containerName string) *config.AzureBlobConfig { key := os.Getenv("ATHENS_AZURE_ACCOUNT_KEY") if key == "" { return nil } + name := os.Getenv("ATHENS_AZURE_ACCOUNT_NAME") + if name == "" { + return nil + } return &config.AzureBlobConfig{ - AccountName: "athens_drone_azure_account", + AccountName: name, AccountKey: key, - ContainerName: "athens_drone_azure_container", + ContainerName: containerName, + } +} + +func randomContainerName(prefix string) string { + // moniker is a cool library to produce mostly unique, human-readable names + // see https://github.com/technosophos/moniker for more details + namer := moniker.New() + if prefix != "" { + return fmt.Sprintf("%s_%s", prefix, namer.NameSep("")) } + return namer.NameSep("") }