Skip to content

Commit 9fe62d8

Browse files
committed
Change order of assertions (expected, actual -> actual, expected): https://github.com/golang/go/wiki/CodeReviewComments#useful-test-failures
1 parent ac7da2c commit 9fe62d8

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

group/group_test.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ func TestCreate(t *testing.T) {
2525
mbtest.AssertTestdata(t, "groupRequestCreateObject.json", mbtest.Request.Body)
2626

2727
if group.Name != "Friends" {
28-
t.Fatalf("expected Friends, got %s", group.Name)
28+
t.Fatalf("got %s, expected Friends", group.Name)
2929
}
3030
}
3131

3232
func TestCreateWithEmptyName(t *testing.T) {
3333
client := mbtest.Client(t)
3434

3535
if _, err := Create(client, &Request{""}); err == nil {
36-
t.Fatalf("expected error, got nil")
36+
t.Fatalf("got nil, expected error")
3737
}
3838
}
3939

@@ -58,31 +58,31 @@ func TestList(t *testing.T) {
5858
}
5959

6060
if list.Offset != 0 {
61-
t.Fatalf("expected 0, got %d", list.Offset)
61+
t.Fatalf("got %d, expected 0", list.Offset)
6262
}
6363

6464
if list.Limit != 10 {
65-
t.Fatalf("expected 10, got %d", list.Limit)
65+
t.Fatalf("got %d, expected 10", list.Limit)
6666
}
6767

6868
if list.Count != 2 {
69-
t.Fatalf("expected 2, got %d", list.Count)
69+
t.Fatalf("got %d, expected 2", list.Count)
7070
}
7171

7272
if list.TotalCount != 2 {
73-
t.Fatalf("expected 2, got %d", list.TotalCount)
73+
t.Fatalf("got %d, expected 2", list.TotalCount)
7474
}
7575

7676
if actualCount := len(list.Items); actualCount != 2 {
77-
t.Fatalf("expected 2, got %d", actualCount)
77+
t.Fatalf("got %d, expected 2", actualCount)
7878
}
7979

8080
if list.Items[0].ID != "first-id" {
81-
t.Fatalf("expected first-id, got %s", list.Items[0].ID)
81+
t.Fatalf("got %s, expected first-id", list.Items[0].ID)
8282
}
8383

8484
if list.Items[1].ID != "second-id" {
85-
t.Fatalf("expected second-id, got %s", list.Items[1].ID)
85+
t.Fatalf("got %s, expected second-id", list.Items[1].ID)
8686
}
8787

8888
mbtest.AssertEndpointCalled(t, http.MethodGet, "/groups")
@@ -104,7 +104,7 @@ func TestListPagination(t *testing.T) {
104104
List(client, tc.options)
105105

106106
if query := mbtest.Request.URL.RawQuery; query != tc.expected {
107-
t.Fatalf("expected %s, got %s", tc.expected, query)
107+
t.Fatalf("got %s, expected %s", tc.expected, query)
108108
}
109109
}
110110
}
@@ -121,31 +121,31 @@ func TestRead(t *testing.T) {
121121
mbtest.AssertEndpointCalled(t, http.MethodGet, "/groups/group-id")
122122

123123
if group.ID != "group-id" {
124-
t.Fatalf("expected group-id, got %s", group.ID)
124+
t.Fatalf("got %s, expected group-id", group.ID)
125125
}
126126

127127
if group.HRef != "https://rest.messagebird.com/groups/group-id" {
128-
t.Fatalf("expected https://rest.messagebird.com/groups/group-id, got %s", group.HRef)
128+
t.Fatalf("got %s, expected https://rest.messagebird.com/groups/group-id", group.HRef)
129129
}
130130

131131
if group.Name != "Friends" {
132-
t.Fatalf("expected Friends, got %s", group.Name)
132+
t.Fatalf("got %s, expected Friends", group.Name)
133133
}
134134

135135
if group.Contacts.TotalCount != 3 {
136-
t.Fatalf("expected 3, got %d", group.Contacts.TotalCount)
136+
t.Fatalf("got %d, expected 3", group.Contacts.TotalCount)
137137
}
138138

139139
if group.Contacts.HRef != "https://rest.messagebird.com/groups/group-id" {
140-
t.Fatalf("expected https://rest.messagebird.com/groups/group-id, got %s", group.Contacts.HRef)
140+
t.Fatalf("got %s, expected https://rest.messagebird.com/groups/group-id", group.Contacts.HRef)
141141
}
142142

143143
if created, _ := time.Parse(time.RFC3339, "2018-07-25T12:16:10+00:00"); !created.Equal(group.CreatedDatetime) {
144-
t.Fatalf("expected 2018-07-25T12:16:10+00:00, got %s", group.CreatedDatetime)
144+
t.Fatalf("got %s, expected 2018-07-25T12:16:10+00:00", group.CreatedDatetime)
145145
}
146146

147147
if updated, _ := time.Parse(time.RFC3339, "2018-07-25T12:16:23+00:00"); !updated.Equal(group.UpdatedDatetime) {
148-
t.Fatalf("expected 2018-07-25T12:16:23+00:00, got %s", group.UpdatedDatetime)
148+
t.Fatalf("got %s, expected 2018-07-25T12:16:23+00:00", group.UpdatedDatetime)
149149
}
150150
}
151151

