Skip to content

Commit

Permalink
Enable Azure storage and stasher tests in drone (gomods#1281)
Browse files Browse the repository at this point in the history
* enable azure ci tests

* add import
  • Loading branch information
marpio authored and arschles committed Aug 30, 2019
1 parent a0c8dff commit e2e5fe1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions pkg/stash/with_azureblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ 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"
)

// TestWithAzureBlob requires a real AzureBlob backend implementation
// 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()
}
Expand Down Expand Up @@ -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("")
}

0 comments on commit e2e5fe1

Please sign in to comment.