Skip to content

Commit

Permalink
Test install script in pipeline
Browse files Browse the repository at this point in the history
Authored-by: Owen Nelson <[email protected]>
  • Loading branch information
tw-owen-nelson committed Jan 25, 2024
1 parent d36d166 commit f9b0c70
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/test-and-coverage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Test

on:
push:
Expand Down Expand Up @@ -27,3 +27,9 @@ jobs:
# You may pin to the exact commit or the version.
# uses: codecov/codecov-action@e156083f13aff6830c92fc5faa23505779fbf649
uses: codecov/[email protected]

- name: Install bash_unit
run: bash <(curl -s https://raw.githubusercontent.com/pgrange/bash_unit/master/install.sh)

- name: Test install script
run: ./bash_unit test-install.sh
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function set_binary_name() {

function download() {
ASSETS=$(curl -Ls https://api.github.com/repos/"$INSTALL_ORG_REPO"/releases/latest |
grep download_url | awk '{print $2}' | tr -d '"')
grep download_url | awk '{print $2}' | tr -d '"')
BINARY_URL=$(echo "$ASSETS" | grep "$BINARY_NAME")
CHECKSUM_URL=$(echo "$ASSETS" | grep $CHECKSUM_FILE_NAME)
echo_debug "Downloading $BINARY_NAME and from $BINARY_URL"
Expand Down
81 changes: 81 additions & 0 deletions test-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
_linux_uname() {
if [ "${FAKE_PARAMS[0]}" = "-m" ]; then
echo "x86_64"
else
echo "Linux"
fi
}
export -f _linux_uname

_windows_uname() {
if [ "${FAKE_PARAMS[0]}" = "-m" ]; then
echo "i686"
else
echo "MINGW64_NT-10.0-19045"
fi
}
export -f _windows_uname

_mac_uname() {
if [ "${FAKE_PARAMS[0]}" = "-m" ]; then
echo "aarch64"
else
echo "Darwin"
fi
}
export -f _mac_uname

setup() {
temp=$(mktemp -d)
fake uname _linux_uname
fake curl 'echo "download_url: talisman_linux_amd64checksums"'
fake shasum true
fake tput true
}

teardown() {
rm -rf "$temp"
}

test_installs_without_sudo() {
fake sudo 'echo "expected no sudo" && exit 1'
INSTALL_LOCATION=$temp ./install.sh
assert "test -x $temp/talisman_linux_amd64" "Should install file with executable mode"
assert_matches "$temp/talisman_linux_amd64" "$(readlink "$temp/talisman")" "Should create a link"
}

test_installs_with_sudo_if_available() {
fake touch 'echo "Permission denied" && exit 1'
fake which 'echo "sudo installed" && exit 0'
# shellcheck disable=SC2016
fake sudo 'bash -c "${FAKE_PARAMS[*]}"'
INSTALL_LOCATION=$temp ./install.sh
assert "test -x $temp/talisman_linux_amd64" "Should install file with executable mode"
assert_matches "$temp/talisman_linux_amd64" "$(readlink "$temp/talisman")" "Should create a link"
}

test_errors_if_unable_to_install() {
fake touch 'echo "Permission denied" && exit 1'
fake which 'echo "sudo not installed" && exit 1'
assert_status_code 126 "INSTALL_LOCATION=$temp ./install.sh"
}

test_errors_if_no_install_location() {
assert_status_code 1 "INSTALL_LOCATION=/does/not/exist ./install.sh"
}

test_mac_arm_binary_name() {
fake uname _mac_uname
fake curl 'echo "download_url: talisman_darwin_arm64checksums"'
INSTALL_LOCATION=$temp ./install.sh
assert "test -x $temp/talisman_darwin_arm64" "Should install file with executable mode"
assert_matches "$temp/talisman_darwin_arm64" "$(readlink "$temp/talisman")" "Should create a link"
}

test_windows_binary_name() {
fake uname _windows_uname
fake curl 'echo "download_url: talisman_windows_386.exechecksums"'
INSTALL_LOCATION=$temp ./install.sh
assert "test -x $temp/talisman_windows_386.exe" "Should install file with executable mode"
assert_matches "$temp/talisman_windows_386.exe" "$(readlink "$temp/talisman")" "Should create a link"
}

0 comments on commit f9b0c70

Please sign in to comment.