Skip to content

Commit

Permalink
Add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
gl-johnson committed Mar 8, 2023
1 parent d0b7cb0 commit 97abc7a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pkg
junit.xml
summon-aws
*.sublime-project
secrets.yml
summon-s3

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
Expand Down
3 changes: 3 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pipeline {
stage('Changelog') {
steps { sh './parse-changelog.sh' }
}
stage('E2E Test') {
steps { sh 'summon --provider summon-conjur ./e2e_test.sh' }
}
}
}

Expand Down
55 changes: 55 additions & 0 deletions e2e_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash -e

# Run this script using summon
# summon --provider summon-conjur ./e2e_test.sh

REQUIRED_VARS=(AWS_REGION AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY)
export AWS_BUCKET="summon-s3-ci"
export AWS_ARTIFACT="ci-secret.txt"

function main {
check_required_vars
build_summon_image
test_output "test secret"
}

function check_required_vars {
for var in "${REQUIRED_VARS[@]}"; do
if [[ -z "${!var}" ]]; then
echo "$var is not set"
exit 1
fi
done
}

function build_summon_image {
rm -rf summon
git clone "https://github.com/cyberark/summon.git"
pushd summon > /dev/null
docker build . -t test-summon
popd > /dev/null
}

# Helper function to build and run the Docker container
function test_output {
local expected_output="$1"
local output=$(docker run --rm \
-v "$PWD:/summon-s3-src" -w "/summon-s3-src" \
-e AWS_REGION -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_BUCKET -e AWS_ARTIFACT \
test-summon \
go build > /dev/null && \
summon --provider ./pkg/darwin/summon-s3 \
--yaml "TEST_CRED: !var $AWS_BUCKET/$AWS_ARTIFACT" \
printenv TEST_CRED) || true

if [ "$output" == "$expected_output" ] && [ $? -eq 0 ]; then
echo "Test passed"
exit 0
else
echo "Test failed"
echo "Expected output to equal: '$expected_output'. Actual output: $output"
exit 1
fi
}

main
3 changes: 3 additions & 0 deletions secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AWS_REGION: !var dev/aws/iam/users/sys_powerful/region
AWS_ACCESS_KEY_ID: !var dev/aws/iam/users/sys_powerful/access_key_id
AWS_SECRET_ACCESS_KEY: !var dev/aws/iam/users/sys_powerful/secret_access_key

0 comments on commit 97abc7a

Please sign in to comment.