diff options
Diffstat (limited to 'lib/common/tests/health')
-rw-r--r-- | lib/common/tests/health/Makefile.am | 17 | ||||
-rw-r--r-- | lib/common/tests/health/pcmk__parse_health_strategy_test.c | 56 | ||||
-rw-r--r-- | lib/common/tests/health/pcmk__validate_health_strategy_test.c | 38 |
3 files changed, 111 insertions, 0 deletions
diff --git a/lib/common/tests/health/Makefile.am b/lib/common/tests/health/Makefile.am new file mode 100644 index 0000000..ad2a2da --- /dev/null +++ b/lib/common/tests/health/Makefile.am @@ -0,0 +1,17 @@ +# +# 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. +# + +include $(top_srcdir)/mk/tap.mk +include $(top_srcdir)/mk/unittest.mk + +# Add "_test" to the end of all test program names to simplify .gitignore. +check_PROGRAMS = pcmk__parse_health_strategy_test \ + pcmk__validate_health_strategy_test + +TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/health/pcmk__parse_health_strategy_test.c b/lib/common/tests/health/pcmk__parse_health_strategy_test.c new file mode 100644 index 0000000..28cc702 --- /dev/null +++ b/lib/common/tests/health/pcmk__parse_health_strategy_test.c @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#include <crm_internal.h> + +#include <crm/common/unittest_internal.h> + +static void +valid(void **state) { + assert_int_equal(pcmk__parse_health_strategy(NULL), + pcmk__health_strategy_none); + + assert_int_equal(pcmk__parse_health_strategy("none"), + pcmk__health_strategy_none); + + assert_int_equal(pcmk__parse_health_strategy("NONE"), + pcmk__health_strategy_none); + + assert_int_equal(pcmk__parse_health_strategy("None"), + pcmk__health_strategy_none); + + assert_int_equal(pcmk__parse_health_strategy("nOnE"), + pcmk__health_strategy_none); + + assert_int_equal(pcmk__parse_health_strategy("migrate-on-red"), + pcmk__health_strategy_no_red); + + assert_int_equal(pcmk__parse_health_strategy("only-green"), + pcmk__health_strategy_only_green); + + assert_int_equal(pcmk__parse_health_strategy("progressive"), + pcmk__health_strategy_progressive); + + assert_int_equal(pcmk__parse_health_strategy("custom"), + pcmk__health_strategy_custom); +} + +static void +invalid(void **state) { + assert_int_equal(pcmk__parse_health_strategy("foo"), + pcmk__health_strategy_none); + assert_int_equal(pcmk__parse_health_strategy("custom1"), + pcmk__health_strategy_none); + assert_int_equal(pcmk__parse_health_strategy("not-only-green-here"), + pcmk__health_strategy_none); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(valid), + cmocka_unit_test(invalid)) 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 0000000..c7c60aa --- /dev/null +++ b/lib/common/tests/health/pcmk__validate_health_strategy_test.c @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#include <crm_internal.h> + +#include <crm/common/unittest_internal.h> + +// 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")); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(valid_strategy), + cmocka_unit_test(invalid_strategy)) |