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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// 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.
package notify
import (
"testing"
"github.com/godbus/dbus/v5"
)
func TestUrgencyFromHints(t *testing.T) {
cases := []struct {
name string
hints map[string]dbus.Variant
want Urgency
}{
{"missing is normal", map[string]dbus.Variant{}, Normal},
{"low byte", map[string]dbus.Variant{"urgency": dbus.MakeVariant(byte(0))}, Low},
{"normal byte", map[string]dbus.Variant{"urgency": dbus.MakeVariant(byte(1))}, Normal},
{"critical byte", map[string]dbus.Variant{"urgency": dbus.MakeVariant(byte(2))}, Critical},
{"critical int32", map[string]dbus.Variant{"urgency": dbus.MakeVariant(int32(2))}, Critical},
{"wrong type is normal", map[string]dbus.Variant{"urgency": dbus.MakeVariant("2")}, Normal},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if got := UrgencyFromHints(c.hints); got != c.want {
t.Errorf("UrgencyFromHints = %q, want %q", got, c.want)
}
})
}
}
func TestEffectiveTimeoutMS(t *testing.T) {
cases := []struct {
name string
expire int32
u Urgency
want int64
}{
{"zero uses low default", 0, Low, 10_000},
{"zero uses normal default", 0, Normal, 10_000},
{"zero critical never", 0, Critical, 0},
{"minus one never", -1, Normal, 0},
{"explicit wins", 3_000, Normal, 3_000},
{"sub second exact", 1, Normal, 1},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if got := EffectiveTimeoutMS(c.expire, c.u); got != c.want {
t.Errorf("EffectiveTimeoutMS(%d, %q) = %d, want %d", c.expire, c.u, got, c.want)
}
})
}
}
func TestStackTagFromHints(t *testing.T) {
dunst := map[string]dbus.Variant{"x-dunst-stack-tag": dbus.MakeVariant("mail-a")}
danix := map[string]dbus.Variant{"x-danix-stack-tag": dbus.MakeVariant("mail-b")}
both := map[string]dbus.Variant{
"x-dunst-stack-tag": dbus.MakeVariant("mail-a"),
"x-danix-stack-tag": dbus.MakeVariant("mail-b"),
}
if got := StackTagFromHints(dunst); got != "mail-a" {
t.Errorf("dunst tag = %q, want mail-a", got)
}
if got := StackTagFromHints(danix); got != "mail-b" {
t.Errorf("danix tag = %q, want mail-b", got)
}
if got := StackTagFromHints(both); got != "mail-a" {
t.Errorf("dunst wins when both present = %q, want mail-a", got)
}
if got := StackTagFromHints(map[string]dbus.Variant{}); got != "" {
t.Errorf("empty = %q, want empty", got)
}
}
func TestParseActions(t *testing.T) {
got := ParseActions([]string{"default", "open", "other", "do the thing"})
want := [][2]string{{"default", "open"}, {"other", "do the thing"}}
if len(got) != len(want) {
t.Fatalf("len = %d, want %d", len(got), len(want))
}
for i := range want {
if got[i] != want[i] {
t.Errorf("action %d = %v, want %v", i, got[i], want[i])
}
}
if got := ParseActions(nil); len(got) != 0 {
t.Errorf("nil actions = %v, want empty", got)
}
}
|