aboutsummaryrefslogtreecommitdiffstats
path: root/test-notify-snooze.sh
blob: 5e25240e9da9133f5528294ab0574dfe0e343056 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/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.
#
# Usage: ./test-notify-snooze.sh

set -u
here="$(cd "$(dirname "$0")" && pwd)"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
export XDG_RUNTIME_DIR="$tmp"
export HOME="$tmp/home"
mkdir -p "$HOME/.local/state"

pass=0; fail=0
check() { if [[ "$2" == "$3" ]]; then echo "ok   $1"; pass=$((pass+1)); else echo "FAIL $1: want $2 got $3"; fail=$((fail+1)); fi; }

before=$(date +%s)
bash "$here/scripts/notify-snooze.sh" 30
snooze="$tmp/notifyd/snooze"
check "writes the snooze file" "yes" "$([[ -f "$snooze" ]] && echo yes)"
delta=$(( $(cat "$snooze") - before ))
check "is about 30 minutes out" "yes" "$([[ $delta -ge 1700 && $delta -le 1900 ]] && echo yes)"
check "remembers the minutes" "30" "$(cat "$HOME/.local/state/notify-snooze.minutes")"
bash "$here/scripts/notify-snooze.sh" off
check "off removes the file" "no" "$([[ -f "$snooze" ]] && echo yes || echo no)"
bash "$here/scripts/notify-snooze.sh" nope >/dev/null 2>&1
check "rejects a bad argument" "1" "$?"

printf '\n%d passed, %d failed\n' "$pass" "$fail"
[[ "$fail" -eq 0 ]]