← Back
Editing: livepatch-kernel-installed.bats
#!/usr/bin/env bats # # Tests for resources/livepatch-kernel-installed. # # Each test copies the script to a temp file and rewrites just the NOTE # variable assignment with sed before executing the copy. setup() { ORIG_SCRIPT="${BATS_TEST_DIRNAME}/../livepatch-kernel-installed" WORKDIR="$(mktemp -d)" SCRIPT="${WORKDIR}/livepatch-kernel-installed" NOTE="${WORKDIR}/canonical-livepatch-kernel-installed" sed \ -e "s#^NOTE=.*#NOTE=\"${NOTE}\"#" \ "$ORIG_SCRIPT" > "$SCRIPT" chmod +x "$SCRIPT" } teardown() { rm -rf "$WORKDIR" } @test "writes the dpkg package name to the note and exits 0" { run env \ DPKG_MAINTSCRIPT_PACKAGE=linux-image-6.8.0-50-generic \ DPKG_MAINTSCRIPT_NAME=postinst \ "$SCRIPT" ignored-kernel-version [ "$status" -eq 0 ] [ -f "$NOTE" ] [ "$(cat "$NOTE")" = "linux-image-6.8.0-50-generic" ] } @test "exits 0 with no output when the note's directory does not exist" { NOTE="${WORKDIR}/nonexistent-dir/note" sed -e "s#^NOTE=.*#NOTE=\"${NOTE}\"#" "$ORIG_SCRIPT" > "$SCRIPT" chmod +x "$SCRIPT" run "$SCRIPT" 6.8.0-50-generic [ "$status" -eq 0 ] [ -z "$output" ] [ ! -f "$NOTE" ] }
Save File
Cancel