This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
# system/winboat.sh with a WinBoat compose file and fake docker and podman.
|
||||
# $POLICY is the container's restart policy; empty means there's no container.
|
||||
|
||||
setup() {
|
||||
common_setup
|
||||
WINBOAT="$HOME/.winboat"
|
||||
COMPOSE="$WINBOAT/docker-compose.yml"
|
||||
mkdir -p "$WINBOAT"
|
||||
export POLICY=no
|
||||
stub docker '[ "$1" = inspect ] && { [ -n "$POLICY" ] || exit 1; echo "$POLICY"; }; exit 0'
|
||||
stub podman '[ "$1" = inspect ] && { [ -n "$POLICY" ] || exit 1; echo "$POLICY"; }; exit 0'
|
||||
}
|
||||
|
||||
# compose RESTART: a compose file like WinBoat's with that restart line
|
||||
compose() {
|
||||
printf 'services:\n windows:\n container_name: WinBoat\n stop_grace_period: 120s\n restart: %s\n privileged: true\n' "$1" > "$COMPOSE"
|
||||
}
|
||||
|
||||
@test "winboat.sh does nothing before WinBoat is set up" {
|
||||
rmdir "$WINBOAT"
|
||||
run bash "$REPO/system/winboat.sh"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -z "$output" ]
|
||||
not_called docker
|
||||
}
|
||||
|
||||
@test "winboat.sh changes nothing when Auto Start Container is off" {
|
||||
compose no
|
||||
cp "$COMPOSE" "$BATS_TEST_TMPDIR/before"
|
||||
run bash "$REPO/system/winboat.sh"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -z "$output" ]
|
||||
cmp "$COMPOSE" "$BATS_TEST_TMPDIR/before"
|
||||
uncalled docker update --restart=no WinBoat
|
||||
}
|
||||
|
||||
@test "winboat.sh turns Auto Start Container off in the compose file and on the container" {
|
||||
compose unless-stopped
|
||||
export POLICY=unless-stopped
|
||||
run bash "$REPO/system/winboat.sh"
|
||||
[ "$status" -eq 0 ]
|
||||
grep -qx ' restart: no' "$COMPOSE"
|
||||
grep -qx ' privileged: true' "$COMPOSE"
|
||||
called docker update --restart=no WinBoat
|
||||
}
|
||||
|
||||
@test "winboat.sh accepts a quoted \"no\"" {
|
||||
compose '"no"'
|
||||
run bash "$REPO/system/winboat.sh"
|
||||
[ "$status" -eq 0 ]
|
||||
grep -qx ' restart: "no"' "$COMPOSE"
|
||||
}
|
||||
|
||||
@test "winboat.sh fixes the compose file when the container doesn't exist" {
|
||||
compose always
|
||||
export POLICY=""
|
||||
run bash "$REPO/system/winboat.sh"
|
||||
[ "$status" -eq 0 ]
|
||||
grep -qx ' restart: no' "$COMPOSE"
|
||||
uncalled docker update --restart=no WinBoat
|
||||
}
|
||||
|
||||
@test "winboat.sh uses Podman when WinBoat does" {
|
||||
compose always
|
||||
echo '{"containerRuntime": "Podman"}' > "$WINBOAT/winboat.config.json"
|
||||
export POLICY=always
|
||||
run bash "$REPO/system/winboat.sh"
|
||||
[ "$status" -eq 0 ]
|
||||
called podman update --restart=no WinBoat
|
||||
not_called docker
|
||||
}
|
||||
Reference in New Issue
Block a user