From 2ced59fba35cd8b46a5b9355f4fdd6db3e674c71 Mon Sep 17 00:00:00 2001 From: Meredith Lancaster Date: Wed, 11 Dec 2024 07:42:05 -0700 Subject: [PATCH] update integration test scripts Signed-off-by: Meredith Lancaster --- .github/workflows/go.yml | 4 +- .../attestation-cmd/download/download.sh | 48 +++++++++++++++++++ .../attestation-cmd/run-all-tests.sh | 19 +++++++- 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100755 test/integration/attestation-cmd/download/download.sh diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index fb9b8687f..c0dd463b1 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -51,6 +51,6 @@ jobs: - name: Build executable run: make - - name: Run attestation command integration tests - linux syntax + - name: Run attestation command set integration tests run: | - ./test/integration/attestation-cmd/run-all-tests.sh + ./test/integration/attestation-cmd/run-all-tests.sh "${{ matrix.os }}" diff --git a/test/integration/attestation-cmd/download/download.sh b/test/integration/attestation-cmd/download/download.sh new file mode 100755 index 000000000..166ed55be --- /dev/null +++ b/test/integration/attestation-cmd/download/download.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +os=$1 + +# Get the root directory of the repository +rootDir="$(git rev-parse --show-toplevel)" + +ghBuildPath="$rootDir/bin/gh" + +artifactPath="$rootDir/pkg/cmd/attestation/test/data/sigstore-js-2.1.0.tgz" + +# Download attestations for the package +if ! $ghBuildPath attestation download "$artifactPath" --owner=sigstore --digest-alg=sha512; then + # cleanup test data + echo "Failed to download attestations" + exit 1 +fi + +digest=$(shasum -a 512 sigstore-js-2.1.0.tgz.sha512 | awk '{print ""$1""}') + +attestation_filename="sha512:$digest.jsonl" +if [ "$os" == "windows-latest" ]; then + echo "Running the test on Windows." + echo "Build the expected filename accordingly" + attestation_filename="sha512-$digest.jsonl" +fi + +if [ ! -f "$attestation_filename" ]; then + echo "Expected attestation file $attestation_filename not found" + exit 1 +fi + +if [ ! -s "$attestation_filename" ]; then + echo "Attestation file $attestation_filename is empty" + rm "$attestation_filename" + exit 1 +fi + +cat "$attestation_filename" + +# Clean up the downloaded attestation file +rm "$attestation_filename" diff --git a/test/integration/attestation-cmd/run-all-tests.sh b/test/integration/attestation-cmd/run-all-tests.sh index 584c50568..45fba964e 100755 --- a/test/integration/attestation-cmd/run-all-tests.sh +++ b/test/integration/attestation-cmd/run-all-tests.sh @@ -1,13 +1,30 @@ #!/usr/bin/env bash set -euo pipefail +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +os=$1 + # Get the root directory of the repository rootDir="$(git rev-parse --show-toplevel)" verify_test_dir="$rootDir/test/integration/attestation-cmd/verify" +echo "Running all \"gh attestation verify\" tests" for script in "$verify_test_dir"/*.sh; do if [ -f "$script" ]; then echo "Running $script..." - $script + bash "$script" + fi +done + +download_test_dir="$rootDir/test/integration/attestation-cmd/download" +echo "Running all \"gh attestation download\" tests" +for script in "$download_test_dir"/*.sh; do + if [ -f "$script" ]; then + echo "Running $script..." + bash "$script" "$os" fi done