diff --git a/lib/common/tests/utils/Makefile.am b/lib/common/tests/utils/Makefile.am index edccf0941a..9bb66f2e55 100644 --- a/lib/common/tests/utils/Makefile.am +++ b/lib/common/tests/utils/Makefile.am @@ -1,28 +1,31 @@ # -# Copyright 2020-2022 the Pacemaker project contributors +# Copyright 2020-2023 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 = \ compare_version_test \ crm_meta_name_test \ crm_meta_value_test \ crm_user_lookup_test \ pcmk_daemon_user_test \ pcmk_str_is_infinity_test \ pcmk_str_is_minus_infinity_test \ - pcmk__getpid_s_test + pcmk__fail_attr_name_test \ + pcmk__failcount_name_test \ + pcmk__getpid_s_test \ + pcmk__lastfailure_name_test if WRAPPABLE_UNAME check_PROGRAMS += pcmk_hostname_test endif TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/utils/pcmk__fail_attr_name_test.c b/lib/common/tests/utils/pcmk__fail_attr_name_test.c new file mode 100644 index 0000000000..c6c25fcbf2 --- /dev/null +++ b/lib/common/tests/utils/pcmk__fail_attr_name_test.c @@ -0,0 +1,36 @@ +/* + * Copyright 2023 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 + +#include + +static void +null_arguments(void **state) +{ + assert_null(pcmk__fail_attr_name(NULL, NULL, NULL, 30000)); + assert_null(pcmk__fail_attr_name(NULL, "myrsc", "monitor", 30000)); + assert_null(pcmk__fail_attr_name("xyz", NULL, "monitor", 30000)); + assert_null(pcmk__fail_attr_name("xyz", "myrsc", NULL, 30000)); +} + +static void +standard_usage(void **state) +{ + char *s = NULL; + + assert_string_equal(pcmk__fail_attr_name("xyz", "myrsc", "monitor", 30000), + "xyz-myrsc#monitor_30000"); + + free(s); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(null_arguments), + cmocka_unit_test(standard_usage)) diff --git a/lib/common/tests/utils/pcmk__failcount_name_test.c b/lib/common/tests/utils/pcmk__failcount_name_test.c new file mode 100644 index 0000000000..a801f4da2f --- /dev/null +++ b/lib/common/tests/utils/pcmk__failcount_name_test.c @@ -0,0 +1,35 @@ +/* + * Copyright 2023 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 + +#include + +static void +null_arguments(void **state) +{ + assert_null(pcmk__failcount_name(NULL, NULL, 30000)); + assert_null(pcmk__failcount_name("myrsc", NULL, 30000)); + assert_null(pcmk__failcount_name(NULL, "monitor", 30000)); +} + +static void +standard_usage(void **state) +{ + char *s = NULL; + + assert_string_equal(pcmk__failcount_name("myrsc", "monitor", 30000), + "fail-count-myrsc#monitor_30000"); + + free(s); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(null_arguments), + cmocka_unit_test(standard_usage)) diff --git a/lib/common/tests/utils/pcmk__lastfailure_name_test.c b/lib/common/tests/utils/pcmk__lastfailure_name_test.c new file mode 100644 index 0000000000..eab01f2fd4 --- /dev/null +++ b/lib/common/tests/utils/pcmk__lastfailure_name_test.c @@ -0,0 +1,35 @@ +/* + * Copyright 2023 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 + +#include + +static void +null_arguments(void **state) +{ + assert_null(pcmk__lastfailure_name(NULL, NULL, 30000)); + assert_null(pcmk__lastfailure_name("myrsc", NULL, 30000)); + assert_null(pcmk__lastfailure_name(NULL, "monitor", 30000)); +} + +static void +standard_usage(void **state) +{ + char *s = NULL; + + assert_string_equal(pcmk__lastfailure_name("myrsc", "monitor", 30000), + "last-failure-myrsc#monitor_30000"); + + free(s); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(null_arguments), + cmocka_unit_test(standard_usage))