github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/test/install/3_install_asset_test.sh (about) 1 . test_harness.sh 2 3 INSTALL_ARCHIVE_POSITIVE_CASES=0 4 5 # helper for asserting install_asset positive cases 6 test_positive_snapshot_install_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 binary=$(get_binary_name "${os}" "${arch}" "${PROJECT_NAME}") 16 github_download=$(snapshot_download_url) 17 version=$(snapshot_version) 18 19 download_dir=$(mktemp -d) 20 install_dir=$(mktemp -d) 21 22 download_and_install_asset "${github_download}" "${download_dir}" "${install_dir}" "${name}" "${os}" "${arch}" "${version}" "${format}" "${binary}" 23 24 assertEquals "0" "$?" "download/install did not succeed" 25 26 expected_path="${install_dir}/${binary}" 27 assertFileExists "${expected_path}" "install_asset os=${os} arch=${arch} format=${format}" 28 29 # directory structure for arch has been updated as of go 1.18 30 # https://goreleaser.com/customization/build/#why-is-there-a-_v1-suffix-on-amd64-buildsjk 31 if [ $arch == "amd64" ]; then 32 arch="amd64_v1" 33 fi 34 35 assertFilesEqual \ 36 "$(snapshot_dir)/${os}-build_${os}_${arch}/${binary}" \ 37 "${expected_path}" \ 38 "unable to verify installation of os=${os} arch=${arch} format=${format}" 39 40 ((INSTALL_ARCHIVE_POSITIVE_CASES++)) 41 42 rm -rf -- "$download_dir" 43 rm -rf -- "$install_dir" 44 } 45 46 # helper for asserting install_asset negative cases 47 test_negative_snapshot_install_asset() { 48 os="$1" 49 arch="$2" 50 format="$3" 51 52 # for troubleshooting 53 # log_set_priority 10 54 55 name=${PROJECT_NAME} 56 binary=$(get_binary_name "${os}" "${arch}" "${PROJECT_NAME}") 57 github_download=$(snapshot_download_url) 58 version=$(snapshot_version) 59 60 download_dir=$(mktemp -d) 61 install_dir=$(mktemp -d) 62 63 download_and_install_asset "${github_download}" "${download_dir}" "${install_dir}" "${name}" "${os}" "${arch}" "${version}" "${format}" "${binary}" 64 65 assertNotEquals "0" "$?" "download/install should have failed but did not" 66 67 rm -rf -- "$download_dir" 68 rm -rf -- "$install_dir" 69 } 70 71 72 test_install_asset_exercised_all_archive_assets() { 73 expected=$(snapshot_assets_archive_count) 74 75 assertEquals "${expected}" "${INSTALL_ARCHIVE_POSITIVE_CASES}" "did not download all possible archive assets (missing an os/arch/format variant?)" 76 } 77 78 79 worker_pid=$(setup_snapshot_server) 80 trap 'teardown_snapshot_server ${worker_pid}' EXIT 81 82 # exercise all possible archive assets (not rpm/deb/dmg) against a snapshot build 83 run_test_case test_positive_snapshot_install_asset "linux" "amd64" "tar.gz" 84 run_test_case test_positive_snapshot_install_asset "linux" "arm64" "tar.gz" 85 run_test_case test_positive_snapshot_install_asset "linux" "ppc64le" "tar.gz" 86 run_test_case test_positive_snapshot_install_asset "linux" "s390x" "tar.gz" 87 run_test_case test_positive_snapshot_install_asset "darwin" "amd64" "tar.gz" 88 run_test_case test_positive_snapshot_install_asset "darwin" "arm64" "tar.gz" 89 run_test_case test_positive_snapshot_install_asset "windows" "amd64" "zip" 90 91 # let's make certain we covered all assets that were expected 92 run_test_case test_install_asset_exercised_all_archive_assets 93 94 # make certain we handle missing assets alright 95 run_test_case test_negative_snapshot_install_asset "bogus" "amd64" "zip" 96 97 trap - EXIT 98 teardown_snapshot_server "${worker_pid}"