diff --git a/src/autoupdate.c b/src/autoupdate.c index e409cfb9..48906294 100644 --- a/src/autoupdate.c +++ b/src/autoupdate.c @@ -161,7 +161,7 @@ enum swupd_code autoupdate_main(int argc, char **argv) rc1 = systemctl_cmd_path(globals.path_prefix, "is-enabled", "swupd-update.service", NULL); rc2 = systemctl_cmd_path(globals.path_prefix, "is-active", "swupd-update.timer", NULL); if (rc1 == SWUPD_OK && rc2 == SWUPD_OK) { - print("Enabled\n"); + info("Enabled\n"); return SWUPD_OK; } else if (rc1 >= STATUS_UNKNOWN || rc2 >= STATUS_UNKNOWN) { /* systemctl returns 1,2, or 3 when program dead or not running */ @@ -173,7 +173,7 @@ enum swupd_code autoupdate_main(int argc, char **argv) error("Unable to determine autoupdate status with --path option\n"); return SWUPD_SUBPROCESS_ERROR; } else { - print("Disabled\n"); + info("Disabled\n"); return SWUPD_NO; } } diff --git a/test/functional/api/api-autoupdate.bats b/test/functional/api/api-autoupdate.bats new file mode 100755 index 00000000..ed3dde89 --- /dev/null +++ b/test/functional/api/api-autoupdate.bats @@ -0,0 +1,51 @@ +#!/usr/bin/env bats + +# Author: Castulo Martinez +# Email: castulo.martinez@intel.com + +load "../testlib" + +test_setup() { + + create_test_environment "$TEST_NAME" + sudo mkdir -p "$PATH_PREFIX"/etc/systemd/system + +} + +@test "API004: autoupdate" { + + run sudo sh -c "$SWUPD autoupdate $SWUPD_OPTS --quiet" + + assert_status_is "$SWUPD_NO" + assert_output_is_empty + +} + +@test "API005: autoupdate --enable" { + + # create mask files manually + sudo ln -s /dev/null "$PATH_PREFIX"/etc/systemd/system/swupd-update.service + sudo ln -s /dev/null "$PATH_PREFIX"/etc/systemd/system/swupd-update.timer + + run sudo sh -c "$SWUPD autoupdate $SWUPD_OPTS --enable --quiet" + + assert_status_is "$SWUPD_OK" + assert_output_is_empty + # check mask files don't exist + assert_file_not_exists "$PATH_PREFIX"/etc/systemd/system/swupd-update.service + assert_file_not_exists "$PATH_PREFIX"/etc/systemd/system/swupd-update.timer + +} + +@test "API006: autoupdate --disable" { + + run sudo sh -c "$SWUPD autoupdate $SWUPD_OPTS --disable --quiet" + + assert_status_is "$SWUPD_OK" + assert_output_is_empty + # check mask files don't exist + assert_symlink_exists "$PATH_PREFIX"/etc/systemd/system/swupd-update.service + assert_symlink_exists "$PATH_PREFIX"/etc/systemd/system/swupd-update.timer + +} + diff --git a/test/functional/testlib.bash b/test/functional/testlib.bash index cd7d2590..25774266 100644 --- a/test/functional/testlib.bash +++ b/test/functional/testlib.bash @@ -4601,6 +4601,15 @@ assert_regex_is_not_output() { # assertion } +assert_output_is_empty() { # assertion + + if [ -n "$output" ]; then + print_assert_failure "The output was expected to be empty and it is not" + return 1 + fi + +} + assert_equal() { # assertion local val1=$1