Skip to content

Commit 9f93e99

Browse files
committed
update install tests
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
1 parent 37c573f commit 9f93e99

5 files changed

Lines changed: 70 additions & 8 deletions

File tree

Makefile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ unit: ## Run unit tests
9999
$(call title,Running unit tests)
100100
go test $(shell go list ./... | grep -v anchore/$(REPO)/test)
101101

102+
# note: this is used by CI to determine if the install test fixture cache (docker image tars) should be busted
103+
install-fingerprint:
104+
cd test/install && \
105+
make cache.fingerprint
106+
107+
install-test: $(SNAPSHOT_DIR)
108+
cd test/install && \
109+
make
110+
111+
install-test-cache-save: $(SNAPSHOT_DIR)
112+
cd test/install && \
113+
make save
114+
115+
install-test-cache-load: $(SNAPSHOT_DIR)
116+
cd test/install && \
117+
make load
118+
119+
install-test-ci-mac: $(SNAPSHOT_DIR)
120+
cd test/install && \
121+
make ci-test-mac
122+
102123
$(SNAPSHOT_DIR): $(TEMP_DIR) ## Build snapshot release binaries and packages
103124
$(call title,Building snapshot artifacts)
104125
# create a config with the dist dir overridden
@@ -114,7 +135,6 @@ release: clean-dist ## Build and publish final binaries and packages
114135

115136
.PHONY: clean
116137
clean: clean-dist clean-snapshot clean-changelog ## Remove previous builds, result reports, and caches
117-
rm -rf $(RESULT_DIR)/*
118138

119139
.PHONY: clean-snapshot
120140
clean-snapshot:

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ main() (
715715
log_info "using release tag='${tag}' version='${version}' os='${os}' arch='${arch}'"
716716
log_debug "downloading files into ${download_dir}"
717717

718-
download_and_install_asset "${download_url}" "${download_dir}" "${install_dir}" "${BINARY}" "${os}" "${arch}" "${version}" "${format}" "${binary}"
718+
download_and_install_asset "${download_url}" "${download_dir}" "${install_dir}" "${PROJECT_NAME}" "${os}" "${arch}" "${version}" "${format}" "${binary}"
719719

720720
# don't continue if we couldn't install the asset
721721
if [ "$?" != "0" ]; then

test/install/Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ ALPINE_IMAGE=$(IMAGE_NAME):alpine-3.6
66
BUSYBOX_IMAGE=busybox:1.35
77

88
ENVS=./environments
9-
DOCKER_RUN=docker run --rm -t -w /project/test/install -v $(shell pwd)/../../:/project
9+
DOCKER_RUN=docker run --rm -t -w /project/test/install -v /var/run/docker.sock:/var/run/docker.sock -v $(shell pwd)/../../:/project
1010
UNIT=make unit-local
1111

1212
# acceptance testing is running the current install.sh against the latest release. Note: this could be a problem down
1313
# the line if there are breaking changes made that don't align with the latest release (but will be OK with the next
1414
# release)
15-
acceptance=sh -c 'curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin && ../../install.sh && docker sbom version'
15+
CURL_INSTALL_SYFT=curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
16+
WGET_INSTALL_SYFT=wget -O - https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
17+
ACCEPTANCE_CMD=../../install.sh && docker sbom version
1618

1719
# CI cache busting values; change these if you want CI to not use previous stored cache
1820
INSTALL_TEST_CACHE_BUSTER=894d8ca
@@ -55,7 +57,7 @@ load:
5557
acceptance-ubuntu-20.04: ubuntu-20.04
5658
$(call title,ubuntu:20.04 - acceptance)
5759
$(DOCKER_RUN) $(UBUNTU_IMAGE) \
58-
$(acceptance)
60+
sh -c '$(CURL_INSTALL_SYFT) && $(ACCEPTANCE_CMD)'
5961

6062
unit-ubuntu-20.04: ubuntu-20.04
6163
$(call title,ubuntu:20.04 - unit)
@@ -73,7 +75,7 @@ ubuntu-20.04:
7375
acceptance-alpine-3.6: alpine-3.6
7476
$(call title,alpine:3.6 - acceptance)
7577
$(DOCKER_RUN) $(ALPINE_IMAGE) \
76-
$(acceptance)
78+
sh -c '$(WGET_INSTALL_SYFT) && $(ACCEPTANCE_CMD)'
7779

7880
alpine-3.6:
7981
$(call title,alpine:3.6 - build environment)
@@ -88,7 +90,7 @@ alpine-3.6:
8890
acceptance-busybox-1.35: busybox-1.35
8991
$(call title,busybox-1.35 - acceptance)
9092
$(DOCKER_RUN) $(BUSYBOX_IMAGE) \
91-
$(acceptance)
93+
sh -c '$(WGET_INSTALL_SYFT) && $(ACCEPTANCE_CMD)'
9294

9395
busybox-1.35:
9496
$(call title,busybox-1.35 - build environment)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
. test_harness.sh
2+
3+
test_download_release_asset() {
4+
release="$1"
5+
os="$2"
6+
arch="$3"
7+
format="$4"
8+
expected_mime_type="$5"
9+
10+
# for troubleshooting
11+
# log_set_priority 10
12+
13+
name=${PROJECT_NAME}
14+
version=$(tag_to_version ${release})
15+
github_download="https://github.com/${OWNER}/${REPO}/releases/download/${release}"
16+
17+
tmpdir=$(mktemp -d)
18+
19+
actual_filepath=$(download_asset "${github_download}" "${tmpdir}" "${name}" "${os}" "${arch}" "${version}" "${format}" )
20+
21+
assertFileExists "${actual_filepath}" "download_asset os=${os} arch=${arch} format=${format}"
22+
23+
actual_mime_type=$(file -b --mime-type ${actual_filepath})
24+
25+
assertEquals "${expected_mime_type}" "${actual_mime_type}" "unexpected mimetype for os=${os} arch=${arch} format=${format}"
26+
27+
rm -rf -- "$tmpdir"
28+
}
29+
30+
# always test against the latest release
31+
release=$(get_release_tag "${OWNER}" "${REPO}" "latest" )
32+
33+
# exercise all possible assets against a real github release (based on asset listing from https://github.com/anchore/docker-sbom-cli-plugin/releases/tag/v0.1.0)
34+
run_test_case test_download_release_asset "${release}" "darwin" "amd64" "tar.gz" "application/gzip"
35+
run_test_case test_download_release_asset "${release}" "darwin" "arm64" "tar.gz" "application/gzip"
36+
run_test_case test_download_release_asset "${release}" "linux" "amd64" "tar.gz" "application/gzip"
37+
run_test_case test_download_release_asset "${release}" "linux" "arm64" "tar.gz" "application/gzip"
38+
run_test_case test_download_release_asset "${release}" "windows" "amd64" "zip" "application/zip"
39+
run_test_case test_download_release_asset "${release}" "windows" "arm64" "zip" "application/zip"
40+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM alpine:3.6
1+
FROM alpine:3.15
22
RUN apk update && apk add python3 wget unzip make ca-certificates docker-cli
33
RUN mkdir ~/.docker

0 commit comments

Comments
 (0)