install_platform_test.sh RawHistoryFolder
1#!/bin/sh
2set -eu
3
4ROOT_DIR=$(CDPATH='' cd "$(dirname "$0")/.." && pwd)
5TEST_DIR=$(mktemp -d)
6trap 'rm -rf "$TEST_DIR"' EXIT HUP INT TERM
7
8FAKE_BIN="$TEST_DIR/bin"
9mkdir -p "$FAKE_BIN"
10
11cat >"$FAKE_BIN/uname" <<'EOF'
12#!/bin/sh
13case "${1:-}" in
14 -s) printf '%s\n' "$FAKE_OS" ;;
15 -m) printf '%s\n' "$FAKE_ARCH" ;;
16 *) exit 2 ;;
17esac
18EOF
19
20cat >"$FAKE_BIN/curl" <<'EOF'
21#!/bin/sh
22printf '%s\n' "$*" >>"$CURL_LOG"
23exit 97
24EOF
25
26chmod +x "$FAKE_BIN/uname" "$FAKE_BIN/curl"
27
28fail() {
29 printf 'FAIL: %s\n' "$*" >&2
30 exit 1
31}
32
33assert_mapping() {
34 os=$1
35 arch=$2
36 tarball=$3
37 curl_log="$TEST_DIR/curl-$os-$arch.log"
38 output="$TEST_DIR/output-$os-$arch.log"
39
40 if FAKE_OS=$os FAKE_ARCH=$arch CURL_LOG=$curl_log HOME="$TEST_DIR/home" \
41 PATH="$FAKE_BIN:$PATH" VEV_VERSION=v0.0.0 \
42 sh "$ROOT_DIR/install.sh" >"$output" 2>&1; then
43 fail "$os/$arch unexpectedly completed installation"
44 fi
45
46 expected_url="https://git.bnema.dev/vev/releases/download/v0.0.0/$tarball"
47 [ -f "$curl_log" ] || fail "$os/$arch did not attempt a download"
48 grep -F "$expected_url" "$curl_log" >/dev/null \
49 || fail "$os/$arch did not select $tarball"
50 [ "$(wc -l <"$curl_log" | tr -d ' ')" = 1 ] \
51 || fail "$os/$arch attempted more than the archive download"
52}
53
54assert_mapping Linux x86_64 vev_linux_x86_64.tar.gz
55assert_mapping Linux amd64 vev_linux_x86_64.tar.gz
56assert_mapping Linux aarch64 vev_linux_arm64.tar.gz
57assert_mapping Linux arm64 vev_linux_arm64.tar.gz
58assert_mapping Darwin arm64 vev_darwin_arm64.tar.gz
59
60curl_log="$TEST_DIR/curl-Linux-armv7l.log"
61output="$TEST_DIR/output-Linux-armv7l.log"
62if FAKE_OS=Linux FAKE_ARCH=armv7l CURL_LOG=$curl_log HOME="$TEST_DIR/home" \
63 PATH="$FAKE_BIN:$PATH" VEV_VERSION=v0.0.0 \
64 sh "$ROOT_DIR/install.sh" >"$output" 2>&1; then
65 fail "Linux/armv7l unexpectedly succeeded"
66fi
67grep -F "unsupported platform: linux/armv7l" "$output" >/dev/null \
68 || fail "Linux/armv7l did not report an unsupported platform"
69grep -F "supported: linux/x86_64, linux/arm64, darwin/arm64" "$output" >/dev/null \
70 || fail "Linux/armv7l did not list the canonical supported platforms"
71[ ! -e "$curl_log" ] || fail "Linux/armv7l invoked curl before rejection"
72
73printf 'installer platform tests passed\n'