-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathgosx-notifier_test.go
179 lines (135 loc) · 3.5 KB
/
gosx-notifier_test.go
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package gosxnotifier
import (
"log"
"path/filepath"
"testing"
)
func Test_Install(t *testing.T) {
//assert file exists
if !exists(FinalPath) {
t.Error("Test_Install failed to install the terminal-notifier.app bundle")
} else {
log.Println("terminal-notifier.app bundle installed successfully at: ", FinalPath)
}
}
func Test_NewNotifier(t *testing.T) {
n := NewNotification("Hello")
//assert defaults
if n.Message != "Hello" {
t.Error("NewNotification doesn't have a Message specified")
}
}
func Test_Push(t *testing.T) {
n := NewNotification("Testing Push")
err := n.Push()
if err != nil {
t.Error("Test_Push failed with error: ", err)
}
}
func Test_Title(t *testing.T) {
n := NewNotification("Testing Title")
n.Title = "gosx-notifier is amazing!"
err := n.Push()
if err != nil {
t.Error("Test_Title failed with error: ", err)
}
}
func Test_Subtitle(t *testing.T) {
n := NewNotification("Testing Subtitle")
n.Subtitle = "gosx-notifier rocks!"
err := n.Push()
if err != nil {
t.Error("Test_Subtitle failed with error: ", err)
}
}
func Test_Sender(t *testing.T) {
for _, s := range []string{"com.apple.Safari", "com.apple.iTunes"} {
n := NewNotification("Testing Icon")
n.Title = s
n.Sender = s
err := n.Push()
if err != nil {
t.Error("Test_Sender failed with error: ", err)
}
}
}
func Test_Group(t *testing.T) {
const app_id string = "github.com/deckarep/gosx-notifier"
for i := 0; i < 3; i++ {
n := NewNotification("Testing Group Functionality...")
n.Group = app_id
err := n.Push()
if err != nil {
t.Error("Test_Group failed with error: ", err)
}
}
}
func Test_AppIcon(t *testing.T) {
const appIcon string = "gopher.png"
n := NewNotification("Testing App Icon")
if icon, err := filepath.Abs(appIcon); err != nil {
t.Error("Test_AppIcon could not get the absolute file of: ", appIcon)
} else {
n.AppIcon = icon
}
err := n.Push()
if err != nil {
t.Error("Test_AppIcon failed with error: ", err)
}
}
func Test_ContentImage(t *testing.T) {
const contentImage string = "gopher.png"
n := NewNotification("Testing Content Image")
if img, err := filepath.Abs(contentImage); err != nil {
t.Error("Test_AppIcon could not get the absolute file of: ", contentImage)
} else {
n.ContentImage = img
}
err := n.Push()
if err != nil {
t.Error("Test_ContentImage failed with error: ", err)
}
}
func Test_ContentImageAndIcon(t *testing.T) {
const image string = "gopher.png"
n := NewNotification("Testing Content Image and Icon")
n.Title = "Hey Gopher!"
n.Subtitle = "I eat Goroutines for breakfast!"
if img, err := filepath.Abs(image); err != nil {
t.Error("Test_AppIcon could not get the absolute file of: ", image)
} else {
n.ContentImage = img
n.AppIcon = img
}
err := n.Push()
if err != nil {
t.Error("Test_ContentImageAndIcon failed with error: ", err)
}
}
/*
Not an easy way to verify the tests below actually work as designed, but here for completion.
*/
func Test_Sound(t *testing.T) {
n := NewNotification("Testing Sound")
n.Sound = Default
err := n.Push()
if err != nil {
t.Error("Test_Sound failed with error: ", err)
}
}
func Test_Link_Url(t *testing.T) {
n := NewNotification("Testing Link Url")
n.Link = "http://www.yahoo.com"
err := n.Push()
if err != nil {
t.Error("Test_Link failed with error: ", err)
}
}
func Test_Link_App_Bundle(t *testing.T) {
n := NewNotification("Testing Link Terminal")
n.Link = "com.apple.Safari"
err := n.Push()
if err != nil {
t.Error("Test_Link failed with error: ", err)
}
}