aboutsummaryrefslogtreecommitdiffstats
path: root/test-notifyctl.sh
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-15 13:53:34 +0200
committerDanilo M. <danix@danix.xyz>2026-09-15 13:53:34 +0200
commitbcf15590f9e43f2d8978cf7cccfbdf3bb66e376f (patch)
treebf6d77460dc7025582fc9a486d9271b176cb6e1b /test-notifyctl.sh
parent3bdd5a50c3b8fa0a885dc58a3d0ec64880f95619 (diff)
downloadnotifyd-bcf15590f9e43f2d8978cf7cccfbdf3bb66e376f.tar.gz
notifyd-bcf15590f9e43f2d8978cf7cccfbdf3bb66e376f.zip
feat: add the control interface and notifyctl
The private interface carries what the spec cannot: close-all, invoke action and clear history. notifyctl reads the published files for list and history, because the files are the interface, and uses D-Bus only for the mutations.
Diffstat (limited to 'test-notifyctl.sh')
-rwxr-xr-xtest-notifyctl.sh65
1 files changed, 65 insertions, 0 deletions
diff --git a/test-notifyctl.sh b/test-notifyctl.sh
new file mode 100755
index 0000000..7018e2a
--- /dev/null
+++ b/test-notifyctl.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+#
+# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# The one runnable check for notifyctl. It runs the daemon and the CLI on a
+# private session bus with a temporary runtime directory, so nothing here
+# touches the live notification state.
+#
+# Usage: ./test-notifyctl.sh (exit 0 = all passed)
+
+set -u
+
+here="$(cd "$(dirname "$0")" && pwd)"
+tmp="$(mktemp -d)"
+trap 'rm -rf "$tmp"' EXIT
+
+pass=0
+fail=0
+check() {
+ local label="$1" want="$2" got="$3"
+ if [[ "$want" == "$got" ]]; then
+ printf 'ok %s\n' "$label"
+ pass=$((pass + 1))
+ else
+ printf 'FAIL %s: want %q, got %q\n' "$label" "$want" "$got"
+ fail=$((fail + 1))
+ fi
+}
+
+go build -o "$tmp/notifyd" "$here/cmd/notifyd" || exit 1
+go build -o "$tmp/notifyctl" "$here/cmd/notifyctl" || exit 1
+
+mkdir -p "$tmp/run"
+export XDG_RUNTIME_DIR="$tmp/run"
+export PATH="$tmp:$PATH"
+
+dbus-run-session -- bash -c '
+ set -u
+ "$1/notifyd" >"$1/daemon.log" 2>&1 & daemon=$!
+ sleep 0.5
+ notifyctl close-all >/dev/null 2>&1
+ notify-send -a test -u normal "t1" "b1" || exit 3
+ sleep 0.3
+ echo "$(notifyctl list | grep -c "\"summary\": \"t1\"")"
+ notifyctl close-all
+ sleep 0.3
+ echo "$(notifyctl list | grep -c "\"summary\": \"t1\"")"
+ kill $daemon
+' _ "$tmp" > "$tmp/out" 2>"$tmp/err"
+
+check "list shows the notification" "1" "$(sed -n 1p "$tmp/out")"
+check "close-all empties the live queue" "0" "$(sed -n 2p "$tmp/out")"
+check "no errors on stderr" "" "$(cat "$tmp/err")"
+
+printf '\n%d passed, %d failed\n' "$pass" "$fail"
+[[ "$fail" -eq 0 ]]