-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnotification_test.go
83 lines (76 loc) · 2.47 KB
/
notification_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
package notificationhubs_test
import (
"reflect"
"testing"
. "github.com/daresaydigital/azure-notificationhubs-go"
)
func TestNewNotification(t *testing.T) {
var (
testPayload = []byte("test payload")
errfmt = "NewNotification test case %d error. Expected %s: %v, got: %v"
testCases = []struct {
format NotificationFormat
payload []byte
expectedNotification *Notification
hasErr bool
}{
{
format: Template,
payload: testPayload,
expectedNotification: &Notification{Format: Template, Payload: testPayload},
hasErr: false,
},
{
format: GcmFormat,
payload: testPayload,
expectedNotification: &Notification{Format: GcmFormat, Payload: testPayload},
hasErr: false,
},
{
format: AppleFormat,
payload: testPayload,
expectedNotification: &Notification{Format: AppleFormat, Payload: testPayload},
hasErr: false,
},
{
format: BaiduFormat,
payload: testPayload,
expectedNotification: &Notification{Format: BaiduFormat, Payload: testPayload},
hasErr: false,
},
{
format: KindleFormat,
payload: testPayload,
expectedNotification: &Notification{Format: KindleFormat, Payload: testPayload},
hasErr: false,
},
{
format: WindowsFormat,
payload: testPayload,
expectedNotification: &Notification{Format: WindowsFormat, Payload: testPayload},
hasErr: false,
},
{
format: WindowsPhoneFormat,
payload: testPayload,
expectedNotification: &Notification{Format: WindowsPhoneFormat, Payload: testPayload},
hasErr: false,
},
{
format: NotificationFormat("unknown_format"),
payload: testPayload,
expectedNotification: nil,
hasErr: true,
},
}
)
for i, testCase := range testCases {
obtainedNotification, obtainedErr := NewNotification(testCase.format, testCase.payload)
if !reflect.DeepEqual(obtainedNotification, testCase.expectedNotification) {
t.Errorf(errfmt, i, "Notification", testCase.expectedNotification, obtainedNotification)
}
if (obtainedErr != nil) != testCase.hasErr {
t.Errorf(errfmt, i, "hasError", testCase.hasErr, obtainedErr != nil)
}
}
}