Page Menu
Home
ClusterLabs Projects
Search
Configure Global Search
Log In
Files
F4623399
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/common/tests/schemas/Makefile.am b/lib/common/tests/schemas/Makefile.am
index 8854eb264c..394217f14c 100644
--- a/lib/common/tests/schemas/Makefile.am
+++ b/lib/common/tests/schemas/Makefile.am
@@ -1,57 +1,58 @@
#
# 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 $(top_srcdir)/mk/tap.mk
include $(top_srcdir)/mk/unittest.mk
CFLAGS += -DPCMK__TEST_SCHEMA_DIR='"$(abs_builddir)/schemas"'
# Add "_test" to the end of all test program names to simplify .gitignore.
-check_PROGRAMS = pcmk__build_schema_xml_node_test \
+check_PROGRAMS = get_schema_version_test \
+ pcmk__build_schema_xml_node_test \
pcmk__schema_files_later_than_test \
pcmk__xml_find_x_0_schema_index_test
TESTS = $(check_PROGRAMS)
$(TESTS): setup-schema-dir
# Set up a temporary schemas/ directory containing only some of the full set of
# pacemaker schema files. This lets us know exactly how many schemas are present,
# allowing us to write tests without having to make changes when new schemas are
# added.
#
# This directory contains the following:
#
# * pacemaker-next.rng - Used to verify that this sorts before all versions
# * upgrade-*.xsl - Required by various schema versions
# * pacemaker-[0-9]*.rng - We're only pulling in 15 schemas, which is enough
# to get everything through pacemaker-3.0.rng. This
# includes 2.10, needed so we can check that versions
# are compared as numbers instead of strings.
# * other RNG files - This catches everything except the pacemaker-*rng
# files. These files are included by the top-level
# pacemaker-*rng files, so we need them for tests.
# This will glob more than we need, but the extra ones
# won't get in the way.
.PHONY: setup-schema-dir
setup-schema-dir:
$(MKDIR_P) schemas
( cd schemas ; \
ln -sf $(abs_top_builddir)/xml/pacemaker-next.rng . ; \
ln -sf $(abs_top_builddir)/xml/upgrade-*.xsl . ; \
for f in $(shell ls -1v $(abs_top_builddir)/xml/pacemaker-[0-9]*.rng | head -15); do \
ln -sf $$f $$(basename $$f); \
done ; \
for f in $(shell ls -1 $(top_srcdir)/xml/*.rng | grep -v pacemaker); do \
ln -sf ../$$f $$(basename $$f); \
done )
.PHONY: clean-local
clean-local:
-rm -rf schemas
diff --git a/lib/common/tests/schemas/get_schema_version_test.c b/lib/common/tests/schemas/get_schema_version_test.c
new file mode 100644
index 0000000000..0d503aa792
--- /dev/null
+++ b/lib/common/tests/schemas/get_schema_version_test.c
@@ -0,0 +1,53 @@
+/*
+ * 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 <crm_internal.h>
+
+#include <crm/msg_xml.h>
+#include <crm/common/unittest_internal.h>
+#include <crm/common/xml_internal.h>
+
+static int
+setup(void **state) {
+ setenv("PCMK_schema_directory", PCMK__TEST_SCHEMA_DIR, 1);
+ crm_schema_init();
+ return 0;
+}
+
+static int
+teardown(void **state) {
+ crm_schema_cleanup();
+ unsetenv("PCMK_schema_directory");
+ return 0;
+}
+
+static void
+bad_input(void **state) {
+ assert_int_equal(16, get_schema_version(NULL));
+ assert_int_equal(-1, get_schema_version(""));
+ assert_int_equal(-1, get_schema_version("blahblah"));
+ assert_int_equal(-1, get_schema_version("pacemaker-2.47"));
+ assert_int_equal(-1, get_schema_version("pacemaker-47.0"));
+}
+
+static void
+typical_usage(void **state) {
+ assert_int_equal(0, get_schema_version("pacemaker-1.0"));
+ assert_int_equal(0, get_schema_version("PACEMAKER-1.0"));
+ assert_int_equal(1, get_schema_version("pacemaker-1.2"));
+ assert_int_equal(3, get_schema_version("pacemaker-2.0"));
+ assert_int_equal(3, get_schema_version("pAcEmAkEr-2.0"));
+ assert_int_equal(8, get_schema_version("pacemaker-2.5"));
+ assert_int_equal(14, get_schema_version("pacemaker-3.0"));
+ assert_int_equal(14, get_schema_version("paceMAKER-3.0"));
+}
+
+PCMK__UNIT_TEST(setup, teardown,
+ cmocka_unit_test(bad_input),
+ cmocka_unit_test(typical_usage));
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jul 8, 3:25 PM (14 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2002179
Default Alt Text
(4 KB)
Attached To
Mode
rP Pacemaker
Attached
Detach File
Event Timeline
Log In to Comment