Skip to content

Commit f9b0c70

Browse files
Test install script in pipeline
Authored-by: Owen Nelson <[email protected]>
1 parent d36d166 commit f9b0c70

File tree

3 files changed

+89
-2
lines changed

3 files changed

+89
-2
lines changed

.github/workflows/test-and-coverage.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build
1+
name: Test
22

33
on:
44
push:
@@ -27,3 +27,9 @@ jobs:
2727
# You may pin to the exact commit or the version.
2828
# uses: codecov/codecov-action@e156083f13aff6830c92fc5faa23505779fbf649
2929
uses: codecov/[email protected]
30+
31+
- name: Install bash_unit
32+
run: bash <(curl -s https://raw.githubusercontent.com/pgrange/bash_unit/master/install.sh)
33+
34+
- name: Test install script
35+
run: ./bash_unit test-install.sh

install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function set_binary_name() {
8080

8181
function download() {
8282
ASSETS=$(curl -Ls https://api.github.com/repos/"$INSTALL_ORG_REPO"/releases/latest |
83-
grep download_url | awk '{print $2}' | tr -d '"')
83+
grep download_url | awk '{print $2}' | tr -d '"')
8484
BINARY_URL=$(echo "$ASSETS" | grep "$BINARY_NAME")
8585
CHECKSUM_URL=$(echo "$ASSETS" | grep $CHECKSUM_FILE_NAME)
8686
echo_debug "Downloading $BINARY_NAME and from $BINARY_URL"

test-install.sh

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
_linux_uname() {
2+
if [ "${FAKE_PARAMS[0]}" = "-m" ]; then
3+
echo "x86_64"
4+
else
5+
echo "Linux"
6+
fi
7+
}
8+
export -f _linux_uname
9+
10+
_windows_uname() {
11+
if [ "${FAKE_PARAMS[0]}" = "-m" ]; then
12+
echo "i686"
13+
else
14+
echo "MINGW64_NT-10.0-19045"
15+
fi
16+
}
17+
export -f _windows_uname
18+
19+
_mac_uname() {
20+
if [ "${FAKE_PARAMS[0]}" = "-m" ]; then
21+
echo "aarch64"
22+
else
23+
echo "Darwin"
24+
fi
25+
}
26+
export -f _mac_uname
27+
28+
setup() {
29+
temp=$(mktemp -d)
30+
fake uname _linux_uname
31+
fake curl 'echo "download_url: talisman_linux_amd64checksums"'
32+
fake shasum true
33+
fake tput true
34+
}
35+
36+
teardown() {
37+
rm -rf "$temp"
38+
}
39+
40+
test_installs_without_sudo() {
41+
fake sudo 'echo "expected no sudo" && exit 1'
42+
INSTALL_LOCATION=$temp ./install.sh
43+
assert "test -x $temp/talisman_linux_amd64" "Should install file with executable mode"
44+
assert_matches "$temp/talisman_linux_amd64" "$(readlink "$temp/talisman")" "Should create a link"
45+
}
46+
47+
test_installs_with_sudo_if_available() {
48+
fake touch 'echo "Permission denied" && exit 1'
49+
fake which 'echo "sudo installed" && exit 0'
50+
# shellcheck disable=SC2016
51+
fake sudo 'bash -c "${FAKE_PARAMS[*]}"'
52+
INSTALL_LOCATION=$temp ./install.sh
53+
assert "test -x $temp/talisman_linux_amd64" "Should install file with executable mode"
54+
assert_matches "$temp/talisman_linux_amd64" "$(readlink "$temp/talisman")" "Should create a link"
55+
}
56+
57+
test_errors_if_unable_to_install() {
58+
fake touch 'echo "Permission denied" && exit 1'
59+
fake which 'echo "sudo not installed" && exit 1'
60+
assert_status_code 126 "INSTALL_LOCATION=$temp ./install.sh"
61+
}
62+
63+
test_errors_if_no_install_location() {
64+
assert_status_code 1 "INSTALL_LOCATION=/does/not/exist ./install.sh"
65+
}
66+
67+
test_mac_arm_binary_name() {
68+
fake uname _mac_uname
69+
fake curl 'echo "download_url: talisman_darwin_arm64checksums"'
70+
INSTALL_LOCATION=$temp ./install.sh
71+
assert "test -x $temp/talisman_darwin_arm64" "Should install file with executable mode"
72+
assert_matches "$temp/talisman_darwin_arm64" "$(readlink "$temp/talisman")" "Should create a link"
73+
}
74+
75+
test_windows_binary_name() {
76+
fake uname _windows_uname
77+
fake curl 'echo "download_url: talisman_windows_386.exechecksums"'
78+
INSTALL_LOCATION=$temp ./install.sh
79+
assert "test -x $temp/talisman_windows_386.exe" "Should install file with executable mode"
80+
assert_matches "$temp/talisman_windows_386.exe" "$(readlink "$temp/talisman")" "Should create a link"
81+
}

0 commit comments

Comments
 (0)