Skip to content

Commit

Permalink
test: add create-pyxis-image test for oci artifacts (#644)
Browse files Browse the repository at this point in the history
This ensures the --platform flag is passed to oras properly

Signed-off-by: Johnny Bieren <[email protected]>
  • Loading branch information
johnbieren authored Oct 30, 2024
1 parent 75d9063 commit bebe15c
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tasks/create-pyxis-image/tests/mocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function create_container_image() {
# e.g. 0001, 0002, 0003...
echo The image id is $(awk 'END{printf("%04i", NR)}' $(workspaces.data.path)/mock_create_container_image.txt)

if [[ "$*" != "--pyxis-url https://pyxis.preprod.api.redhat.com/ --certified false --tags "*" --is-latest false --verbose --oras-manifest-fetch /tmp/oras-manifest-fetch.json --name "*" --media-type my_media_type --digest "*" --architecture-digest "*" --architecture "*" --rh-push "* ]]
if [[ "$*" != "--pyxis-url https://pyxis.preprod.api.redhat.com/ --certified false --tags "*" --is-latest false --verbose --oras-manifest-fetch /tmp/oras-manifest-fetch.json --name "*" --media-type "*" --digest "*" --architecture-digest "*" --architecture "*" --rh-push "* ]]
then
echo Error: Unexpected call
echo Mock create_container_image called with: $*
Expand All @@ -30,7 +30,10 @@ function cleanup_tags() {

function skopeo() {
echo $* >> $(workspaces.data.path)/mock_skopeo.txt
if [[ "$*" == "inspect --raw docker://"* ]] || [[ "$*" == "inspect --no-tags --override-os linux --override-arch "*" docker://"* ]]
if [[ "$*" == "inspect --raw docker://registry.io/oci-artifact"* ]]
then
echo '{"mediaType": "application/vnd.oci.image.index.v1+json"}'
elif [[ "$*" == "inspect --raw docker://"* ]] || [[ "$*" == "inspect --no-tags --override-os linux --override-arch "*" docker://"* ]]
then
echo '{"mediaType": "my_media_type"}'
else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: test-create-pyxis-image-oci-artifact
spec:
description: |
Run the create-pyxis-image task with a single oci artifact in the snapshot.
This test ensures the ORAS_ARGS are passed properly.
workspaces:
- name: tests-workspace
tasks:
- name: setup
workspaces:
- name: data
workspace: tests-workspace
taskSpec:
workspaces:
- name: data
steps:
- name: setup-values
image: quay.io/konflux-ci/release-service-utils:65d8db844c008e7736ec8dff307868525279484d
script: |
#!/usr/bin/env bash
set -eux
cat > "$(workspaces.data.path)"/snapshot.json << EOF
{
"application": "myapp",
"components": [
{
"name": "comp",
"containerImage": "source@sha256:mydigest",
"repository": "registry.io/oci-artifact",
"tags": [
"testtag"
]
}
]
}
EOF
- name: run-task
taskRef:
name: create-pyxis-image
params:
- name: pyxisSecret
value: test-create-pyxis-image-cert
- name: server
value: stage
- name: snapshotPath
value: snapshot.json
workspaces:
- name: data
workspace: tests-workspace
runAfter:
- setup
- name: check-result
workspaces:
- name: data
workspace: tests-workspace
taskSpec:
workspaces:
- name: data
steps:
- name: check-result
image: quay.io/konflux-ci/release-service-utils:65d8db844c008e7736ec8dff307868525279484d
script: |
#!/usr/bin/env bash
set -eux
if [ "$(wc -l < "$(workspaces.data.path)"/mock_create_container_image.txt)" != 1 ]; then
echo Error: create_container_image was expected to be called 1 time. Actual calls:
cat "$(workspaces.data.path)/mock_create_container_image.txt"
exit 1
fi
if [ -f "$(workspaces.data.path)"/mock_cleanup_tags.txt ]; then
echo Error: cleanup_tags was not expected to be called. Actual calls:
cat "$(workspaces.data.path)/mock_cleanup_tags.txt"
exit 1
fi
if ! grep -- "--tags testtag" < "$(workspaces.data.path)"/mock_create_container_image.txt 2> /dev/null
then
echo Error: create_container_image call was expected to include "--tags testtag". Actual call:
cat "$(workspaces.data.path)/mock_create_container_image.txt"
exit 1
fi
if ! grep -- "--rh-push false" < "$(workspaces.data.path)"/mock_create_container_image.txt 2> /dev/null
then
echo Error: create_container_image call was expected to include "--rh-push false". Actual call:
cat "$(workspaces.data.path)/mock_create_container_image.txt"
exit 1
fi
if [ "$(wc -l < "$(workspaces.data.path)"/mock_skopeo.txt)" != 1 ]; then
echo Error: skopeo was expected to be called 1 time. Actual calls:
cat "$(workspaces.data.path)/mock_skopeo.txt"
exit 1
fi
if [ "$(wc -l < "$(workspaces.data.path)"/mock_oras.txt)" != 3 ]; then
echo Error: oras was expected to be called 3 times. Actual calls:
cat "$(workspaces.data.path)/mock_oras.txt"
exit 1
fi
if ! grep -- "--platform linux/amd64" < "$(workspaces.data.path)"/mock_oras.txt 2> /dev/null
then
echo Error: oras call was expected to include "--platform linux/amd64". Actual call:
cat "$(workspaces.data.path)/mock_oras.txt"
exit 1
fi
[ "$(head -n 1 < "$(workspaces.data.path)"/mock_skopeo.txt)" \
= "inspect --raw docker://registry.io/oci-artifact@sha256:mydigest" ]
if [ "$(wc -l < "$(workspaces.data.path)"/mock_select-oci-auth.txt)" != 2 ]; then
echo Error: select-oci-with was expected to be called 2 times. Actual calls:
cat "$(workspaces.data.path)/mock_select-oci-auth.txt"
exit 1
fi
runAfter:
- run-task

0 comments on commit bebe15c

Please sign in to comment.