feat: check skips snoozed alarms and sweeps expired snooze entries
This commit is contained in:
parent
a2c3755635
commit
793a1cd38a
2 changed files with 153 additions and 0 deletions
|
|
@ -124,3 +124,76 @@ SCRIPT
|
|||
_new_ts="$(cut -f3 "${NAG_DIR}/alarms" | head -1)"
|
||||
(( _new_ts > $(date +%s) ))
|
||||
}
|
||||
|
||||
@test "check skips snoozed alarm and does not fire it" {
|
||||
local _past_ts=$(( $(date +%s) - 60 ))
|
||||
write_alarm "$(printf "1\t\t%s\t\tsnoozed alarm" "${_past_ts}")"
|
||||
printf "1\\n" > "${NAG_DIR}/snoozed"
|
||||
|
||||
local _fired="${NAG_DIR}/fired"
|
||||
export NAG_CMD="${NAG_DIR}/recorder"
|
||||
cat > "${NAG_CMD}" <<'SCRIPT'
|
||||
#!/usr/bin/env bash
|
||||
printf "%s\n" "$2" >> "${NAG_DIR}/fired"
|
||||
SCRIPT
|
||||
chmod +x "${NAG_CMD}"
|
||||
|
||||
run_nag check
|
||||
[ "${status}" -eq 0 ]
|
||||
[ ! -f "${_fired}" ]
|
||||
[ -s "${NAG_DIR}/alarms" ]
|
||||
grep -q "snoozed alarm" "${NAG_DIR}/alarms"
|
||||
}
|
||||
|
||||
@test "check skips alarm snoozed with expiry" {
|
||||
local _past_ts=$(( $(date +%s) - 60 ))
|
||||
local _future_expiry=$(( $(date +%s) + 3600 ))
|
||||
write_alarm "$(printf "1\t\t%s\t\tsnoozed alarm" "${_past_ts}")"
|
||||
printf "1\t%s\\n" "${_future_expiry}" > "${NAG_DIR}/snoozed"
|
||||
|
||||
local _fired="${NAG_DIR}/fired"
|
||||
export NAG_CMD="${NAG_DIR}/recorder"
|
||||
cat > "${NAG_CMD}" <<'SCRIPT'
|
||||
#!/usr/bin/env bash
|
||||
printf "%s\n" "$2" >> "${NAG_DIR}/fired"
|
||||
SCRIPT
|
||||
chmod +x "${NAG_CMD}"
|
||||
|
||||
run_nag check
|
||||
[ "${status}" -eq 0 ]
|
||||
[ ! -f "${_fired}" ]
|
||||
[ -s "${NAG_DIR}/alarms" ]
|
||||
}
|
||||
|
||||
@test "check sweeps expired snooze entries" {
|
||||
local _future_ts=$(( $(date +%s) + 3600 ))
|
||||
write_alarm "$(printf "1\t\t%s\t\talarm" "${_future_ts}")"
|
||||
local _past_expiry=$(( $(date +%s) - 60 ))
|
||||
printf "1\t%s\\n" "${_past_expiry}" > "${NAG_DIR}/snoozed"
|
||||
|
||||
run_nag check
|
||||
[ "${status}" -eq 0 ]
|
||||
|
||||
if [ -f "${NAG_DIR}/snoozed" ]; then
|
||||
[ ! -s "${NAG_DIR}/snoozed" ] || ! grep -q "^1" "${NAG_DIR}/snoozed"
|
||||
fi
|
||||
}
|
||||
|
||||
@test "check fires alarm after snooze expires" {
|
||||
local _past_ts=$(( $(date +%s) - 60 ))
|
||||
local _past_expiry=$(( $(date +%s) - 120 ))
|
||||
write_alarm "$(printf "1\t\t%s\t\texpired snooze" "${_past_ts}")"
|
||||
printf "1\t%s\\n" "${_past_expiry}" > "${NAG_DIR}/snoozed"
|
||||
|
||||
local _fired="${NAG_DIR}/fired"
|
||||
export NAG_CMD="${NAG_DIR}/recorder"
|
||||
cat > "${NAG_CMD}" <<'SCRIPT'
|
||||
#!/usr/bin/env bash
|
||||
printf "%s\n" "$2" >> "${NAG_DIR}/fired"
|
||||
SCRIPT
|
||||
chmod +x "${NAG_CMD}"
|
||||
|
||||
run_nag check
|
||||
[ "${status}" -eq 0 ]
|
||||
grep -q "expired snooze" "${_fired}"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue