github.com/anchore/syft@v1.38.2/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 # note: this is a change made in goreleaser v1.62.0 36 local_suffix="" 37 if [ "${arch}" == "arm64" ]; then 38 local_suffix="_v8.0" 39 fi 40 41 # note: this is a change made in goreleaser v2.5.0 42 if [ "${arch}" == "ppc64le" ]; then 43 local_suffix="_power8" 44 fi 45 46 47 assertFilesEqual \ 48 "$(snapshot_dir)/${os}-build_${os}_${arch}${local_suffix}/${binary}" \ 49 "${expected_path}" \ 50 "unable to verify installation of os=${os} arch=${arch} format=${format}" 51 52 ((INSTALL_ARCHIVE_POSITIVE_CASES++)) 53 54 rm -rf -- "$download_dir" 55 rm -rf -- "$install_dir" 56 } 57 58 # helper for asserting install_asset negative cases 59 test_negative_snapshot_install_asset() { 60 os="$1" 61 arch="$2" 62 format="$3" 63 64 # for troubleshooting 65 # log_set_priority 10 66 67 name=${PROJECT_NAME} 68 binary=$(get_binary_name "${os}" "${arch}" "${PROJECT_NAME}") 69 github_download=$(snapshot_download_url) 70 version=$(snapshot_version) 71 72 download_dir=$(mktemp -d) 73 install_dir=$(mktemp -d) 74 75 download_and_install_asset "${github_download}" "${download_dir}" "${install_dir}" "${name}" "${os}" "${arch}" "${version}" "${format}" "${binary}" 76 77 assertNotEquals "0" "$?" "download/install should have failed but did not" 78 79 rm -rf -- "$download_dir" 80 rm -rf -- "$install_dir" 81 } 82 83 84 test_install_asset_exercised_all_archive_assets() { 85 expected=$(snapshot_assets_archive_count) 86 87 assertEquals "${expected}" "${INSTALL_ARCHIVE_POSITIVE_CASES}" "did not download all possible archive assets (missing an os/arch/format variant?)" 88 } 89 90 91 worker_pid=$(setup_snapshot_server) 92 trap 'teardown_snapshot_server ${worker_pid}' EXIT 93 94 # exercise all possible archive assets (not rpm/deb/dmg) against a snapshot build 95 run_test_case test_positive_snapshot_install_asset "linux" "amd64" "tar.gz" 96 run_test_case test_positive_snapshot_install_asset "linux" "arm64" "tar.gz" 97 run_test_case test_positive_snapshot_install_asset "linux" "ppc64le" "tar.gz" 98 run_test_case test_positive_snapshot_install_asset "linux" "s390x" "tar.gz" 99 run_test_case test_positive_snapshot_install_asset "darwin" "amd64" "tar.gz" 100 run_test_case test_positive_snapshot_install_asset "darwin" "arm64" "tar.gz" 101 run_test_case test_positive_snapshot_install_asset "windows" "amd64" "zip" 102 run_test_case test_positive_snapshot_install_asset "windows" "arm64" "zip" 103 104 # let's make certain we covered all assets that were expected 105 run_test_case test_install_asset_exercised_all_archive_assets 106 107 # make certain we handle missing assets alright 108 run_test_case test_negative_snapshot_install_asset "bogus" "amd64" "zip" 109 110 trap - EXIT 111 teardown_snapshot_server "${worker_pid}"