@@ -172,7 +172,7 @@ func TestAddContacts(t *testing.T) {
172172
mbtest.AssertEndpointCalled(t, http.MethodGet, "/groups/group-id/contacts")
173173

174174
if mbtest.Request.URL.RawQuery != "_method=PUT&ids[]=first-contact-id&ids[]=second-contact-id" {
175-
t.Fatalf("expected _method=PUT&ids[]=first-contact-id&ids[]=second-contact-id, got %s", mbtest.Request.URL.RawQuery)
175+
t.Fatalf("got %s, expected _method=PUT&ids[]=first-contact-id&ids[]=second-contact-id", mbtest.Request.URL.RawQuery)
176176
}
177177
}
178178

@@ -188,7 +188,7 @@ func TestAddContactsWithEmptyContacts(t *testing.T) {
188188

189189
for _, tc := range tt {
190190
if err := AddContacts(client, "group-id", tc.contactIDs); err == nil {
191-
t.Fatalf("expected error, got nil")
191+
t.Fatalf("got nil, expected error")
192192
}
193193
}
194194
}
@@ -200,7 +200,7 @@ func TestAddContactsWithTooManyContacts(t *testing.T) {
200200
contactIDs := make([]string, 51)
201201

202202
if err := AddContacts(client, "group-id", contactIDs); err == nil {
203-
t.Fatalf("expected error, got nil")
203+
t.Fatalf("got nil, expected error")
204204
}
205205
}
206206

@@ -214,31 +214,31 @@ func TestListContacts(t *testing.T) {
214214
}
215215

216216
if list.Offset != 0 {
217-
t.Fatalf("expected 0, got %d", list.Offset)
217+
t.Fatalf("got %d, expected 0", list.Offset)
218218
}
219219

220220
if list.Limit != 20 {
221-
t.Fatalf("expected 20, got %d", list.Limit)
221+
t.Fatalf("got %d, expected 20", list.Limit)
222222
}
223223

224224
if list.Count != 3 {
225-
t.Fatalf("expected 3, got %d", list.Count)
225+
t.Fatalf("got %d, expected 3", list.Count)
226226
}
227227

228228
if list.TotalCount != 3 {
229-
t.Fatalf("expected 3, got %d", list.TotalCount)
229+
t.Fatalf("got %d, expected 3", list.TotalCount)
230230
}
231231

232232
if list.Items[0].ID != "first-contact-id" {
233-
t.Fatalf("expected first-contact-id, got %s", list.Items[0].ID)
233+
t.Fatalf("got %s, expected first-contact-id", list.Items[0].ID)
234234
}
235235

236236
if list.Items[1].ID != "second-contact-id" {
237-
t.Fatalf("expected second-contact-id, got %s", list.Items[1].ID)
237+
t.Fatalf("got %s, expected second-contact-id", list.Items[1].ID)
238238
}
239239

240240
if list.Items[2].ID != "third-contact-id" {
241-
t.Fatalf("expected third-contact-id, got %s", list.Items[2].ID)
241+
t.Fatalf("got %s, expected third-contact-id", list.Items[2].ID)
242242
}
243243

244244
mbtest.AssertEndpointCalled(t, http.MethodGet, "/groups/group-id/contacts")

0 commit comments

Comments
 (0)