Tests cover skip-already-processed logic, cleanup, idempotency, and the config.sh single-source-of-truth invariant. bats-core, bats-assert, and bats-support added as submodules under tests/libs/.
51 lines
1.4 KiB
Bash
51 lines
1.4 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load 'libs/bats-support/load'
|
|
load 'libs/bats-assert/load'
|
|
load 'helpers/common'
|
|
|
|
SCRIPT="$REPO_ROOT/images_resize.sh"
|
|
|
|
setup() {
|
|
setup_mock_env
|
|
}
|
|
|
|
teardown() {
|
|
teardown_mock_env
|
|
}
|
|
|
|
@test "skips JPEG that already has the processing comment" {
|
|
cp "$FIXTURES/processed.jpg" "$TEST_WORKDIR/img.jpg"
|
|
run bash -c "cd '$TEST_WORKDIR' && '$SCRIPT'"
|
|
assert_success
|
|
assert_output --partial "Skipping"
|
|
assert_output --partial "already processed"
|
|
}
|
|
|
|
@test "processes JPEG without the comment and embeds it" {
|
|
cp "$FIXTURES/unprocessed.jpg" "$TEST_WORKDIR/img.jpg"
|
|
run bash -c "cd '$TEST_WORKDIR' && '$SCRIPT'"
|
|
assert_success
|
|
assert_output --partial "Resized"
|
|
local comment
|
|
comment=$(identify -format "%c" "$TEST_WORKDIR/img.jpg")
|
|
assert_equal "$comment" "magick:resize=8mp,quality=85,sampling=4:2:0"
|
|
}
|
|
|
|
@test "re-running skips a JPEG that was just processed" {
|
|
cp "$FIXTURES/unprocessed.jpg" "$TEST_WORKDIR/img.jpg"
|
|
bash -c "cd '$TEST_WORKDIR' && '$SCRIPT'" >/dev/null 2>&1
|
|
run bash -c "cd '$TEST_WORKDIR' && '$SCRIPT'"
|
|
assert_success
|
|
assert_output --partial "Skipping"
|
|
}
|
|
|
|
@test "processes only JPEGs, ignores other file types" {
|
|
cp "$FIXTURES/unprocessed.jpg" "$TEST_WORKDIR/img.jpg"
|
|
echo "not an image" > "$TEST_WORKDIR/readme.txt"
|
|
run bash -c "cd '$TEST_WORKDIR' && '$SCRIPT'"
|
|
assert_success
|
|
assert_output --partial "Resized"
|
|
refute_output --partial "readme.txt"
|
|
}
|