pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
crm_meta_value_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2022-2024 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU General Public License version 2
7 * or later (GPLv2+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
13#include <crm/common/xml.h>
14
15#include <glib.h>
16
17static void
18empty_params(void **state)
19{
20 GHashTable *tbl = pcmk__strkey_table(free, free);
21
22 assert_null(crm_meta_value(NULL, NULL));
23 assert_null(crm_meta_value(tbl, NULL));
24
25 g_hash_table_destroy(tbl);
26}
27
28static void
29key_not_in_table(void **state)
30{
31 GHashTable *tbl = pcmk__strkey_table(free, free);
32
33 assert_null(crm_meta_value(tbl, PCMK_META_NOTIFY));
35
36 g_hash_table_destroy(tbl);
37}
38
39static void
40key_in_table(void **state)
41{
42 GHashTable *tbl = pcmk__strkey_table(free, free);
43
44 g_hash_table_insert(tbl, crm_meta_name(PCMK_META_NOTIFY), strdup("1"));
45 g_hash_table_insert(tbl, crm_meta_name(PCMK_META_RESOURCE_STICKINESS),
46 strdup("2"));
47
48 assert_string_equal(crm_meta_value(tbl, PCMK_META_NOTIFY), "1");
49 assert_string_equal(crm_meta_value(tbl, PCMK_META_RESOURCE_STICKINESS),
50 "2");
51
52 g_hash_table_destroy(tbl);
53}
54
55PCMK__UNIT_TEST(NULL, NULL,
56 cmocka_unit_test(empty_params),
57 cmocka_unit_test(key_not_in_table),
58 cmocka_unit_test(key_in_table))
const char * crm_meta_value(GHashTable *hash, const char *field)
Get the value of a meta-attribute.
Definition nvpair.c:553
char * crm_meta_name(const char *field)
Get the environment variable equivalent of a meta-attribute name.
Definition nvpair.c:525
#define PCMK_META_RESOURCE_STICKINESS
Definition options.h:112
#define PCMK_META_NOTIFY
Definition options.h:98
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
Definition strings.c:685
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
Wrappers for and extensions to libxml2.