|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +SCRIPT_NAME="install.sh" |
| 4 | +SCRIPT="$BATS_TEST_DIRNAME/../../$SCRIPT_NAME" |
| 5 | + |
| 6 | +function should-use-deb() { |
| 7 | + DISTRO=$1 ARCH=$2 OS=linux run "$SCRIPT" --dry-run |
| 8 | + [ "$status" -eq 0 ] |
| 9 | + echo "${lines[1]}" |
| 10 | + [[ "${lines[1]}" = "Installing v"*" of the $2 deb package from GitHub." ]] |
| 11 | +} |
| 12 | + |
| 13 | +function should-use-rpm() { |
| 14 | + DISTRO=$1 ARCH=$2 OS=linux run "$SCRIPT" --dry-run |
| 15 | + [ "$status" -eq 0 ] |
| 16 | + [[ "${lines[1]}" = "Installing v"*" of the $2 rpm package from GitHub." ]] |
| 17 | +} |
| 18 | + |
| 19 | +function should-fallback-npm() { |
| 20 | + DISTRO=$1 ARCH=$2 OS=linux run "$SCRIPT" --dry-run |
| 21 | + [ "$status" -eq 0 ] |
| 22 | + [ "${lines[1]}" = "No standalone releases for $2." ] |
| 23 | + [ "${lines[2]}" = "Falling back to installation from npm." ] |
| 24 | + [ "${lines[3]}" = "Installing latest from npm." ] |
| 25 | +} |
| 26 | + |
| 27 | +function should-use-npm() { |
| 28 | + DISTRO=$1 ARCH=$2 OS=linux run "$SCRIPT" --dry-run |
| 29 | + [ "$status" -eq 0 ] |
| 30 | + [[ "${lines[1]}" = "Installing latest from npm." ]] |
| 31 | +} |
| 32 | + |
| 33 | +function should-use-aur() { |
| 34 | + DISTRO=$1 ARCH=$2 OS=linux run "$SCRIPT" --dry-run |
| 35 | + [ "$status" -eq 0 ] |
| 36 | + [[ "${lines[1]}" = "Installing latest from the AUR." ]] |
| 37 | +} |
| 38 | + |
| 39 | +function should-fallback-npm-brew() { |
| 40 | + BREW_PATH= OS=macos ARCH=$1 run "$SCRIPT" --dry-run |
| 41 | + [ "$status" -eq 0 ] |
| 42 | + [ "${lines[1]}" = "Homebrew not installed." ] |
| 43 | + [ "${lines[2]}" = "Falling back to standalone installation." ] |
| 44 | + [ "${lines[3]}" = "No standalone releases for $1." ] |
| 45 | + [ "${lines[4]}" = "Falling back to installation from npm." ] |
| 46 | + [ "${lines[5]}" = "Installing latest from npm." ] |
| 47 | +} |
| 48 | + |
| 49 | +function should-use-brew() { |
| 50 | + BREW_PATH=brew OS=macos ARCH=$1 run "$SCRIPT" --dry-run |
| 51 | + [ "$status" -eq 0 ] |
| 52 | + [[ "${lines[1]}" = "Installing latest from Homebrew." ]] |
| 53 | +} |
| 54 | + |
| 55 | +@test "$SCRIPT_NAME: usage with --help" { |
| 56 | + run "$SCRIPT" --help |
| 57 | + [ "$status" -eq 0 ] |
| 58 | + [ "${lines[0]}" = "Installs code-server." ] |
| 59 | +} |
| 60 | + |
| 61 | +# These use the deb but fall back to npm for unsupported arch. |
| 62 | +@test "$SCRIPT_NAME: debian arm64" { |
| 63 | + should-use-deb "debian" "arm64" |
| 64 | +} |
| 65 | +@test "$SCRIPT_NAME: debian amd64" { |
| 66 | + should-use-deb "debian" "amd64" |
| 67 | +} |
| 68 | +@test "$SCRIPT_NAME: debian i386" { |
| 69 | + should-fallback-npm "debian" "i386" |
| 70 | +} |
| 71 | + |
| 72 | +# These use the rpm but fall back to npm for unsupported arch. |
| 73 | +@test "$SCRIPT_NAME: fedora arm64" { |
| 74 | + should-use-rpm "fedora" "arm64" |
| 75 | +} |
| 76 | +@test "$SCRIPT_NAME: fedora amd64" { |
| 77 | + should-use-rpm "fedora" "amd64" |
| 78 | +} |
| 79 | +@test "$SCRIPT_NAME: fedora i386" { |
| 80 | + should-fallback-npm "fedora" "i386" |
| 81 | +} |
| 82 | + |
| 83 | +# These always use npm regardless of the arch. |
| 84 | +@test "$SCRIPT_NAME: alpine arm64" { |
| 85 | + should-use-npm "alpine" "arm64" |
| 86 | +} |
| 87 | +@test "$SCRIPT_NAME: alpine amd64" { |
| 88 | + should-use-npm "alpine" "amd64" |
| 89 | +} |
| 90 | +@test "$SCRIPT_NAME: alpine i386" { |
| 91 | + should-use-npm "alpine" "i386" |
| 92 | +} |
| 93 | + |
| 94 | +@test "$SCRIPT_NAME: freebsd arm64" { |
| 95 | + should-use-npm "freebsd" "arm64" |
| 96 | +} |
| 97 | +@test "$SCRIPT_NAME: freebsd amd64" { |
| 98 | + should-use-npm "freebsd" "amd64" |
| 99 | +} |
| 100 | +@test "$SCRIPT_NAME: freebsd i386" { |
| 101 | + should-use-npm "freebsd" "i386" |
| 102 | +} |
| 103 | + |
| 104 | +# Arch Linux uses AUR but falls back to npm for unsuppported arch. |
| 105 | +@test "$SCRIPT_NAME: arch arm64" { |
| 106 | + should-use-aur "arch" "arm64" |
| 107 | +} |
| 108 | +@test "$SCRIPT_NAME: arch amd64" { |
| 109 | + should-use-aur "arch" "amd64" |
| 110 | +} |
| 111 | +@test "$SCRIPT_NAME: arch i386" { |
| 112 | + should-fallback-npm "arch" "i386" |
| 113 | +} |
| 114 | + |
| 115 | +# macOS use homebrew but falls back to standalone when brew is unavailable and |
| 116 | +# to npm for unsupported arch. |
| 117 | +@test "$SCRIPT_NAME: macos arm64 (no brew)" { |
| 118 | + should-fallback-npm-brew "arm64" |
| 119 | +} |
| 120 | +@test "$SCRIPT_NAME: macos amd64 (no brew)" { |
| 121 | + BREW_PATH= OS=macos ARCH=amd64 run "$SCRIPT" --dry-run |
| 122 | + [ "$status" -eq 0 ] |
| 123 | + [ "${lines[1]}" = "Homebrew not installed." ] |
| 124 | + [ "${lines[2]}" = "Falling back to standalone installation." ] |
| 125 | + [[ "${lines[3]}" = "Installing v"*" of the amd64 release from GitHub." ]] |
| 126 | +} |
| 127 | +@test "$SCRIPT_NAME: macos i386 (no brew)" { |
| 128 | + should-fallback-npm-brew "i386" |
| 129 | +} |
| 130 | + |
| 131 | +@test "$SCRIPT_NAME: macos arm64 (brew)" { |
| 132 | + should-use-brew "arm64" |
| 133 | +} |
| 134 | +@test "$SCRIPT_NAME: macos amd64 (brew)" { |
| 135 | + should-use-brew "amd64" |
| 136 | +} |
| 137 | +@test "$SCRIPT_NAME: macos i386 (brew)" { |
| 138 | + should-use-brew "i386" |
| 139 | +} |
0 commit comments