summaryrefslogtreecommitdiff
path: root/test/test-bootctl-json.sh
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-11-16 09:49:30 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-12-01 18:01:00 +0100
commit50f2c32cd5477bb42bf9a26e4aefd7230c2574c7 (patch)
tree5c8bb223fd39df2d3520a7feb743e91971ebdf35 /test/test-bootctl-json.sh
parentb570204a97bccfbfce8fc4ffa65306f8a06fe16e (diff)
downloadsystemd-50f2c32cd5477bb42bf9a26e4aefd7230c2574c7.tar.gz
tests: add a simple test that bootctl output is valid json
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.
Diffstat (limited to 'test/test-bootctl-json.sh')
-rwxr-xr-xtest/test-bootctl-json.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/test-bootctl-json.sh b/test/test-bootctl-json.sh
new file mode 100755
index 0000000000..7a660a8ea7
--- /dev/null
+++ b/test/test-bootctl-json.sh
@@ -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