mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
Refactor install.sh (#765)
* [wip] get assets based on gh api Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * put install.sh download_asset fn under test Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * put install.sh install_asset fn under test Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * use zip for darwin installs Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix install.sh negative test cases Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * allow errors to propagate in install.sh Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove exit on error from install.sh tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add more docs around install.sh helpers Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add integration tests for install.sh Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add install.sh testing to pipeline Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add install test cache to CI Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * make colors globally available Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * test download against github release Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * always test release-based install against latest release Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * use better install.sh test names Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
. test_harness.sh
|
||||
|
||||
test_download_release_asset() {
|
||||
release="$1"
|
||||
os="$2"
|
||||
arch="$3"
|
||||
format="$4"
|
||||
expected_mime_type="$5"
|
||||
|
||||
# for troubleshooting
|
||||
# log_set_priority 10
|
||||
|
||||
name=${PROJECT_NAME}
|
||||
version=$(tag_to_version ${release})
|
||||
github_download="https://github.com/${OWNER}/${REPO}/releases/download/${release}"
|
||||
|
||||
tmpdir=$(mktemp -d)
|
||||
|
||||
actual_filepath=$(download_asset "${github_download}" "${tmpdir}" "${name}" "${os}" "${arch}" "${version}" "${format}" )
|
||||
|
||||
assertFileExists "${actual_filepath}" "download_asset os=${os} arch=${arch} format=${format}"
|
||||
|
||||
actual_mime_type=$(file -b --mime-type ${actual_filepath})
|
||||
|
||||
assertEquals "${expected_mime_type}" "${actual_mime_type}" "unexpected mimetype for os=${os} arch=${arch} format=${format}"
|
||||
|
||||
rm -rf -- "$tmpdir"
|
||||
}
|
||||
|
||||
# always test against the latest release
|
||||
release=$(get_release_tag "${OWNER}" "${REPO}" "latest" )
|
||||
|
||||
# exercise all possible assets against a real github release (based on asset listing from https://github.com/anchore/syft/releases/tag/v0.36.0)
|
||||
run_test_case test_download_release_asset "${release}" "darwin" "amd64" "tar.gz" "application/gzip"
|
||||
run_test_case test_download_release_asset "${release}" "darwin" "arm64" "tar.gz" "application/gzip"
|
||||
run_test_case test_download_release_asset "${release}" "darwin" "arm64" "zip" "application/zip"
|
||||
run_test_case test_download_release_asset "${release}" "darwin" "amd64" "dmg" "application/zlib"
|
||||
run_test_case test_download_release_asset "${release}" "linux" "amd64" "tar.gz" "application/gzip"
|
||||
run_test_case test_download_release_asset "${release}" "linux" "amd64" "rpm" "application/x-rpm"
|
||||
run_test_case test_download_release_asset "${release}" "linux" "amd64" "deb" "application/vnd.debian.binary-package"
|
||||
run_test_case test_download_release_asset "${release}" "linux" "arm64" "tar.gz" "application/gzip"
|
||||
run_test_case test_download_release_asset "${release}" "linux" "arm64" "rpm" "application/x-rpm"
|
||||
run_test_case test_download_release_asset "${release}" "linux" "arm64" "deb" "application/vnd.debian.binary-package"
|
||||
Reference in New Issue
Block a user