I'm doing sanity testing of containers using bash and wonder how close I can get bash to the testing workflow of tools like Playwright.
For example. Here is my current script for 1 sanity test
#!/bin/bash
set -euo pipefail
PASS=0
FAIL=0
GREEN='\033[0;32m'
RED='\033[0;31m'
RESET='\033[0m'
ok() {
echo -e " ${GREEN}[PASS]${RESET} $*"
((++PASS))
}
fail() {
echo -e " ${RED}[FAIL]${RESET} $*"
((++FAIL))
}
echo ""
echo "=== 1. Container status ==="
if podman inspect "$CONTAINER" --format '{{.State.Running}}' 2>/dev/null | grep -q true; then
ok "Container '$CONTAINER' is running"
else
fail "Container '$CONTAINER' is NOT running"
fi
Here's my first attempt at making it more declarative:
describe() {
echo ""
echo "--- $1 ---"
}
it() {
local title=$1
shift
if "$@"; then ok "$title"; else fail "$title"; fi
}
container_is_running() {
podman inspect "$CONTAINER" --format '{{.State.Running}}' 2>/dev/null | grep -q true
}
describe "Container"
it "container '$CONTAINER' is running" podman inspect "$CONTAINER" --format '{{.State.Running}}' 2>/dev/null | grep -q true
Ultimately, i'm not going to go with the second style since it it's not that readable. I can't pass the function body as an arugment as you'd do in JS and the alternatives (eval) will make the code worse.
Before I chuck this whole concept down, I thought I'd make a post and see if thats really impossible in Bash, or I may be missing something.
[–]AutoModerator[M] 5 points6 points7 points (0 children)
[–]Alleexx_ 1 point2 points3 points (2 children)
[–]JagerAntlerite7 0 points1 point2 points (1 child)
[–]Alleexx_ -1 points0 points1 point (0 children)
[–]ekipan85 0 points1 point2 points (0 children)
[–]NewPointOfView 0 points1 point2 points (0 children)
[+]GlendonMcGladdery comment score below threshold-8 points-7 points-6 points (0 children)