@@ -5,52 +5,52 @@ import (
5
5
"testing"
6
6
"time"
7
7
8
- "github.com/messagebird/go-rest-api/internal/messagebirdtest "
8
+ "github.com/messagebird/go-rest-api/mbtest "
9
9
)
10
10
11
11
func TestMain (m * testing.M ) {
12
- messagebirdtest .EnableServer (m )
12
+ mbtest .EnableServer (m )
13
13
}
14
14
15
15
func TestCreate (t * testing.T ) {
16
- messagebirdtest .WillReturnTestdata (t , "groupObject.json" , http .StatusCreated )
17
- client := messagebirdtest .Client (t )
16
+ mbtest .WillReturnTestdata (t , "groupObject.json" , http .StatusCreated )
17
+ client := mbtest .Client (t )
18
18
19
19
group , err := Create (client , & Request {"Friends" })
20
20
if err != nil {
21
21
t .Fatalf ("unexpected error creating Group: %s" , err )
22
22
}
23
23
24
- messagebirdtest .AssertEndpointCalled (t , http .MethodPost , "/groups" )
25
- messagebirdtest .AssertTestdata (t , "groupRequestCreateObject.json" , messagebirdtest .Request .Body )
24
+ mbtest .AssertEndpointCalled (t , http .MethodPost , "/groups" )
25
+ mbtest .AssertTestdata (t , "groupRequestCreateObject.json" , messagebirdtest .Request .Body )
26
26
27
27
if group .Name != "Friends" {
28
28
t .Fatalf ("expected Friends, got %s" , group .Name )
29
29
}
30
30
}
31
31
32
32
func TestCreateWithEmptyName (t * testing.T ) {
33
- client := messagebirdtest .Client (t )
33
+ client := mbtest .Client (t )
34
34
35
35
if _ , err := Create (client , & Request {"" }); err == nil {
36
36
t .Fatalf ("expected error, got nil" )
37
37
}
38
38
}
39
39
40
40
func TestDelete (t * testing.T ) {
41
- messagebirdtest .WillReturn ([]byte ("" ), http .StatusNoContent )
42
- client := messagebirdtest .Client (t )
41
+ mbtest .WillReturn ([]byte ("" ), http .StatusNoContent )
42
+ client := mbtest .Client (t )
43
43
44
44
if err := Delete (client , "group-id" ); err != nil {
45
45
t .Fatalf ("unexpected error deleting Group: %s" , err )
46
46
}
47
47
48
- messagebirdtest .AssertEndpointCalled (t , http .MethodDelete , "/groups/group-id" )
48
+ mbtest .AssertEndpointCalled (t , http .MethodDelete , "/groups/group-id" )
49
49
}
50
50
51
51
func TestList (t * testing.T ) {
52
- messagebirdtest .WillReturnTestdata (t , "groupListObject.json" , http .StatusOK )
53
- client := messagebirdtest .Client (t )
52
+ mbtest .WillReturnTestdata (t , "groupListObject.json" , http .StatusOK )
53
+ client := mbtest .Client (t )
54
54
55
55
list , err := List (client , DefaultListOptions )
56
56
if err != nil {
@@ -85,11 +85,11 @@ func TestList(t *testing.T) {
85
85
t .Fatalf ("expected second-id, got %s" , list .Items [1 ].ID )
86
86
}
87
87
88
- messagebirdtest .AssertEndpointCalled (t , http .MethodGet , "/groups" )
88
+ mbtest .AssertEndpointCalled (t , http .MethodGet , "/groups" )
89
89
}
90
90
91
91
func TestListPagination (t * testing.T ) {
92
- client := messagebirdtest .Client (t )
92
+ client := mbtest .Client (t )
93
93
94
94
tt := []struct {
95
95
expected string
@@ -103,22 +103,22 @@ func TestListPagination(t *testing.T) {
103
103
for _ , tc := range tt {
104
104
List (client , tc .options )
105
105
106
- if query := messagebirdtest .Request .URL .RawQuery ; query != tc .expected {
106
+ if query := mbtest .Request .URL .RawQuery ; query != tc .expected {
107
107
t .Fatalf ("expected %s, got %s" , tc .expected , query )
108
108
}
109
109
}
110
110
}
111
111
112
112
func TestRead (t * testing.T ) {
113
- messagebirdtest .WillReturnTestdata (t , "groupObject.json" , http .StatusOK )
114
- client := messagebirdtest .Client (t )
113
+ mbtest .WillReturnTestdata (t , "groupObject.json" , http .StatusOK )
114
+ client := mbtest .Client (t )
115
115
116
116
group , err := Read (client , "group-id" )
117
117
if err != nil {
118
118
t .Fatalf ("unexpected error reading Group: %s" , err )
119
119
}
120
120
121
- messagebirdtest .AssertEndpointCalled (t , http .MethodGet , "/groups/group-id" )
121
+ mbtest .AssertEndpointCalled (t , http .MethodGet , "/groups/group-id" )
122
122
123
123
if group .ID != "group-id" {
124
124
t .Fatalf ("expected group-id, got %s" , group .ID )
@@ -150,34 +150,34 @@ func TestRead(t *testing.T) {
150
150
}
151
151
152
152
func TestUpdate (t * testing.T ) {
153
- messagebirdtest .WillReturn ([]byte ("" ), http .StatusNoContent )
154
- client := messagebirdtest .Client (t )
153
+ mbtest .WillReturn ([]byte ("" ), http .StatusNoContent )
154
+ client := mbtest .Client (t )
155
155
156
156
if err := Update (client , "group-id" , & Request {"Family" }); err != nil {
157
157
t .Fatalf ("unexpected error updating Group: %s" , err )
158
158
}
159
159
160
- messagebirdtest .AssertEndpointCalled (t , http .MethodPatch , "/groups/group-id" )
161
- messagebirdtest .AssertTestdata (t , "groupRequestUpdateObject.json" , messagebirdtest .Request .Body )
160
+ mbtest .AssertEndpointCalled (t , http .MethodPatch , "/groups/group-id" )
161
+ mbtest .AssertTestdata (t , "groupRequestUpdateObject.json" , messagebirdtest .Request .Body )
162
162
}
163
163
164
164
func TestAddContacts (t * testing.T ) {
165
- messagebirdtest .WillReturn ([]byte ("" ), http .StatusNoContent )
166
- client := messagebirdtest .Client (t )
165
+ mbtest .WillReturn ([]byte ("" ), http .StatusNoContent )
166
+ client := mbtest .Client (t )
167
167
168
168
if err := AddContacts (client , "group-id" , []string {"first-contact-id" , "second-contact-id" }); err != nil {
169
169
t .Fatalf ("unexpected error removing Contacts from Group: %s" , err )
170
170
}
171
171
172
- messagebirdtest .AssertEndpointCalled (t , http .MethodGet , "/groups/group-id/contacts" )
172
+ mbtest .AssertEndpointCalled (t , http .MethodGet , "/groups/group-id/contacts" )
173
173
174
- if messagebirdtest .Request .URL .RawQuery != "_method=PUT&ids[]=first-contact-id&ids[]=second-contact-id" {
174
+ if mbtest .Request .URL .RawQuery != "_method=PUT&ids[]=first-contact-id&ids[]=second-contact-id" {
175
175
t .Fatalf ("expected _method=PUT&ids[]=first-contact-id&ids[]=second-contact-id, got %s" , messagebirdtest .Request .URL .RawQuery )
176
176
}
177
177
}
178
178
179
179
func TestAddContactsWithEmptyContacts (t * testing.T ) {
180
- client := messagebirdtest .Client (t )
180
+ client := mbtest .Client (t )
181
181
182
182
tt := []struct {
183
183
contactIDS []string
@@ -194,7 +194,7 @@ func TestAddContactsWithEmptyContacts(t *testing.T) {
194
194
}
195
195
196
196
func TestAddContactsWithTooManyContacts (t * testing.T ) {
197
- client := messagebirdtest .Client (t )
197
+ client := mbtest .Client (t )
198
198
199
199
contactIDS := make ([]string , 51 )
200
200
@@ -204,8 +204,8 @@ func TestAddContactsWithTooManyContacts(t *testing.T) {
204
204
}
205
205
206
206
func TestListContacts (t * testing.T ) {
207
- messagebirdtest .WillReturnTestdata (t , "groupContactListObject.json" , http .StatusOK )
208
- client := messagebirdtest .Client (t )
207
+ mbtest .WillReturnTestdata (t , "groupContactListObject.json" , http .StatusOK )
208
+ client := mbtest .Client (t )
209
209
210
210
list , err := ListContacts (client , "group-id" , DefaultListOptions )
211
211
if err != nil {
@@ -242,16 +242,16 @@ func TestListContacts(t *testing.T) {
242
242
243
243
client .DebugLog .Printf ("list:\n %#v\n " , list )
244
244
245
- messagebirdtest .AssertEndpointCalled (t , http .MethodGet , "/groups/group-id/contacts" )
245
+ mbtest .AssertEndpointCalled (t , http .MethodGet , "/groups/group-id/contacts" )
246
246
}
247
247
248
248
func TestRemoveContact (t * testing.T ) {
249
- messagebirdtest .WillReturn ([]byte ("" ), http .StatusNoContent )
250
- client := messagebirdtest .Client (t )
249
+ mbtest .WillReturn ([]byte ("" ), http .StatusNoContent )
250
+ client := mbtest .Client (t )
251
251
252
252
if err := RemoveContact (client , "group-id" , "contact-id" ); err != nil {
253
253
t .Fatalf ("unexpected error deleting Group: %s" , err )
254
254
}
255
255
256
- messagebirdtest .AssertEndpointCalled (t , http .MethodDelete , "/groups/group-id/contacts/contact-id" )
256
+ mbtest .AssertEndpointCalled (t , http .MethodDelete , "/groups/group-id/contacts/contact-id" )
257
257
}
0 commit comments