-
Notifications
You must be signed in to change notification settings - Fork 3
/
view_action_test.go
60 lines (55 loc) · 1.27 KB
/
view_action_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
package gotfy
import (
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestViewMarshalJSON(mainTest *testing.T) {
uri, err := url.Parse("https://docs.ntfy.sh/publish/#icons")
if err != nil {
mainTest.Fatalf("failed setting up test URL: %v", err)
}
testCases := []struct {
name string
arg ViewAction
expected string
expectedErr error
}{
{
name: "base case",
expected: `{"action":"view","label":""}`,
},
{
name: "only label",
arg: ViewAction{Label: "label"},
expected: `{"action":"view","label":"label"}`,
},
{
name: "url",
arg: ViewAction{Link: uri},
expected: `{"action":"view","label":"","url":"https://docs.ntfy.sh/publish/#icons"}`,
},
{
name: "clear",
arg: ViewAction{
Clear: true,
},
expected: `{"action":"view","label":"","clear":true}`,
},
{
name: "everything",
arg: ViewAction{
Label: "label",
Link: uri,
Clear: true,
},
expected: `{"action":"view","label":"label","url":"https://docs.ntfy.sh/publish/#icons","clear":true}`,
},
}
t := assert.New(mainTest)
for _, tc := range testCases {
actual, actualErr := tc.arg.MarshalJSON()
t.Equal([]byte(tc.expected), actual, tc.name)
t.Equal(tc.expectedErr, actualErr, tc.name)
}
}