forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmsglobal_test.go
150 lines (138 loc) · 3.04 KB
/
smsglobal_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
package smsglobal
import (
"testing"
"github.com/thrasher-corp/gocryptotrader/communications/base"
"github.com/thrasher-corp/gocryptotrader/config"
)
func TestSetup(t *testing.T) {
t.Parallel()
var s SMSGlobal
cfg := &config.Config{Communications: base.CommunicationsConfig{}}
commsCfg := cfg.GetCommunicationsConfig()
s.Setup(&commsCfg)
}
func TestConnect(t *testing.T) {
t.Parallel()
var s SMSGlobal
if err := s.Connect(); err != nil {
t.Error(err)
}
}
func TestPushEvent(t *testing.T) {
t.Parallel()
var s SMSGlobal
err := s.PushEvent(base.Event{})
if err != nil {
t.Error("SMSGlobal PushEvent() error", err)
}
}
func TestGetEnabledContacts(t *testing.T) {
t.Parallel()
s := SMSGlobal{
Contacts: []Contact{
{
Name: "test123",
Enabled: true,
},
},
}
if v := s.GetEnabledContacts(); v != 1 {
t.Error("expected one enabled contact")
}
}
func TestGetContactByNumber(t *testing.T) {
t.Parallel()
s := SMSGlobal{
Contacts: []Contact{
{
Name: "test123",
Enabled: true,
Number: "1337",
},
},
}
_, err := s.GetContactByNumber("1337")
if err != nil {
t.Error("SMSGlobal GetContactByNumber() error", err)
}
_, err = s.GetContactByNumber("basketball")
if err == nil {
t.Error("SMSGlobal GetContactByNumber() error")
}
}
func TestGetContactByName(t *testing.T) {
t.Parallel()
s := SMSGlobal{
Contacts: []Contact{
{
Name: "test123",
Enabled: true,
},
},
}
_, err := s.GetContactByName("test123")
if err != nil {
t.Error("SMSGlobal GetContactByName() error", err)
}
_, err = s.GetContactByName("blah")
if err == nil {
t.Error("SMSGlobal GetContactByName() error")
}
}
func TestAddContact(t *testing.T) {
t.Parallel()
s := SMSGlobal{
Contacts: []Contact{},
}
err := s.AddContact(Contact{Name: "bra", Number: "2876", Enabled: true})
if err != nil {
t.Error("SMSGlobal AddContact() error", err)
}
err = s.AddContact(Contact{Name: "bra", Number: "2876", Enabled: true})
if err == nil {
t.Error("SMSGlobal AddContact() error")
}
err = s.AddContact(Contact{Name: "", Number: "", Enabled: true})
if err == nil {
t.Error("SMSGlobal AddContact() error")
}
if len(s.Contacts) == 0 {
t.Error("failed to add contacts")
}
}
func TestRemoveContact(t *testing.T) {
t.Parallel()
s := SMSGlobal{
Contacts: []Contact{
{
Name: "test123",
Enabled: true,
Number: "1337",
},
},
}
err := s.RemoveContact(Contact{Name: "test123", Number: "1337", Enabled: true})
if err != nil {
t.Error("SMSGlobal RemoveContact() error", err)
}
err = s.RemoveContact(Contact{Name: "frieda", Number: "243453", Enabled: true})
if err == nil {
t.Error("SMSGlobal RemoveContact() Expected error")
}
}
func TestSendMessageToAll(t *testing.T) {
t.Parallel()
var s SMSGlobal
err := s.SendMessageToAll("Hello,World!")
if err != nil {
t.Error("SMSGlobal SendMessageToAll() error", err)
}
}
func TestSendMessage(t *testing.T) {
t.Parallel()
var s SMSGlobal
err := s.SendMessage("1337", "Hello!")
if err != nil {
t.Error("SMSGlobal SendMessage() error", err)
}
}