-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor acceptance tests with robot framework
Signed-off-by: Josh Dolitsky <josh@dolit.ski>
- Loading branch information
Showing
6 changed files
with
197 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,7 @@ tmp/ | |
.docker/ | ||
*.tar.gz | ||
.cover/ | ||
.venv/ | ||
.robot/ | ||
acceptance/lib/__pycache__/ | ||
test.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import subprocess | ||
|
||
|
||
class Sh(object): | ||
def run_command(self, command, detach=False, hide_debug=False): | ||
process = subprocess.Popen(['/bin/bash', '-xc', command], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT) | ||
if not detach: | ||
stdout = process.communicate()[0].strip().decode() | ||
self.rc = process.returncode | ||
tmp = [] | ||
for x in stdout.split('\n'): | ||
is_debug_line = x.startswith('+ ') | ||
if not is_debug_line or not hide_debug: | ||
print(x) | ||
# Remove debug lines that start with "+ " | ||
if not is_debug_line: | ||
tmp.append(x) | ||
self.stdout = '\n'.join(tmp) | ||
|
||
def return_code_should_be(self, expected_rc): | ||
if int(expected_rc) != self.rc: | ||
raise AssertionError('Expected return code to be "%s" but was "%s".' | ||
% (expected_rc, self.rc)) | ||
|
||
def should_pass(self, cmd): | ||
self.run_command(cmd) | ||
self.return_code_should_be(0) | ||
|
||
def should_pass_no_output(self, cmd): | ||
self.run_command(cmd, hide_debug=True) | ||
self.return_code_should_be(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
*** Settings *** | ||
Documentation Tests to verify that docker-credential-magic/magician works properly | ||
... against various commercial registry providers (Docker required). | ||
Library String | ||
Library OperatingSystem | ||
Library lib/Sh.py | ||
Suite Setup Suite Setup | ||
Suite Teardown Suite Teardown | ||
|
||
*** Test Cases *** | ||
Azure Container Registry (ACR) | ||
Cleanup envfile | ||
Skip test or add to envfile AZURE_REGISTRY_ENDPOINT REGISTRY_ENDPOINT | ||
Skip test or add to envfile AZURE_REGISTRY_NAMESPACE REGISTRY_NAMESPACE | ||
Skip test or add to envfile AZURE_CLIENT_ID | ||
Skip test or add to envfile AZURE_CLIENT_SECRET | ||
Skip test or add to envfile AZURE_TENANT_ID | ||
Test registry provider integration | ||
|
||
Amazon Elastic Container Registry (ECR) | ||
Cleanup envfile | ||
Skip test or add to envfile AWS_REGISTRY_ENDPOINT REGISTRY_ENDPOINT | ||
Skip test or add to envfile AWS_REGISTRY_NAMESPACE REGISTRY_NAMESPACE | ||
Skip test or add to envfile AWS_DEFAULT_REGION | ||
Skip test or add to envfile AWS_ACCESS_KEY_ID | ||
Skip test or add to envfile AWS_SECRET_ACCESS_KEY | ||
Test registry provider integration | ||
|
||
Google Container Registry (GCR) / Google Artifact Registry (GAR) | ||
Cleanup envfile | ||
Skip test or add to envfile GOOGLE_REGISTRY_ENDPOINT REGISTRY_ENDPOINT | ||
Skip test or add to envfile GOOGLE_REGISTRY_NAMESPACE REGISTRY_NAMESPACE | ||
Skip test or add to envfile GOOGLE_APPLICATION_CREDENTIALS | ||
Test registry provider integration | ||
|
||
*** Keyword *** | ||
Skip test or add to envfile | ||
[Arguments] ${key} ${override_key}=unset | ||
Skip If "%{${key}}" == "" Missing required env var ${key} | ||
IF "${override_key}" != "unset" | ||
Add to envfile "${override_key}" "%{${key}}" | ||
ELSE | ||
Add to envfile "${key}" "%{${key}}" | ||
END | ||
|
||
Add to envfile | ||
[Arguments] ${key} ${value} | ||
Should pass no output echo "${key}=${value}" >> test.env | ||
|
||
Cleanup envfile | ||
Should pass rm -f test.env || true | ||
|
||
Test registry provider integration | ||
Should pass docker run --rm --env-file=test.env --entrypoint %{PUSH_ENTRYPOINT} %{PUSH_MOUNT_FLAGS} %{LOCAL_IMAGE} %{PUSH_ARGS} | ||
Should pass %{POST_PUSH_CMD} | ||
Should pass docker run --rm --env-file=test.env --entrypoint %{PULL_ENTRYPOINT} %{PULL_MOUNT_FLAGS} %{LOCAL_IMAGE} %{PULL_ARGS} | ||
Should pass %{VERIFY_CMD} | ||
|
||
Start local test registry | ||
Should pass docker rmi -f %{LOCAL_IMAGE} || true | ||
Should pass docker rm -f %{CONTAINER_NAME} || true | ||
Should pass docker run --rm -d -p %{CONTAINER_PORT}:5000 --name %{CONTAINER_NAME} registry | ||
|
||
Stop local test registry | ||
Should pass docker logs %{CONTAINER_NAME} | ||
Should pass docker rm -f %{CONTAINER_NAME} | ||
|
||
Mutate remote test image | ||
Should pass docker-credential-magician %{REMOTE_IMAGE} -t %{LOCAL_IMAGE} | ||
|
||
Suite Setup | ||
Start local test registry | ||
Mutate remote test image | ||
|
||
Suite Teardown | ||
Cleanup envfile | ||
Stop local test registry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
cd $DIR/../ | ||
export PATH="${PWD}/bin:${PATH}" | ||
|
||
PY_REQUIRES="robotframework==4.1" | ||
|
||
# Default test settings | ||
export REMOTE_IMAGE="${REMOTE_IMAGE:-ghcr.io/oras-project/oras:v0.12.0@sha256:c17f028ecbe9caed88a352d590fbe58abef4b91baf9157e353f7ab7b60cd6fdb}" | ||
export CONTAINER_NAME="${CONTAINER_NAME:-docker-credential-magic-acceptance}" | ||
export CONTAINER_PORT="${CONTAINER_PORT:-5000}" | ||
export LOCAL_IMAGE="${LOCAL_IMAGE:-localhost:${CONTAINER_PORT}/acceptance:magic}" | ||
export PUSH_ENTRYPOINT="${PUSH_ENTRYPOINT:-sh}" | ||
export PUSH_MOUNT_FLAGS="${PUSH_MOUNT_FLAGS:--v ${PWD}/testdata/helm/nginx-9.3.6.tgz:/workspace/nginx-9.3.6.tgz}" | ||
export PUSH_ARGS="${PUSH_ARGS:--c 'echo "{}" > config.json && \ | ||
oras push --manifest-config config.json:application/vnd.cncf.helm.config.v1+json \ | ||
\${REGISTRY_ENDPOINT}/\${REGISTRY_NAMESPACE}:9.3.6 \ | ||
nginx-9.3.6.tgz:application/tar+gzip'}" | ||
export POST_PUSH_CMD="${POST_PUSH_CMD:-rm -rf tmp/ && mkdir tmp/}" | ||
export PULL_ENTRYPOINT="${PULL_ENTRYPOINT:-sh}" | ||
export PULL_MOUNT_FLAGS="${PULL_MOUNT_FLAGS:--v ${PWD}/tmp:/workspace}" | ||
export PULL_ARGS="${PULL_ARGS:--c 'oras pull -a \${REGISTRY_ENDPOINT}/\${REGISTRY_NAMESPACE}:9.3.6'}" | ||
export VERIFY_CMD="${VERIFY_CMD:-ls -la tmp/ | grep nginx-9.3.6.tgz}" | ||
|
||
# Special case for Google: if GOOGLE_APPLICATION_CREDENTIALS_BASE64 is set, | ||
# create sa.json and add to the mount args | ||
set +x | ||
if [[ "${GOOGLE_APPLICATION_CREDENTIALS_BASE64}" != "" ]]; then | ||
echo "${GOOGLE_APPLICATION_CREDENTIALS_BASE64}" | base64 -d > sa.json | ||
export PUSH_MOUNT_FLAGS="${PUSH_MOUNT_FLAGS} -v ${PWD}/sa.json:/sa.json" | ||
export PULL_MOUNT_FLAGS="${PULL_MOUNT_FLAGS} -v ${PWD}/sa.json:/sa.json" | ||
export GOOGLE_APPLICATION_CREDENTIALS="/sa.json" | ||
fi | ||
set -x | ||
|
||
# Default all provider-specific env vars to empty strings so robot does not complain | ||
set +x | ||
export AZURE_REGISTRY_ENDPOINT="${AZURE_REGISTRY_ENDPOINT}" | ||
export AZURE_REGISTRY_NAMESPACE="${AZURE_REGISTRY_NAMESPACE}" | ||
export AZURE_CLIENT_ID="${AZURE_CLIENT_ID}" | ||
export AZURE_CLIENT_SECRET="${AZURE_CLIENT_SECRET}" | ||
export AZURE_TENANT_ID="${AZURE_TENANT_ID}" | ||
export AWS_REGISTRY_ENDPOINT="${AWS_REGISTRY_ENDPOINT}" | ||
export AWS_REGISTRY_NAMESPACE="${AWS_REGISTRY_NAMESPACE}" | ||
export AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" | ||
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" | ||
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" | ||
export GOOGLE_REGISTRY_ENDPOINT="${GOOGLE_REGISTRY_ENDPOINT}" | ||
export GOOGLE_REGISTRY_NAMESPACE="${GOOGLE_REGISTRY_NAMESPACE}" | ||
export GOOGLE_APPLICATION_CREDENTIALS="${GOOGLE_APPLICATION_CREDENTIALS}" | ||
set -x | ||
|
||
if [ ! -d .venv/ ]; then | ||
virtualenv -p $(which python3) .venv/ | ||
.venv/bin/python .venv/bin/pip install $PY_REQUIRES | ||
fi | ||
|
||
rm -rf .robot/ | ||
.venv/bin/robot --outputdir=.robot/ acceptance/ |