Repository navigation
Expand file tree
/
Copy pathnotify_test.go
More file actions
88 lines (76 loc) · 1.6 KB
/
Copy pathnotify_test.go
File metadata and controls
88 lines (76 loc) · 1.6 KB
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
package beeep
import (
_ "embed"
"os"
"runtime"
"sync"
"testing"
)
//go:embed testdata/info.png
var data []byte
func desktopTest(t *testing.T) {
t.Helper()
if os.Getenv("BEEEP_TEST_DESKTOP") == "" {
t.Skip("set BEEEP_TEST_DESKTOP=1 to send real notifications")
}
}
func stockIcon() string {
switch runtime.GOOS {
case "darwin":
return "NSCaution"
case "windows", "js":
return ""
default:
return "dialog-information"
}
}
var iconTests = []struct {
name string
icon any
}{
{"bytes", data},
{"path", "testdata/warning.png"},
{"stock", stockIcon()},
{"none", ""},
{"missing", "testdata/missing.png"},
{"invalid", []byte("not a png")},
}
func TestNotify(t *testing.T) {
desktopTest(t)
for _, tt := range iconTests {
t.Run(tt.name, func(t *testing.T) {
if err := Notify("Notify "+tt.name, "Message body", tt.icon); err != nil {
t.Error(err)
}
})
}
}
func TestNotifyText(t *testing.T) {
desktopTest(t)
title := `Quotes "double" 'single' \backslash`
message := "Unicode čćžšđ ✓, tab\tand newline\nsecond line"
if err := Notify(title, message, data); err != nil {
t.Error(err)
}
}
func TestNotifyConcurrent(t *testing.T) {
desktopTest(t)
var wg sync.WaitGroup
for i := 0; i < 3; i++ {
wg.Add(1)
go func() {
defer wg.Done()
if err := Notify("Notify concurrent", "Message body", data); err != nil {
t.Error(err)
}
}()
}
wg.Wait()
}
func TestNotifyUnsupportedIcon(t *testing.T) {
for _, icon := range []any{42, nil, struct{}{}} {
if err := Notify("Notify title", "Message body", icon); err == nil {
t.Errorf("icon %T: expected error", icon)
}
}
}