-
Notifications
You must be signed in to change notification settings - Fork 3
/
message_test.go
114 lines (111 loc) · 2.17 KB
/
message_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
package infobip
import "testing"
func TestForSingleMessageValidation(t *testing.T) {
tests := []struct {
reference string
from string
to string
err error
}{
{
reference: "#1",
from: "",
to: "",
err: ErrForFromNonAlphanumeric,
},
{
reference: "#2",
from: "111111111111111",
to: "",
err: ErrForFromNonAlphanumeric,
},
{
reference: "#3",
from: "invalid1111111",
to: "",
err: ErrForFromAlphanumeric,
},
{
reference: "#4",
from: "valid",
to: "111111111111111",
err: ErrForToNonAlphanumeric,
},
{
reference: "#5",
from: "442071838750",
to: "14155552671",
err: nil,
},
}
for _, test := range tests {
test := test
t.Run(test.reference, func(t *testing.T) {
m := Message{
From: test.from,
To: test.to,
}
if err := m.Validate(); err != test.err {
t.Errorf("Error: expected '%s', got '%s'", test.err, err)
}
})
}
}
func TestForAdvancedMessageValidation(t *testing.T) {
tests := []struct {
reference string
from string
to []Destination
err error
}{
{
reference: "#1",
to: []Destination{},
err: ErrForFromNonAlphanumeric,
},
{
reference: "#2",
from: "111111111111111",
to: []Destination{},
err: ErrForFromNonAlphanumeric,
},
{
reference: "#3",
from: "invalid1111111",
to: []Destination{},
err: ErrForFromAlphanumeric,
},
{
reference: "#4",
from: "valid",
to: []Destination{
Destination{To: "111111111111111"},
},
err: ErrForDestinationNonAlphanumeric,
},
{
reference: "#5",
from: "442071838750",
to: []Destination{
Destination{To: "14155552671"},
},
err: nil,
},
}
for _, test := range tests {
test := test
t.Run(test.reference, func(t *testing.T) {
b := BulkMessage{
Messages: []Message{
Message{
From: test.from,
Destinations: test.to,
},
},
}
if err := b.Validate(); err != test.err {
t.Errorf("Error: expected '%s', got '%s'", test.err, err)
}
})
}
}