diff options
| author | Danilo M. <danix@danix.xyz> | 2026-07-13 12:04:03 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-07-13 12:04:03 +0200 |
| commit | 3e79c1b392e39a929fe6ab3cad569b5b7d97d97b (patch) | |
| tree | d7d062288f999109b8d9ed3a8f9ec2ec825a051c /.extras/image-builder | |
| parent | 8b4c556ff02aa4a5e200941e4fbded2eb4175183 (diff) | |
| download | sbo-slackbuilds-3e79c1b392e39a929fe6ab3cad569b5b7d97d97b.tar.gz sbo-slackbuilds-3e79c1b392e39a929fe6ab3cad569b5b7d97d97b.zip | |
image-builder: lib.sh self-check
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to '.extras/image-builder')
| -rw-r--r-- | .extras/image-builder/test-image-builder.sh | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/.extras/image-builder/test-image-builder.sh b/.extras/image-builder/test-image-builder.sh new file mode 100644 index 0000000..39d3f1c --- /dev/null +++ b/.extras/image-builder/test-image-builder.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# Assert-based self-check for lib.sh pure logic. No docker, no network. +# Run: bash .extras/image-builder/test-image-builder.sh +set -u +cd "$(dirname "$0")" +source ./lib.sh + +pass=0 fail=0 +check() { # DESC EXPECTED ACTUAL + if [[ "$2" == "$3" ]]; then pass=$((pass+1)); + else fail=$((fail+1)); echo "FAIL: $1"; echo " expected: [$2]"; echo " actual: [$3]"; fi +} +check_rc() { # DESC EXPECTED_RC ACTUAL_RC + if [[ "$2" == "$3" ]]; then pass=$((pass+1)); + else fail=$((fail+1)); echo "FAIL: $1 (rc expected $2 got $3)"; fi +} + +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT + +# --- mirror_path --- +check "mirror_path trailing slash" \ + "file:///mnt/nas/slackware64-current/PACKAGES.TXT" \ + "$(mirror_path 'file:///mnt/nas/' 'slackware64-current/PACKAGES.TXT')" +check "mirror_path no trailing slash" \ + "file:///mnt/nas/x/y" "$(mirror_path 'file:///mnt/nas' '/x/y')" + +# --- is_local_mirror --- +is_local_mirror "file:///mnt/nas"; check_rc "is_local file://" 0 $? +is_local_mirror "/mnt/nas"; check_rc "is_local bare abs" 0 $? +is_local_mirror "https://x/y"; check_rc "is_local https" 1 $? + +# --- strip_scheme --- +check "strip_scheme file://" "/mnt/nas" "$(strip_scheme 'file:///mnt/nas')" +check "strip_scheme bare" "/mnt/nas" "$(strip_scheme '/mnt/nas')" + +# --- fetch: local file resolves --- +echo hello > "$tmp/src.txt" +fetch "file://$tmp/src.txt" "$tmp/dst.txt"; check_rc "fetch local ok" 0 $? +check "fetch local content" "hello" "$(cat "$tmp/dst.txt" 2>/dev/null)" + +# --- fetch: missing local file errors --- +fetch "file://$tmp/nope.txt" "$tmp/x.txt"; check_rc "fetch local missing" 1 $? + +# --- txz_hash: stable + content-sensitive --- +mkdir -p "$tmp/pkgs" +printf a > "$tmp/pkgs/sbopkg-1.txz" +printf b > "$tmp/pkgs/tools-1.txz" +h1="$(txz_hash "$tmp/pkgs")" +h2="$(txz_hash "$tmp/pkgs")" +check "txz_hash stable" "$h1" "$h2" +printf c > "$tmp/pkgs/tools-1.txz" # change content +h3="$(txz_hash "$tmp/pkgs")" +check_rc "txz_hash changes on content" 0 "$([[ "$h1" != "$h3" ]] && echo 0 || echo 1)" +check "txz_hash empty dir" "" "$(txz_hash "$tmp/empty-nope")" + +# --- require_mount: missing mount errors (subshell to catch _err exit) --- +MIRROR="file://$tmp/no-such-root" +( require_mount current ) 2>/dev/null; check_rc "require_mount missing" 1 $? +mkdir -p "$tmp/mnt/slackware64-current" +MIRROR="file://$tmp/mnt" +( require_mount current ) 2>/dev/null; check_rc "require_mount present" 0 $? +MIRROR="https://example/x" +( require_mount current ) 2>/dev/null; check_rc "require_mount http skips" 0 $? + +echo "----" +echo "PASS: $pass FAIL: $fail" +[[ "$fail" -eq 0 ]] |
