Skip to content

Commit 205fc66

Browse files
committed
Rename package messagebirdtest to mbtest
1 parent 7dccb97 commit 205fc66

File tree

13 files changed

+96
-98
lines changed

13 files changed

+96
-98
lines changed

balance/balance_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66

77
messagebird "github.com/messagebird/go-rest-api"
8-
"github.com/messagebird/go-rest-api/internal/messagebirdtest"
8+
"github.com/messagebird/go-rest-api/internal/mbtest"
99
)
1010

1111
const Epsilon float32 = 0.001
@@ -15,12 +15,12 @@ func cmpFloat32(a, b float32) bool {
1515
}
1616

1717
func TestMain(m *testing.M) {
18-
messagebirdtest.EnableServer(m)
18+
mbtest.EnableServer(m)
1919
}
2020

2121
func TestRead(t *testing.T) {
22-
messagebirdtest.WillReturnTestdata(t, "balance.json", http.StatusOK)
23-
client := messagebirdtest.Client(t)
22+
mbtest.WillReturnTestdata(t, "balance.json", http.StatusOK)
23+
client := mbtest.Client(t)
2424

2525
balance, err := Read(client)
2626
if err != nil {
@@ -41,8 +41,8 @@ func TestRead(t *testing.T) {
4141
}
4242

4343
func TestReadError(t *testing.T) {
44-
messagebirdtest.WillReturnAccessKeyError()
45-
client := messagebirdtest.Client(t)
44+
mbtest.WillReturnAccessKeyError()
45+
client := mbtest.Client(t)
4646

4747
_, err := Read(client)
4848

contact/contact_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ import (
55
"testing"
66
"time"
77

8-
"github.com/messagebird/go-rest-api/internal/messagebirdtest"
8+
"github.com/messagebird/go-rest-api/internal/mbtest"
99
)
1010

1111
func TestMain(m *testing.M) {
12-
messagebirdtest.EnableServer(m)
12+
mbtest.EnableServer(m)
1313
}
1414

1515
func TestCreateWithEmptyMSISDN(t *testing.T) {
16-
client := messagebirdtest.Client(t)
16+
client := mbtest.Client(t)
1717

1818
if _, err := Create(client, &Request{}); err == nil {
1919
t.Fatalf("expected error, got nil")
2020
}
2121
}
2222

2323
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)
2626

2727
contact, err := Create(client, &Request{
2828
MSISDN: "31612345678",
@@ -35,8 +35,8 @@ func TestCreate(t *testing.T) {
3535
t.Fatalf("unexpected error creating Contact: %s", err)
3636
}
3737

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)
4040

4141
if contact.MSISDN != 31612345678 {
4242
t.Fatalf("expected 31612345678, got %d", contact.MSISDN)
@@ -68,27 +68,27 @@ func TestCreate(t *testing.T) {
6868
}
6969

7070
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)
7373

7474
if err := Delete(client, "contact-id"); err != nil {
7575
t.Fatalf("unexpected error deleting Contact: %s", err)
7676
}
7777

78-
messagebirdtest.AssertEndpointCalled(t, http.MethodDelete, "/contacts/contact-id")
78+
mbtest.AssertEndpointCalled(t, http.MethodDelete, "/contacts/contact-id")
7979
}
8080

8181
func TestDeleteWithEmptyID(t *testing.T) {
82-
client := messagebirdtest.Client(t)
82+
client := mbtest.Client(t)
8383

8484
if err := Delete(client, ""); err == nil {
8585
t.Fatalf("expected error, got nil")
8686
}
8787
}
8888

8989
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)
9292

9393
list, err := List(client, DefaultListOptions)
9494
if err != nil {
@@ -123,11 +123,11 @@ func TestList(t *testing.T) {
123123
t.Fatalf("expected second-id, got %s", list.Items[1].ID)
124124
}
125125

126-
messagebirdtest.AssertEndpointCalled(t, http.MethodGet, "/contacts")
126+
mbtest.AssertEndpointCalled(t, http.MethodGet, "/contacts")
127127
}
128128

129129
func TestListPagination(t *testing.T) {
130-
client := messagebirdtest.Client(t)
130+
client := mbtest.Client(t)
131131

132132
tt := []struct {
133133
expected string
@@ -141,22 +141,22 @@ func TestListPagination(t *testing.T) {
141141
for _, tc := range tt {
142142
List(client, tc.options)
143143

144-
if query := messagebirdtest.Request.URL.RawQuery; query != tc.expected {
144+
if query := mbtest.Request.URL.RawQuery; query != tc.expected {
145145
t.Fatalf("expected %s, got %s", tc.expected, query)
146146
}
147147
}
148148
}
149149

150150
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)
153153

154154
contact, err := Read(client, "contact-id")
155155
if err != nil {
156156
t.Fatalf("unexpected error reading Contact: %s", err)
157157
}
158158

159-
messagebirdtest.AssertEndpointCalled(t, http.MethodGet, "/contacts/contact-id")
159+
mbtest.AssertEndpointCalled(t, http.MethodGet, "/contacts/contact-id")
160160

161161
if contact.ID != "contact-id" {
162162
t.Fatalf("expected contact-id, got %s", contact.ID)
@@ -206,15 +206,15 @@ func TestRead(t *testing.T) {
206206
}
207207

208208
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)
211211

212212
contact, err := Read(client, "contact-id")
213213
if err != nil {
214214
t.Fatalf("unexpected error reading Contact with custom details: %s", err)
215215
}
216216

217-
messagebirdtest.AssertEndpointCalled(t, http.MethodGet, "/contacts/contact-id")
217+
mbtest.AssertEndpointCalled(t, http.MethodGet, "/contacts/contact-id")
218218

219219
if contact.CustomDetails.Custom1 != "First" {
220220
t.Fatalf("expected First, got %s", contact.CustomDetails.Custom1)
@@ -234,7 +234,7 @@ func TestReadWithCustomDetails(t *testing.T) {
234234
}
235235

236236
func TestUpdate(t *testing.T) {
237-
client := messagebirdtest.Client(t)
237+
client := mbtest.Client(t)
238238

239239
tt := []struct {
240240
expectedTestdata string
@@ -250,7 +250,7 @@ func TestUpdate(t *testing.T) {
250250
t.Fatalf("unexpected error updating Contact: %s\n", err)
251251
}
252252

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)
255255
}
256256
}

hlr/hlr_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import (
66
"time"
77

88
"github.com/messagebird/go-rest-api"
9-
10-
"github.com/messagebird/go-rest-api/internal/messagebirdtest"
9+
"github.com/messagebird/go-rest-api/internal/mbtest"
1110
)
1211

1312
func TestMain(m *testing.M) {
14-
messagebirdtest.EnableServer(m)
13+
mbtest.EnableServer(m)
1514
}
1615

1716
func assertHLRObject(t *testing.T, hlr *HLR) {
@@ -49,8 +48,8 @@ func assertHLRObject(t *testing.T, hlr *HLR) {
4948
}
5049

5150
func TestRead(t *testing.T) {
52-
messagebirdtest.WillReturnTestdata(t, "hlrObject.json", http.StatusOK)
53-
client := messagebirdtest.Client(t)
51+
mbtest.WillReturnTestdata(t, "hlrObject.json", http.StatusOK)
52+
client := mbtest.Client(t)
5453

5554
hlr, err := Read(client, "27978c50354a93ca0ca8de6h54340177")
5655
if err != nil {
@@ -76,8 +75,8 @@ func TestRequestDataForHLR(t *testing.T) {
7675
}
7776

7877
func TestCreate(t *testing.T) {
79-
messagebirdtest.WillReturnTestdata(t, "hlrObject.json", http.StatusOK)
80-
client := messagebirdtest.Client(t)
78+
mbtest.WillReturnTestdata(t, "hlrObject.json", http.StatusOK)
79+
client := mbtest.Client(t)
8180

8281
hlr, err := Create(client, "31612345678", "MyReference")
8382
if err != nil {
@@ -88,8 +87,8 @@ func TestCreate(t *testing.T) {
8887
}
8988

9089
func TestHLRError(t *testing.T) {
91-
messagebirdtest.WillReturnAccessKeyError()
92-
client := messagebirdtest.Client(t)
90+
mbtest.WillReturnAccessKeyError()
91+
client := mbtest.Client(t)
9392

9493
_, err := Read(client, "dummy_hlr_id")
9594

@@ -112,8 +111,8 @@ func TestHLRError(t *testing.T) {
112111
}
113112

114113
func TestList(t *testing.T) {
115-
messagebirdtest.WillReturnTestdata(t, "hlrListObject.json", http.StatusOK)
116-
client := messagebirdtest.Client(t)
114+
mbtest.WillReturnTestdata(t, "hlrListObject.json", http.StatusOK)
115+
client := mbtest.Client(t)
117116

118117
hlrList, err := List(client)
119118
if err != nil {

internal/mbtest/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package mbtest provides a test server that effectively mocks the
2+
// MessageBird API.
3+
package mbtest

internal/messagebirdtest/helper.go renamed to internal/mbtest/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package messagebirdtest
1+
package mbtest
22

33
import (
44
"bytes"

internal/messagebirdtest/test_client.go renamed to internal/mbtest/test_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package messagebirdtest
1+
package mbtest
22

33
import (
44
"crypto/tls"

internal/messagebirdtest/test_server.go renamed to internal/mbtest/test_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package messagebirdtest
1+
package mbtest
22

33
import (
44
"io/ioutil"

internal/messagebirdtest/doc.go

Lines changed: 0 additions & 3 deletions
This file was deleted.

lookup/lookup_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import (
66
"testing"
77

88
"github.com/messagebird/go-rest-api/hlr"
9-
"github.com/messagebird/go-rest-api/internal/messagebirdtest"
9+
"github.com/messagebird/go-rest-api/internal/mbtest"
1010
)
1111

1212
func TestMain(m *testing.M) {
13-
messagebirdtest.EnableServer(m)
13+
mbtest.EnableServer(m)
1414
}
1515

1616
func TestCreate(t *testing.T) {
17-
messagebirdtest.WillReturnTestdata(t, "lookupObject.json", http.StatusOK)
18-
client := messagebirdtest.Client(t)
17+
mbtest.WillReturnTestdata(t, "lookupObject.json", http.StatusOK)
18+
client := mbtest.Client(t)
1919

2020
phoneNumber := "31624971134"
2121
lookup, err := Create(client, phoneNumber, &Params{CountryCode: "NL"})
@@ -60,8 +60,8 @@ func checkHLR(t *testing.T, hlr *hlr.HLR) {
6060
}
6161

6262
func TestReadHLR(t *testing.T) {
63-
messagebirdtest.WillReturnTestdata(t, "lookupHLRObject.json", http.StatusOK)
64-
client := messagebirdtest.Client(t)
63+
mbtest.WillReturnTestdata(t, "lookupHLRObject.json", http.StatusOK)
64+
client := mbtest.Client(t)
6565

6666
hlr, err := ReadHLR(client, "31624971134", &Params{CountryCode: "NL"})
6767
if err != nil {
@@ -86,8 +86,8 @@ func TestRequestDataForLookupHLR(t *testing.T) {
8686
}
8787

8888
func TestCreateHLR(t *testing.T) {
89-
messagebirdtest.WillReturnTestdata(t, "lookupHLRObject.json", http.StatusCreated)
90-
client := messagebirdtest.Client(t)
89+
mbtest.WillReturnTestdata(t, "lookupHLRObject.json", http.StatusCreated)
90+
client := mbtest.Client(t)
9191

9292
hlr, err := CreateHLR(client, "31624971134", &Params{CountryCode: "NL", Reference: "reference2000"})
9393
if err != nil {

0 commit comments

Comments
 (0)