From a5a7ae4bec79355220d382b9f8fbd6ddefbfd164 Mon Sep 17 00:00:00 2001 From: wangyueliang Date: Thu, 1 Feb 2024 11:37:30 +0800 Subject: [PATCH] Synchronize test code --- tests/check_one.sh | 4 +++ tests/test-cmd-copy-container.sh | 47 ++++++++++++++++++++++++++++++++ tests/test_cli.py | 2 +- tests/test_cosalib_cmdlib.py | 14 +++++----- 4 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 tests/test-cmd-copy-container.sh diff --git a/tests/check_one.sh b/tests/check_one.sh index fcdd75f5..71863ea6 100755 --- a/tests/check_one.sh +++ b/tests/check_one.sh @@ -27,6 +27,10 @@ if [[ ${HASSHELLCHECK} == 1 ]]; then if [[ $shebang =~ ^#!/.*/bash.* ]] || [[ $shebang =~ ^#!/.*/env\ bash ]]; then shellcheck -x "$f" bash -n "$f" + if grep -E '(^|[[:space:]])if[[:space:]]+"?\$' "$f"; then + echo "Possible unbracketed conditional in $f" + exit 1 + fi echo "OK ${f}" fi fi diff --git a/tests/test-cmd-copy-container.sh b/tests/test-cmd-copy-container.sh new file mode 100644 index 00000000..be4169d5 --- /dev/null +++ b/tests/test-cmd-copy-container.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -xeuo pipefail + +# NOTE: both destination repos must be empty before starting + +SRC_REPO=quay.io/jlebon/fedora-coreos +DEST_REPO_QUAY=quay.io/jlebon/fedora-coreos-2 +DEST_REPO_QUAY_AUTHFILE=dest.quay.auth.json +DEST_REPO_APPCI=registry.ci.openshift.org/coreos/jlebon-fedora-coreos-test +DEST_REPO_APPCI_AUTHFILE=dest.appci.auth.json + +fatal() { + echo "$@" + exit 1 +} + +# copy to quay.io; auto-default to preserving manifest list +cosa copy-container --dest-authfile "${DEST_REPO_QUAY_AUTHFILE}" \ + --tag=stable --tag=stable-single "${SRC_REPO}" "${DEST_REPO_QUAY}" +skopeo inspect --raw "docker://${DEST_REPO_QUAY}:stable" | grep -q manifests +skopeo inspect --raw "docker://${DEST_REPO_QUAY}:stable-amd64" && fatal "expected missing" +skopeo inspect --raw "docker://${DEST_REPO_QUAY}:stable-arm64" && fatal "expected missing" +skopeo inspect --raw "docker://${DEST_REPO_QUAY}:stable-s390x" && fatal "expected missing" +skopeo inspect --raw "docker://${DEST_REPO_QUAY}:stable-single" | grep -q layers + +# copy to quay.io; force arch tag +cosa copy-container --dest-authfile "${DEST_REPO_QUAY_AUTHFILE}" \ + --tag=stable --manifest-list-to-arch-tag=always \ + "${SRC_REPO}" "${DEST_REPO_QUAY}" +skopeo inspect --raw "docker://${DEST_REPO_QUAY}:stable-amd64" | grep -q layers +skopeo inspect --raw "docker://${DEST_REPO_QUAY}:stable-arm64" | grep -q layers +skopeo inspect --raw "docker://${DEST_REPO_QUAY}:stable-s390x" | grep -q layers + +# copy to registry.ci; auto-default to arch tag transform +cosa copy-container --dest-authfile "${DEST_REPO_APPCI_AUTHFILE}" \ + --tag=stable --tag=stable-single "${SRC_REPO}" "${DEST_REPO_APPCI}" +skopeo inspect --raw "docker://${DEST_REPO_APPCI}:stable" && fatal "expected missing" +skopeo inspect --raw "docker://${DEST_REPO_APPCI}:stable-amd64" | grep -q layers +skopeo inspect --raw "docker://${DEST_REPO_APPCI}:stable-arm64" | grep -q layers +skopeo inspect --raw "docker://${DEST_REPO_APPCI}:stable-s390x" | grep -q layers +skopeo inspect --raw "docker://${DEST_REPO_APPCI}:stable-single" | grep -q layers + +# copy in v2s2 mode +skopeo inspect --raw "docker://${DEST_REPO_APPCI}:stable-single" | grep -q vnd.oci.image.config.v1 +cosa copy-container --dest-authfile "${DEST_REPO_APPCI_AUTHFILE}" \ + --tag=stable-single --v2s2 "${SRC_REPO}" "${DEST_REPO_APPCI}" +skopeo inspect --raw "docker://${DEST_REPO_APPCI}:stable-single" | grep -q vnd.docker.distribution.manifest.v2 diff --git a/tests/test_cli.py b/tests/test_cli.py index 17287dcb..31daed19 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -37,7 +37,7 @@ def test_build_cli_additional_args(): Ensure that BuildCli contains the expected additional default args """ parser = BuildCli() - expected = ['--build', '--buildroot', '--dump'] + expected = ['--build', '--buildroot'] for action in parser._actions: for expect in expected: if expect in action.option_strings: diff --git a/tests/test_cosalib_cmdlib.py b/tests/test_cosalib_cmdlib.py index 63f9833b..e720866d 100644 --- a/tests/test_cosalib_cmdlib.py +++ b/tests/test_cosalib_cmdlib.py @@ -13,17 +13,17 @@ from cosalib import cmdlib PY_MAJOR, PY_MINOR, PY_PATCH = platform.python_version_tuple() -def test_run_verbose(): +def test_runcmd(): """ - Verify run_verbose returns expected information + Verify runcmd returns expected information """ - result = cmdlib.run_verbose(['echo', 'hi']) + result = cmdlib.runcmd(['echo', 'hi']) assert result.stdout is None with pytest.raises(FileNotFoundError): - cmdlib.run_verbose(['idonotexist']) + cmdlib.runcmd(['idonotexist']) # If we are not at least on Python 3.7 we must skip the following test if PY_MAJOR == 3 and PY_MINOR >= 7: - result = cmdlib.run_verbose(['echo', 'hi'], capture_output=True) + result = cmdlib.runcmd(['echo', 'hi'], capture_output=True) assert result.stdout == b'hi\n' @@ -103,10 +103,10 @@ def test_rm_allow_noent(tmpdir): def test_image_info(tmpdir): - cmdlib.run_verbose([ + cmdlib.runcmd([ "qemu-img", "create", "-f", "qcow2", f"{tmpdir}/test.qcow2", "10M"]) assert cmdlib.image_info(f"{tmpdir}/test.qcow2").get('format') == "qcow2" - cmdlib.run_verbose([ + cmdlib.runcmd([ "qemu-img", "create", "-f", "vpc", '-o', 'force_size,subformat=fixed', f"{tmpdir}/test.vpc", "10M"]) -- Gitee