Skip to content

Commit d305703

Browse files
authored
Merge pull request #20 from davidovich/allow-limited-storage-availability-for-tests
Only test storages that are configured in the env
2 parents ec98534 + 99ac1b9 commit d305703

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

acceptance_tests/helm.robot

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Documentation Tests to verify that ChartMuseum is able to work with
33
... Helm CLI and act as a valid Helm Chart Repository using
44
... all supported storage backends (local, s3, gcs).
5+
Library String
56
Library OperatingSystem
67
Library lib/ChartMuseum.py
78
Library lib/Helm.py
@@ -21,6 +22,12 @@ ChartMuseum works with Helm using Google cloud storage
2122
*** Keyword ***
2223
Test Helm integration
2324
[Arguments] ${storage}
25+
26+
# return fast if we cannot find a bucket in an environment variable.
27+
${USTORAGE}= Convert To Uppercase ${storage}
28+
${ENV_STORAGE_SET}= Get Environment variable TEST_STORAGE_${USTORAGE}_BUCKET ${EMPTY}
29+
Return from Keyword if '${ENV_STORAGE_SET}'=='${EMPTY}' and '${storage}'!='local'
30+
2431
Start ChartMuseum server with storage backend ${storage}
2532
Able to add ChartMuseum as Helm chart repo
2633
Helm search does not return test charts

acceptance_tests/lib/common.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
KEYRING = 'testdata/pgp/helm-test-key.pub'
1313
LOGFILE = '.chartmuseum.log'
1414

15-
STORAGE_AMAZON_BUCKET = os.environ['TEST_STORAGE_AMAZON_BUCKET']
16-
STORAGE_AMAZON_REGION = os.environ['TEST_STORAGE_AMAZON_REGION']
17-
STORAGE_GOOGLE_BUCKET = os.environ['TEST_STORAGE_GOOGLE_BUCKET']
15+
STORAGE_AMAZON_BUCKET = os.getenv('TEST_STORAGE_AMAZON_BUCKET')
16+
STORAGE_AMAZON_REGION = os.getenv('TEST_STORAGE_AMAZON_REGION')
17+
STORAGE_GOOGLE_BUCKET = os.getenv('TEST_STORAGE_GOOGLE_BUCKET')
1818

1919
STORAGE_AMAZON_PREFIX = 'acceptance/%s' % NOW
2020
STORAGE_GOOGLE_PREFIX = 'acceptance/%s' % NOW

pkg/storage/amazon_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func (suite *AmazonTestSuite) TestPutObject() {
5252
}
5353

5454
func TestAmazonStorageTestSuite(t *testing.T) {
55-
if os.Getenv("TEST_CLOUD_STORAGE") == "1" {
55+
if os.Getenv("TEST_CLOUD_STORAGE") == "1" &&
56+
os.Getenv("TEST_STORAGE_AMAZON_BUCKET") != "" &&
57+
os.Getenv("TEST_STORAGE_AMAZON_REGION") != "" {
5658
suite.Run(t, new(AmazonTestSuite))
5759
}
5860
}

pkg/storage/storage_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ func (suite *StorageTestSuite) setupStorageBackends() {
3030
s3Bucket := os.Getenv("TEST_STORAGE_AMAZON_BUCKET")
3131
s3Region := os.Getenv("TEST_STORAGE_AMAZON_REGION")
3232
gcsBucket := os.Getenv("TEST_STORAGE_GOOGLE_BUCKET")
33-
suite.StorageBackends["AmazonS3"] = Backend(NewAmazonS3Backend(s3Bucket, prefix, s3Region, ""))
34-
suite.StorageBackends["GoogleCS"] = Backend(NewGoogleCSBackend(gcsBucket, prefix))
33+
if s3Bucket != "" && s3Region != "" {
34+
suite.StorageBackends["AmazonS3"] = Backend(NewAmazonS3Backend(s3Bucket, prefix, s3Region, ""))
35+
}
36+
if gcsBucket != "" {
37+
suite.StorageBackends["GoogleCS"] = Backend(NewGoogleCSBackend(gcsBucket, prefix))
38+
}
3539
}
3640
}
3741

scripts/setup_test_environment.sh

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ main() {
2323

2424
check_storage_env_vars() {
2525
set +x
26-
ALL_ENV_VARS_PRESENT="1"
26+
SOME_ENV_VARS_PRESENT="0"
2727
for VAR in ${REQUIRED_TEST_STORAGE_ENV_VARS[@]}; do
28-
if [ "${!VAR}" == "" ]; then
29-
echo "missing required test env var: $VAR"
30-
ALL_ENV_VARS_PRESENT="0"
28+
if [ "${!VAR}" != "" ]; then
29+
echo "Detected one required test env var: $VAR"
30+
SOME_ENV_VARS_PRESENT="1"
3131
fi
3232
done
33-
if [ "$ALL_ENV_VARS_PRESENT" == "0" ]; then
33+
if [ "$SOME_ENV_VARS_PRESENT" == "0" ]; then
34+
echo "At least one or all of ${REQUIRED_TEST_STORAGE_ENV_VARS[@]} should be present"
3435
exit 1
3536
fi
3637
set -x

0 commit comments

Comments
 (0)