github.com/metasources/buildx@v0.0.0-20230418141019-7aa1459cedea/test/install/1_download_snapshot_asset_test.sh (about) 1 . test_harness.sh 2 3 DOWNLOAD_SNAPSHOT_POSITIVE_CASES=0 4 5 # helper for asserting test_positive_snapshot_download_asset positive cases 6 test_positive_snapshot_download_asset() { 7 os="$1" 8 arch="$2" 9 format="$3" 10 11 # for troubleshooting 12 # log_set_priority 10 13 14 name=${PROJECT_NAME} 15 github_download=$(snapshot_download_url) 16 version=$(snapshot_version) 17 18 tmpdir=$(mktemp -d) 19 20 actual_filepath=$(download_asset "${github_download}" "${tmpdir}" "${name}" "${os}" "${arch}" "${version}" "${format}" ) 21 22 assertFileExists "${actual_filepath}" "download_asset os=${os} arch=${arch} format=${format}" 23 24 assertFilesEqual \ 25 "$(snapshot_dir)/${name}_${version}_${os}_${arch}.${format}" \ 26 "${actual_filepath}" \ 27 "unable to download os=${os} arch=${arch} format=${format}" 28 29 ((DOWNLOAD_SNAPSHOT_POSITIVE_CASES++)) 30 31 rm -rf -- "$tmpdir" 32 } 33 34 35 test_download_snapshot_asset_exercised_all_assets() { 36 expected=$(snapshot_assets_count) 37 38 assertEquals "${expected}" "${DOWNLOAD_SNAPSHOT_POSITIVE_CASES}" "did not download all possible assets (missing an os/arch/format variant?)" 39 } 40 41 # helper for asserting download_asset negative cases 42 test_negative_snapshot_download_asset() { 43 os="$1" 44 arch="$2" 45 format="$3" 46 47 # for troubleshooting 48 # log_set_priority 10 49 50 name=${PROJECT_NAME} 51 github_download=$(snapshot_download_url) 52 version=$(snapshot_version) 53 54 tmpdir=$(mktemp -d) 55 56 actual_filepath=$(download_asset "${github_download}" "${tmpdir}" "${name}" "${os}" "${arch}" "${version}" "${format}") 57 58 assertEquals "" "${actual_filepath}" "unable to download os=${os} arch=${arch} format=${format}" 59 60 rm -rf -- "$tmpdir" 61 } 62 63 64 worker_pid=$(setup_snapshot_server) 65 trap 'teardown_snapshot_server ${worker_pid}' EXIT 66 67 # exercise all possible assets 68 run_test_case test_positive_snapshot_download_asset "linux" "amd64" "tar.gz" 69 run_test_case test_positive_snapshot_download_asset "linux" "amd64" "rpm" 70 run_test_case test_positive_snapshot_download_asset "linux" "amd64" "deb" 71 run_test_case test_positive_snapshot_download_asset "linux" "arm64" "tar.gz" 72 run_test_case test_positive_snapshot_download_asset "linux" "arm64" "rpm" 73 run_test_case test_positive_snapshot_download_asset "linux" "arm64" "deb" 74 run_test_case test_positive_snapshot_download_asset "linux" "ppc64le" "tar.gz" 75 run_test_case test_positive_snapshot_download_asset "linux" "ppc64le" "rpm" 76 run_test_case test_positive_snapshot_download_asset "linux" "ppc64le" "deb" 77 run_test_case test_positive_snapshot_download_asset "linux" "s390x" "tar.gz" 78 run_test_case test_positive_snapshot_download_asset "linux" "s390x" "rpm" 79 run_test_case test_positive_snapshot_download_asset "linux" "s390x" "deb" 80 81 run_test_case test_positive_snapshot_download_asset "darwin" "amd64" "tar.gz" 82 run_test_case test_positive_snapshot_download_asset "darwin" "arm64" "tar.gz" 83 run_test_case test_positive_snapshot_download_asset "windows" "amd64" "zip" 84 # note: the mac signing process produces a dmg which is not part of the snapshot process (thus is not exercised here) 85 86 # let's make certain we covered all assets that were expected 87 run_test_case test_download_snapshot_asset_exercised_all_assets 88 89 # make certain we handle missing assets alright 90 run_test_case test_negative_snapshot_download_asset "bogus" "amd64" "zip" 91 92 trap - EXIT 93 teardown_snapshot_server "${worker_pid}"