]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: add a simple test that bootctl output is valid json
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 16 Nov 2022 08:49:30 +0000 (09:49 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 1 Dec 2022 17:01:00 +0000 (18:01 +0100)
python's json.tool module is used because it does validation. jq is more forgiving.
Also, json is in the stdlib, so it should be always available.

meson.build
test/meson.build
test/test-bootctl-json.sh [new file with mode: 0755]

index 37d46dfae2a9aa16981e7956c891462595b41e65..2fb510297124b95f2ad5de7ec907da55757a48f6 100644 (file)
@@ -2583,7 +2583,7 @@ if conf.get('HAVE_BLKID') == 1 and conf.get('HAVE_GNU_EFI') == 1
                 boot_link_with = [libsystemd_static, libshared_static]
         endif
 
-        public_programs += executable(
+        exe = executable(
                 'bootctl',
                 'src/boot/bootctl.c',
                 include_directories : includes,
@@ -2592,6 +2592,14 @@ if conf.get('HAVE_BLKID') == 1 and conf.get('HAVE_GNU_EFI') == 1
                                 versiondep],
                 install_rpath : rootpkglibdir,
                 install : true)
+        public_programs += exe
+
+        if want_tests != 'false'
+                test('test-bootctl-json',
+                     test_bootctl_json_sh,
+                     args : exe.full_path(),
+                     depends : exe)
+        endif
 
         public_programs += executable(
                 'systemd-bless-boot',
index f2080b5a9a1ce7c3d02fe7451f18e2785d832b4f..93f0e679fe3afba0ad186631193c3004e549d9f6 100644 (file)
@@ -89,6 +89,7 @@ if install_tests
                      install_dir : testdata_dir)
 endif
 
+test_bootctl_json_sh = find_program('test-bootctl-json.sh')
 test_fstab_generator_sh = find_program('test-fstab-generator.sh')
 test_network_generator_conversion_sh = find_program('test-network-generator-conversion.sh')
 test_systemctl_enable_sh = find_program('test-systemctl-enable.sh')
diff --git a/test/test-bootctl-json.sh b/test/test-bootctl-json.sh
new file mode 100755 (executable)
index 0000000..7a660a8
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -e
+set -o pipefail
+
+bootctl="${1:?}"
+
+"$bootctl" --no-pager list >/dev/null || {
+    echo "$bootctl list failed, skipping tests" 1>&2
+    exit 77
+}
+
+set -x
+
+"$bootctl" list --json=pretty | python3 -m json.tool >/dev/null
+"$bootctl" list --json=short | python3 -m json.tool >/dev/null
+
+command -v jq >/dev/null || {
+    echo "jq is not available, skipping jq tests" 1>&2
+    exit 0
+}
+
+"$bootctl" list --json=pretty | jq . >/dev/null
+"$bootctl" list --json=short | jq . >/dev/null