#!/usr/bin/env bats load 'libs/bats-support/load' load 'libs/bats-assert/load' load 'helpers/common' SCRIPT="$REPO_ROOT/zip_images_resize.sh" setup() { setup_mock_env } teardown() { teardown_mock_env } @test "prints usage and exits 1 when no arguments given" { run "$SCRIPT" assert_failure assert_output --partial "Usage:" } @test "skips ZIP whose first JPEG already has the processing comment" { make_zip "$TEST_WORKDIR/archive.zip" "$FIXTURES/processed.jpg" run "$SCRIPT" "$TEST_WORKDIR/archive.zip" assert_success assert_output --partial "Skipping" assert_output --partial "already processed" } @test "does not skip ZIP whose JPEG has no processing comment" { make_zip "$TEST_WORKDIR/archive.zip" "$FIXTURES/unprocessed.jpg" run "$SCRIPT" "$TEST_WORKDIR/archive.zip" assert_success refute_output --partial "Skipping" assert_output --partial "Resized" } @test "processed ZIP is unchanged on disk after skip" { make_zip "$TEST_WORKDIR/archive.zip" "$FIXTURES/processed.jpg" local before_size after_size before_size=$(stat -c%s "$TEST_WORKDIR/archive.zip") run "$SCRIPT" "$TEST_WORKDIR/archive.zip" after_size=$(stat -c%s "$TEST_WORKDIR/archive.zip") assert_equal "$before_size" "$after_size" } @test "after processing, re-running skips the same ZIP" { make_zip "$TEST_WORKDIR/archive.zip" "$FIXTURES/unprocessed.jpg" "$SCRIPT" "$TEST_WORKDIR/archive.zip" >/dev/null 2>&1 run "$SCRIPT" "$TEST_WORKDIR/archive.zip" assert_success assert_output --partial "Skipping" } @test "ZIP with no JPEGs inside is processed without error" { echo "not an image" > "$TEST_WORKDIR/readme.txt" (cd "$TEST_WORKDIR" && zip -q archive.zip readme.txt) run "$SCRIPT" "$TEST_WORKDIR/archive.zip" assert_success refute_output --partial "Skipping" refute_output --partial "Error:" } @test "no temp files left in /dev/shm after processing" { make_zip "$TEST_WORKDIR/archive.zip" "$FIXTURES/unprocessed.jpg" local before after before=$(find /dev/shm -maxdepth 1 -name 'tmp.*' | sort) run "$SCRIPT" "$TEST_WORKDIR/archive.zip" after=$(find /dev/shm -maxdepth 1 -name 'tmp.*' | sort) assert_equal "$before" "$after" } @test "no temp files left in /dev/shm after skipping" { make_zip "$TEST_WORKDIR/archive.zip" "$FIXTURES/processed.jpg" local before after before=$(find /dev/shm -maxdepth 1 -name 'tmp.*' | sort) run "$SCRIPT" "$TEST_WORKDIR/archive.zip" after=$(find /dev/shm -maxdepth 1 -name 'tmp.*' | sort) assert_equal "$before" "$after" } @test "processes multiple ZIPs, skipping already-processed ones" { make_zip "$TEST_WORKDIR/done.zip" "$FIXTURES/processed.jpg" make_zip "$TEST_WORKDIR/todo.zip" "$FIXTURES/unprocessed.jpg" run "$SCRIPT" "$TEST_WORKDIR/done.zip" "$TEST_WORKDIR/todo.zip" assert_success assert_output --partial "Skipping" assert_output --partial "Resized" }