pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
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 
21 static int
22 setup(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 
29 static int
30 teardown(void **state)
31 {
32  unsetenv("PCMK_schema_directory");
33  return 0;
34 }
35 
36 static void
37 assert_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 
52 static void
53 last_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 
63 static void
64 last_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 
78 static void
79 schema_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 
97 PCMK__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))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
void crm_schema_init(void)
Definition: schemas.c:470
void crm_schema_cleanup(void)
Definition: schemas.c:643
G_GNUC_INTERNAL GList * pcmk__find_x_0_schema(void)
Definition: schemas.c:111
#define SCHEMA_PREFIX