@@ -5,24 +5,24 @@ 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/internal/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 TestCreateWithEmptyMSISDN (t * testing.T ) {
16
- client := messagebirdtest .Client (t )
16
+ client := mbtest .Client (t )
17
17
18
18
if _ , err := Create (client , & Request {}); err == nil {
19
19
t .Fatalf ("expected error, got nil" )
20
20
}
21
21
}
22
22
23
23
func TestCreate (t * testing.T ) {
24
- messagebirdtest .WillReturnTestdata (t , "contactObject.json" , http .StatusCreated )
25
- client := messagebirdtest .Client (t )
24
+ mbtest .WillReturnTestdata (t , "contactObject.json" , http .StatusCreated )
25
+ client := mbtest .Client (t )
26
26
27
27
contact , err := Create (client , & Request {
28
28
MSISDN : "31612345678" ,
@@ -35,8 +35,8 @@ func TestCreate(t *testing.T) {
35
35
t .Fatalf ("unexpected error creating Contact: %s" , err )
36
36
}
37
37
38
- messagebirdtest .AssertEndpointCalled (t , http .MethodPost , "/contacts" )
39
- messagebirdtest .AssertTestdata (t , "contactRequestObjectCreate.json" , messagebirdtest .Request .Body )
38
+ mbtest .AssertEndpointCalled (t , http .MethodPost , "/contacts" )
39
+ mbtest .AssertTestdata (t , "contactRequestObjectCreate.json" , mbtest .Request .Body )
40
40
41
41
if contact .MSISDN != 31612345678 {
42
42
t .Fatalf ("expected 31612345678, got %d" , contact .MSISDN )
@@ -68,27 +68,27 @@ func TestCreate(t *testing.T) {
68
68
}
69
69
70
70
func TestDelete (t * testing.T ) {
71
- messagebirdtest .WillReturn ([]byte ("" ), http .StatusNoContent )
72
- client := messagebirdtest .Client (t )
71
+ mbtest .WillReturn ([]byte ("" ), http .StatusNoContent )
72
+ client := mbtest .Client (t )
73
73
74
74
if err := Delete (client , "contact-id" ); err != nil {
75
75
t .Fatalf ("unexpected error deleting Contact: %s" , err )
76
76
}
77
77
78
- messagebirdtest .AssertEndpointCalled (t , http .MethodDelete , "/contacts/contact-id" )
78
+ mbtest .AssertEndpointCalled (t , http .MethodDelete , "/contacts/contact-id" )
79
79
}
80
80
81
81
func TestDeleteWithEmptyID (t * testing.T ) {
82
- client := messagebirdtest .Client (t )
82
+ client := mbtest .Client (t )
83
83
84
84
if err := Delete (client , "" ); err == nil {
85
85
t .Fatalf ("expected error, got nil" )
86
86
}
87
87
}
88
88
89
89
func TestList (t * testing.T ) {
90
- messagebirdtest .WillReturnTestdata (t , "contactListObject.json" , http .StatusOK )
91
- client := messagebirdtest .Client (t )
90
+ mbtest .WillReturnTestdata (t , "contactListObject.json" , http .StatusOK )
91
+ client := mbtest .Client (t )
92
92
93
93
list , err := List (client , DefaultListOptions )
94
94
if err != nil {
@@ -123,11 +123,11 @@ func TestList(t *testing.T) {
123
123
t .Fatalf ("expected second-id, got %s" , list .Items [1 ].ID )
124
124
}
125
125
126
- messagebirdtest .AssertEndpointCalled (t , http .MethodGet , "/contacts" )
126
+ mbtest .AssertEndpointCalled (t , http .MethodGet , "/contacts" )
127
127
}
128
128
129
129
func TestListPagination (t * testing.T ) {
130
- client := messagebirdtest .Client (t )
130
+ client := mbtest .Client (t )
131
131
132
132
tt := []struct {
133
133
expected string
@@ -141,22 +141,22 @@ func TestListPagination(t *testing.T) {
141
141
for _ , tc := range tt {
142
142
List (client , tc .options )
143
143
144
- if query := messagebirdtest .Request .URL .RawQuery ; query != tc .expected {
144
+ if query := mbtest .Request .URL .RawQuery ; query != tc .expected {
145
145
t .Fatalf ("expected %s, got %s" , tc .expected , query )
146
146
}
147
147
}
148
148
}
149
149
150
150
func TestRead (t * testing.T ) {
151
- messagebirdtest .WillReturnTestdata (t , "contactObject.json" , http .StatusOK )
152
- client := messagebirdtest .Client (t )
151
+ mbtest .WillReturnTestdata (t , "contactObject.json" , http .StatusOK )
152
+ client := mbtest .Client (t )
153
153
154
154
contact , err := Read (client , "contact-id" )
155
155
if err != nil {
156
156
t .Fatalf ("unexpected error reading Contact: %s" , err )
157
157
}
158
158
159
- messagebirdtest .AssertEndpointCalled (t , http .MethodGet , "/contacts/contact-id" )
159
+ mbtest .AssertEndpointCalled (t , http .MethodGet , "/contacts/contact-id" )
160
160
161
161
if contact .ID != "contact-id" {
162
162
t .Fatalf ("expected contact-id, got %s" , contact .ID )
@@ -206,15 +206,15 @@ func TestRead(t *testing.T) {
206
206
}
207
207
208
208
func TestReadWithCustomDetails (t * testing.T ) {
209
- messagebirdtest .WillReturnTestdata (t , "contactObjectWithCustomDetails.json" , http .StatusOK )
210
- client := messagebirdtest .Client (t )
209
+ mbtest .WillReturnTestdata (t , "contactObjectWithCustomDetails.json" , http .StatusOK )
210
+ client := mbtest .Client (t )
211
211
212
212
contact , err := Read (client , "contact-id" )
213
213
if err != nil {
214
214
t .Fatalf ("unexpected error reading Contact with custom details: %s" , err )
215
215
}
216
216
217
- messagebirdtest .AssertEndpointCalled (t , http .MethodGet , "/contacts/contact-id" )
217
+ mbtest .AssertEndpointCalled (t , http .MethodGet , "/contacts/contact-id" )
218
218
219
219
if contact .CustomDetails .Custom1 != "First" {
220
220
t .Fatalf ("expected First, got %s" , contact .CustomDetails .Custom1 )
@@ -234,7 +234,7 @@ func TestReadWithCustomDetails(t *testing.T) {
234
234
}
235
235
236
236
func TestUpdate (t * testing.T ) {
237
- client := messagebirdtest .Client (t )
237
+ client := mbtest .Client (t )
238
238
239
239
tt := []struct {
240
240
expectedTestdata string
@@ -250,7 +250,7 @@ func TestUpdate(t *testing.T) {
250
250
t .Fatalf ("unexpected error updating Contact: %s\n " , err )
251
251
}
252
252
253
- messagebirdtest .AssertEndpointCalled (t , http .MethodPatch , "/contacts/contact-id" )
254
- messagebirdtest .AssertTestdata (t , tc .expectedTestdata , messagebirdtest .Request .Body )
253
+ mbtest .AssertEndpointCalled (t , http .MethodPatch , "/contacts/contact-id" )
254
+ mbtest .AssertTestdata (t , tc .expectedTestdata , mbtest .Request .Body )
255
255
}
256
256
}
0 commit comments