|
| 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