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