Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions tests/minikube-test-environment.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bats
# SUR-2184: shallow coverage for bash/minikube-test-environment — help output,
# env defaults, unknown-command path, and stubbed external tools (PATH prefix)
# mirroring tests/kind-test-environment.bats hermetic style.

setup() {
load 'helpers.bash'
helpers::isolate_home
STUB_BIN=$(mktemp -d)
MINIKUBE_ARGV_LOG=$(mktemp)
cat >"$STUB_BIN/minikube" <<'STUB_EOF'
#!/usr/bin/env bash
printf '%s\n' "$@" >>"$MINIKUBE_ARGV_LOG"
exit 0
STUB_EOF
for stub_name in kubectl helm jq daemonize; do
printf '%s\n' '#!/usr/bin/env bash' 'exit 0' >"$STUB_BIN/$stub_name"
chmod +x "$STUB_BIN/$stub_name"
done
chmod +x "$STUB_BIN/minikube"
PATH="$STUB_BIN:$PATH"
export STUB_BIN MINIKUBE_ARGV_LOG PATH
MK_ENV="$REPO_ROOT/bash/minikube-test-environment"
}

teardown() {
rm -rf "$STUB_BIN"
rm -f "$MINIKUBE_ARGV_LOG"
}

@test "help lists defaults including MINIKUBE_DRIVER=docker" {
run "$MK_ENV" help
[ "$status" -eq 0 ]
[[ "$output" == *"MINIKUBE_DRIVER=docker"* ]]
[[ "$output" == *"KUBERNETES_VERSION="* ]]
[[ "$output" == *create* ]] && [[ "$output" == *stop* ]] && [[ "$output" == *delete* ]]
}

@test "help reflects MINIKUBE_DRIVER override from the environment" {
run env MINIKUBE_DRIVER=podman "$MK_ENV" help
[ "$status" -eq 0 ]
[[ "$output" == *"MINIKUBE_DRIVER=podman"* ]]
}

@test "bare invocation runs help" {
run "$MK_ENV"
[ "$status" -eq 0 ]
[[ "$output" == *"MINIKUBE_DRIVER=docker"* ]]
}

@test "unknown command exits 1 and prints allowed commands" {
run "$MK_ENV" not-a-command
[ "$status" -eq 1 ]
[[ "$output" == *"Unknown command"* ]]
[[ "$output" == *create* ]] && [[ "$output" == *stop* ]] && [[ "$output" == *delete* ]]
}

@test "stop invokes minikube stop with stubs on PATH" {
run env "PATH=$PATH" "MINIKUBE_ARGV_LOG=$MINIKUBE_ARGV_LOG" "$MK_ENV" stop
[ "$status" -eq 0 ]
grep -qx 'stop' "$MINIKUBE_ARGV_LOG"
}
75 changes: 75 additions & 0 deletions tests/on-change.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bats
# SUR-2179: regression coverage for bash/on-change — options, defaults,
# post-`--` argv to the watched command, and stable error paths (no wall-clock
# assertions on the polling loop itself).

setup() {
load 'helpers.bash'
helpers::isolate_home
ONCHANGE="$REPO_ROOT/bash/on-change"
}

@test "bare invocation prints syntax and exits 1" {
run "$ONCHANGE"
[ "$status" -eq 1 ]
[[ "$output" == *SYNTAX* ]] || [[ "$output" == *OPTIONS* ]]
}

@test "-h prints help and exits 1" {
run "$ONCHANGE" -h
[ "$status" -eq 1 ]
[[ "$output" == *SYNTAX* ]] || [[ "$output" == *OPTIONS* ]]
[[ "$output" == *"-W"* ]] && [[ "$output" == *"-w"* ]] && [[ "$output" == *"-t"* ]]
}

@test "missing WorkingDir surfaces not-found error" {
watch_dir=$(mktemp -d)
run "$ONCHANGE" -W "$watch_dir" -w "/no/such/working/dir" -t 9 -- true
rm -rf "$watch_dir"
[ "$status" -eq 1 ]
[[ "$output" == *"/no/such/working/dir not found"* ]]
}

@test "WorkingDir defaults to WatchDir when -w is omitted" {
watch_dir=$(mktemp -d)
touch "$watch_dir/seed"
argv_log=$(mktemp)
stub_bin=$(mktemp -d)
cat >"$stub_bin/record_argv" <<EOF
#!/usr/bin/env bash
printf '%s\n' "\$@" >>"$argv_log"
EOF
chmod +x "$stub_bin/record_argv"
(
sleep 0.4
echo trigger >>"$watch_dir/marker"
) &
run env PATH="$stub_bin:$PATH" timeout 8s "$ONCHANGE" -W "$watch_dir" -t 1 -v -v -- "$stub_bin/record_argv" ok
[[ "$output" == *"Working directory $watch_dir"* ]]
[[ "$output" == *"Watching directory $watch_dir"* ]]
[[ "$output" == *"Polling interval 1"* ]]
grep -qx 'ok' "$argv_log"
rm -rf "$watch_dir" "$stub_bin"
rm -f "$argv_log"
}

@test "argv after -- is passed unchanged to the invoked command" {
watch_dir=$(mktemp -d)
touch "$watch_dir/seed"
argv_log=$(mktemp)
stub_bin=$(mktemp -d)
cat >"$stub_bin/record_argv" <<EOF
#!/usr/bin/env bash
printf '%s\n' "\$@" >>"$argv_log"
EOF
chmod +x "$stub_bin/record_argv"
(
sleep 0.4
echo trigger >>"$watch_dir/marker"
) &
run env PATH="$stub_bin:$PATH" timeout 8s "$ONCHANGE" -W "$watch_dir" -w "$watch_dir" -t 1 -- "$stub_bin/record_argv" "arg one" "arg two"
grep -qx 'arg one' "$argv_log"
grep -qx 'arg two' "$argv_log"
rm -rf "$watch_dir" "$stub_bin"
rm -f "$argv_log"
}
Loading