pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
pcmk__find_x_0_schema_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2023-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
12#include <stdio.h> // NULL, rename()
13#include <stdlib.h> // setenv(), unsetenv()
14#include <glib.h>
15
17#include "crmcommon_private.h"
18
19#define SCHEMA_PREFIX PCMK__TEST_SCHEMA_DIR "/find_x_0/pacemaker-"
20
21static int
22setup(void **state)
23{
24 // Use a unique schema directory so we can move files around
25 setenv("PCMK_schema_directory", PCMK__TEST_SCHEMA_DIR "/find_x_0", 1);
26 return 0;
27}
28
29static int
30teardown(void **state)
31{
32 unsetenv("PCMK_schema_directory");
33 return 0;
34}
35
36static void
37assert_schema_0(int schema_index, const char *schema_name)
38{
39 GList *entry = NULL;
40 pcmk__schema_t *schema = NULL;
41
42 entry = pcmk__find_x_0_schema();
43 assert_non_null(entry);
44
45 schema = entry->data;
46 assert_non_null(schema);
47
48 assert_int_equal(schema->schema_index, schema_index);
49 assert_string_equal(schema->name, schema_name);
50}
51
52static void
53last_is_0(void **state)
54{
55 /* This loads all the schemas normally linked for unit testing, so we have
56 * many 1.x and 2.x schemas and a single pacemaker-3.0 schema at index 14.
57 */
59 assert_schema_0(14, "pacemaker-3.0");
61}
62
63static void
64last_is_not_0(void **state)
65{
66 /* Disable the pacemaker-3.0 schema, so we now should get pacemaker-2.0 at
67 * index 3.
68 */
69 assert_int_equal(0, rename(SCHEMA_PREFIX "3.0.rng",
70 SCHEMA_PREFIX "3.0.bak"));
72 assert_schema_0(3, "pacemaker-2.0");
73 assert_int_equal(0, rename(SCHEMA_PREFIX "3.0.bak",
74 SCHEMA_PREFIX "3.0.rng"));
76}
77
78static void
79schema_0_missing(void **state)
80{
81 /* Disable the pacemaker-3.0 and pacemaker-2.0 schemas, so we now should get
82 * pacemaker-2.1 at index 3.
83 */
84 assert_int_equal(0, rename(SCHEMA_PREFIX "3.0.rng",
85 SCHEMA_PREFIX "3.0.bak"));
86 assert_int_equal(0, rename(SCHEMA_PREFIX "2.0.rng",
87 SCHEMA_PREFIX "2.0.bak"));
89 assert_schema_0(3, "pacemaker-2.1");
90 assert_int_equal(0, rename(SCHEMA_PREFIX "2.0.bak",
91 SCHEMA_PREFIX "2.0.rng"));
92 assert_int_equal(0, rename(SCHEMA_PREFIX "3.0.bak",
93 SCHEMA_PREFIX "3.0.rng"));
95}
96
97PCMK__UNIT_TEST(setup, teardown,
98 cmocka_unit_test(last_is_0),
99 cmocka_unit_test(last_is_not_0),
100 cmocka_unit_test(schema_0_missing))
G_GNUC_INTERNAL GList * pcmk__find_x_0_schema(void)
Definition schemas.c:115
#define SCHEMA_PREFIX
void pcmk__schema_cleanup(void)
Definition schemas.c:712
void pcmk__schema_init(void)
Definition schemas.c:550
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)