diff --git a/lib/common/tests/health/Makefile.am b/lib/common/tests/health/Makefile.am index 8cee3fefa3..4fa40c475e 100644 --- a/lib/common/tests/health/Makefile.am +++ b/lib/common/tests/health/Makefile.am @@ -1,20 +1,21 @@ # # Copyright 2022 the Pacemaker project contributors # # The version control history for this file may have further details. # # This source code is licensed under the GNU General Public License version 2 # or later (GPLv2+) WITHOUT ANY WARRANTY. # AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include LDADD = $(top_builddir)/lib/common/libcrmcommon.la \ -lcmocka include $(top_srcdir)/mk/tap.mk # Add "_test" to the end of all test program names to simplify .gitignore. -check_PROGRAMS = pcmk__parse_health_strategy_test +check_PROGRAMS = pcmk__parse_health_strategy_test \ + pcmk__validate_health_strategy_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/health/pcmk__validate_health_strategy_test.c b/lib/common/tests/health/pcmk__validate_health_strategy_test.c new file mode 100644 index 0000000000..0e7d8423ea --- /dev/null +++ b/lib/common/tests/health/pcmk__validate_health_strategy_test.c @@ -0,0 +1,49 @@ +/* + * Copyright 2022 the Pacemaker project contributors + * + * The version control history for this file may have further details. + * + * This source code is licensed under the GNU Lesser General Public License + * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + */ + +#include + +#include +#include +#include +#include +#include + +// Test functions + +static void +valid_strategy(void **state) { + assert_true(pcmk__validate_health_strategy("none")); + assert_true(pcmk__validate_health_strategy("None")); + assert_true(pcmk__validate_health_strategy("NONE")); + assert_true(pcmk__validate_health_strategy("NoNe")); + assert_true(pcmk__validate_health_strategy("migrate-on-red")); + assert_true(pcmk__validate_health_strategy("only-green")); + assert_true(pcmk__validate_health_strategy("progressive")); + assert_true(pcmk__validate_health_strategy("custom")); +} + +static void +invalid_strategy(void **state) { + assert_false(pcmk__validate_health_strategy(NULL)); + assert_false(pcmk__validate_health_strategy("")); + assert_false(pcmk__validate_health_strategy("none to speak of")); + assert_false(pcmk__validate_health_strategy("customized")); +} + +int +main(int argc, char **argv) { + const struct CMUnitTest tests[] = { + cmocka_unit_test(valid_strategy), + cmocka_unit_test(invalid_strategy), + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); +}