2023-09-07 21:06:21 +03:00
# Note: Intended to be run as "make run-blackbox-tests" or "make run-blackbox-ci"
# Makefile target installs & checks all necessary tooling
# Extra tools that are not covered in Makefile target needs to be added in verify_prerequisites()
2023-09-01 17:23:34 +03:00
load helpers_zot
function verify_prerequisites {
if [ ! command -v curl ] &>/dev/null; then
echo "you need to install curl as a prerequisite to running the tests" >&3
return 1
fi
if [ ! command -v jq ] &>/dev/null; then
echo "you need to install jq as a prerequisite to running the tests" >&3
return 1
fi
}
function setup_file() {
# Verify prerequisites are available
2023-09-07 21:06:21 +03:00
if ! verify_prerequisites; then
2023-09-01 17:23:34 +03:00
exit 1
fi
# Download test data to folder common for the entire suite, not just this file
skopeo --insecure-policy copy --format=oci docker://ghcr.io/project-zot/test-images/alpine:3.17.3 oci:${TEST_DATA_DIR}/alpine:3.17.3
# Setup zot server
2023-09-07 21:06:21 +03:00
ZOT_ROOT_DIR=${BATS_FILE_TMPDIR}/zot
2023-09-01 17:23:34 +03:00
echo ${ZOT_ROOT_DIR}
2023-09-07 21:06:21 +03:00
local zot_log_file=${BATS_FILE_TMPDIR}/zot-log.json
local zot_config_file=${BATS_FILE_TMPDIR}/zot_config.json
2023-09-01 17:23:34 +03:00
mkdir -p ${ZOT_ROOT_DIR}
touch ${zot_log_file}
2023-11-15 20:44:31 +02:00
zot_port=$(get_free_port)
echo ${zot_port} > ${BATS_FILE_TMPDIR}/zot.port
2023-09-01 17:23:34 +03:00
cat >${zot_config_file} <<EOF
{
2024-02-20 13:27:21 +02:00
"distSpecVersion": "1.1.0",
2023-09-01 17:23:34 +03:00
"storage": {
"rootDirectory": "${ZOT_ROOT_DIR}"
},
"http": {
"address": "0.0.0.0",
2023-11-15 20:44:31 +02:00
"port": "${zot_port}"
2023-09-01 17:23:34 +03:00
},
"log": {
"level": "debug",
"output": "${zot_log_file}"
},
"extensions": {
"search": {
"enable": true
}
}
}
EOF
zot_serve ${ZOT_PATH} ${zot_config_file}
2023-11-15 20:44:31 +02:00
wait_zot_reachable ${zot_port}
2023-09-01 17:23:34 +03:00
run skopeo --insecure-policy copy --dest-tls-verify=false \
oci:${TEST_DATA_DIR}/alpine:3.17.3 \
2023-11-15 20:44:31 +02:00
docker://127.0.0.1:${zot_port}/alpine:3.17.3
2023-09-01 17:23:34 +03:00
[ "$status" -eq 0 ]
2023-11-15 20:44:31 +02:00
run curl http://127.0.0.1:${zot_port}/v2/_catalog
2023-09-01 17:23:34 +03:00
[ "$status" -eq 0 ]
[ $(echo "${lines[-1]}" | jq '.repositories[]') = '"alpine"' ]
2023-11-15 20:44:31 +02:00
MANIFEST_DIGEST=$(skopeo inspect --tls-verify=false docker://localhost:${zot_port}/alpine:3.17.3 | jq -r '.Digest')
2023-09-01 17:23:34 +03:00
echo ${MANIFEST_DIGEST}
}
2023-09-07 21:06:21 +03:00
function teardown() {
# conditionally printing on failure is possible from teardown but not from from teardown_file
cat ${BATS_FILE_TMPDIR}/zot-log.json
}
2023-09-01 17:23:34 +03:00
function teardown_file() {
zot_stop_all
}
@test "delete one manifest by it's tag" {
2023-11-15 20:44:31 +02:00
zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
run curl http://127.0.0.1:${zot_port}/v2/_catalog
2023-09-01 17:23:34 +03:00
[ "$status" -eq 0 ]
[ $(echo "${lines[-1]}" | jq '.repositories[]') = '"alpine"' ]
2023-11-15 20:44:31 +02:00
run curl -i -X GET http://localhost:${zot_port}/v2/alpine/manifests/3.17.3
2023-09-01 17:23:34 +03:00
[ "$status" -eq 0 ]
echo $(echo "${lines[-1]}")
foundConfigDigest=0
for i in "${lines[@]}"
do
if [[ "$i" == *"\"digest\":\"sha256:4798f93a2cc876a25ef1f5ae73e7a2ff7132ddc2746fc22632a2641b318eb56c\""* ]]; then
foundConfigDigest=1
fi
done
[ "$foundConfigDigest" -eq 1 ]
2023-11-15 20:44:31 +02:00
run curl -X DELETE http://localhost:${zot_port}/v2/alpine/manifests/3.17.3
2023-09-01 17:23:34 +03:00
[ "$status" -eq 0 ]
2023-11-15 20:44:31 +02:00
run curl -i -X GET http://localhost:${zot_port}/v2/alpine/manifests/3.17.3
2023-09-01 17:23:34 +03:00
[ "$status" -eq 0 ]
found=0
for i in "${lines[@]}"
do
if [[ "$i" = *"MANIFEST_UNKNOWN"* ]]; then
found=1
fi
done
[ "$found" -eq 1 ]
}