Skip to content

Commit

Permalink
tests: account for system and vendor scripts
Browse files Browse the repository at this point in the history
Amend the existing scripts to verify the expected behaviors for
greenboot check|green|red invocations when scripts are provided in
/usr/lib/greenboot/ and /etc/greenboot.

This slightly extends the checks by verifying the test scritps from both
vendor and system-specific sources are called during tests of greenboot
check, red and green commands.

Signed-off-by: Eric Chanudet <[email protected]>
  • Loading branch information
eric-ch authored and nullr0ute committed Jun 5, 2023
1 parent 12b48ec commit 16ab67b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
6 changes: 4 additions & 2 deletions tests/common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ GRUB2_EDITENV=/usr/bin/grub2-editenv

GREENBOOT_DEFAULT_CHECK_PATH="$GREENBOOT_USR_LIB_ROOT_PATH/check"
GREENBOOT_ETC_CHECK_PATH="$GREENBOOT_ETC_ROOT_PATH/check"
GREENBOOT_GREEN_PATH="$GREENBOOT_ETC_ROOT_PATH/green.d"
GREENBOOT_RED_PATH="$GREENBOOT_ETC_ROOT_PATH/red.d"
GREENBOOT_DEFAULT_GREEN_PATH="$GREENBOOT_USR_LIB_ROOT_PATH/green.d"
GREENBOOT_DEFAULT_RED_PATH="$GREENBOOT_USR_LIB_ROOT_PATH/red.d"
GREENBOOT_ETC_GREEN_PATH="$GREENBOOT_ETC_ROOT_PATH/green.d"
GREENBOOT_ETC_RED_PATH="$GREENBOOT_ETC_ROOT_PATH/red.d"
7 changes: 7 additions & 0 deletions tests/greenboot_check_fail_required.bats
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
load common.bash

function setup() {
mkdir -p $GREENBOOT_DEFAULT_CHECK_PATH $GREENBOOT_ETC_CHECK_PATH
cp testing_files/10_failing_check.sh $GREENBOOT_DEFAULT_CHECK_PATH/required.d/10_failing_check.sh
cp testing_files/10_failing_check.sh $GREENBOOT_DEFAULT_CHECK_PATH/required.d/20_failing_check.sh
cp testing_files/10_failing_check.sh $GREENBOOT_ETC_CHECK_PATH/required.d/30_failing_check.sh
cp testing_files/10_failing_check.sh $GREENBOOT_ETC_CHECK_PATH/required.d/40_failing_check.sh
}

@test "Test greenboot check with required scripts failing" {
Expand All @@ -14,9 +17,13 @@ function setup() {
run $GREENBOOT_BIN_PATH check
[[ "$output" == *"10_failing_check"* ]]
[[ "$output" == *"20_failing_check"* ]]
[[ "$output" == *"30_failing_check"* ]]
[[ "$output" == *"40_failing_check"* ]]
}

function teardown() {
rm $GREENBOOT_DEFAULT_CHECK_PATH/required.d/10_failing_check.sh
rm $GREENBOOT_DEFAULT_CHECK_PATH/required.d/20_failing_check.sh
rm $GREENBOOT_ETC_CHECK_PATH/required.d/30_failing_check.sh
rm $GREENBOOT_ETC_CHECK_PATH/required.d/40_failing_check.sh
}
8 changes: 7 additions & 1 deletion tests/greenboot_check_fail_wanted.bats
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
load common.bash

function setup() {
mkdir -p $GREENBOOT_DEFAULT_CHECK_PATH $GREENBOOT_ETC_CHECK_PATH

# 02_watchdog.sh can't be checked within the container at the moment
# due to rpm-ostree, hence moving it out of the required directory
# for this test
mv $GREENBOOT_DEFAULT_CHECK_PATH/required.d/02_watchdog.sh /tmp/02_watchdog.sh

cp testing_files/10_failing_check.sh $GREENBOOT_DEFAULT_CHECK_PATH/wanted.d/
cp testing_files/10_failing_check.sh $GREENBOOT_DEFAULT_CHECK_PATH/wanted.d/10_failing_check.sh
cp testing_files/10_failing_check.sh $GREENBOOT_ETC_CHECK_PATH/wanted.d/20_failing_check.sh
}

@test "Test greenboot check with wanted scripts failing" {
run $GREENBOOT_BIN_PATH check
[ "$status" -eq 0 ]
[[ "$output" == *"10_failing_check.sh"* ]]
[[ "$output" == *"20_failing_check.sh"* ]]
}

function teardown() {
rm $GREENBOOT_DEFAULT_CHECK_PATH/wanted.d/10_failing_check.sh
rm $GREENBOOT_ETC_CHECK_PATH/wanted.d/20_failing_check.sh
mv /tmp/02_watchdog.sh $GREENBOOT_DEFAULT_CHECK_PATH/required.d/02_watchdog.sh
}
10 changes: 7 additions & 3 deletions tests/greenboot_green.bats
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
load common.bash

function setup() {
mkdir -p $GREENBOOT_GREEN_PATH
cp testing_files/20_green_script.sh $GREENBOOT_GREEN_PATH/
mkdir -p $GREENBOOT_DEFAULT_GREEN_PATH $GREENBOOT_ETC_GREEN_PATH
cp testing_files/20_green_script.sh $GREENBOOT_DEFAULT_GREEN_PATH/20_green_script.sh
cp testing_files/20_green_script.sh $GREENBOOT_ETC_GREEN_PATH/30_green_script.sh
}

@test "Test greenboot green command" {
run $GREENBOOT_BIN_PATH green
[ "$status" -eq 0 ]
[[ "$output" == *"Health Check SUCCESS"* ]]
[[ "$output" == *"20_green_script.sh"* ]]
[[ "$output" == *"30_green_script.sh"* ]]
}

function teardown() {
rm $GREENBOOT_GREEN_PATH/20_green_script.sh
rm $GREENBOOT_DEFAULT_GREEN_PATH/20_green_script.sh
rm $GREENBOOT_ETC_GREEN_PATH/30_green_script.sh
}
10 changes: 7 additions & 3 deletions tests/greenboot_red.bats
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
load common.bash

function setup() {
mkdir -p $GREENBOOT_RED_PATH
cp testing_files/30_red_script.sh $GREENBOOT_RED_PATH/
mkdir -p $GREENBOOT_DEFAULT_RED_PATH $GREENBOOT_ETC_RED_PATH
cp testing_files/30_red_script.sh $GREENBOOT_DEFAULT_RED_PATH/30_red_script.sh
cp testing_files/30_red_script.sh $GREENBOOT_ETC_RED_PATH/40_red_script.sh
}

@test "Test greenboot red command" {
run $GREENBOOT_BIN_PATH red
[ "$status" -eq 0 ]
[[ "$output" == *"Health Check FAILURE"* ]]
[[ "$output" == *"30_red_script.sh"* ]]
[[ "$output" == *"40_red_script.sh"* ]]
}

function teardown() {
rm $GREENBOOT_RED_PATH/30_red_script.sh
rm $GREENBOOT_DEFAULT_RED_PATH/30_red_script.sh
rm $GREENBOOT_ETC_RED_PATH/40_red_script.sh
}

0 comments on commit 16ab67b

Please sign in to comment.