Skip to content

Commit 81d7826

Browse files
dylanhittEwenQuim
authored andcommitted
chore: fix reversed require test assertions that were in the wrong order
1 parent d3bc5e3 commit 81d7826

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

ctx_test.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestContext_QueryParam(t *testing.T) {
5151
t.Run("string", func(t *testing.T) {
5252
param := c.QueryParam("other")
5353
require.NotEmpty(t, param)
54-
require.Equal(t, param, "hello")
54+
require.Equal(t, "hello", param)
5555

5656
param = c.QueryParam("notfound")
5757
require.Empty(t, param)
@@ -60,20 +60,20 @@ func TestContext_QueryParam(t *testing.T) {
6060
t.Run("int", func(t *testing.T) {
6161
param := c.QueryParam("id")
6262
require.NotEmpty(t, param)
63-
require.Equal(t, param, "456")
63+
require.Equal(t, "456", param)
6464

6565
paramInt := c.QueryParamInt("id", 0)
66-
require.Equal(t, paramInt, 456)
66+
require.Equal(t, 456, paramInt)
6767

6868
paramInt = c.QueryParamInt("notfound", 42)
69-
require.Equal(t, paramInt, 42)
69+
require.Equal(t, 42, paramInt)
7070

7171
paramInt = c.QueryParamInt("other", 42)
72-
require.Equal(t, paramInt, 42)
72+
require.Equal(t, 42, paramInt)
7373

7474
paramInt, err := c.QueryParamIntErr("id")
7575
require.NoError(t, err)
76-
require.Equal(t, paramInt, 456)
76+
require.Equal(t, 456, paramInt)
7777

7878
paramInt, err = c.QueryParamIntErr("notfound")
7979
require.Error(t, err)
@@ -83,34 +83,34 @@ func TestContext_QueryParam(t *testing.T) {
8383
paramInt, err = c.QueryParamIntErr("other")
8484
require.Error(t, err)
8585
require.Contains(t, err.Error(), "param other=hello is not of type int")
86-
require.Equal(t, paramInt, 0)
86+
require.Equal(t, 0, paramInt)
8787
})
8888

8989
t.Run("bool", func(t *testing.T) {
9090
param := c.QueryParam("boo")
9191
require.NotEmpty(t, param)
92-
require.Equal(t, param, "true")
92+
require.Equal(t, "true", param)
9393

9494
paramBool := c.QueryParamBool("boo", false)
95-
require.Equal(t, paramBool, true)
95+
require.Equal(t, true, paramBool)
9696

9797
paramBool = c.QueryParamBool("notfound", true)
98-
require.Equal(t, paramBool, true)
98+
require.Equal(t, true, paramBool)
9999

100100
paramBool = c.QueryParamBool("other", true)
101-
require.Equal(t, paramBool, true)
101+
require.Equal(t, true, paramBool)
102102

103103
paramBool, err := c.QueryParamBoolErr("boo")
104104
require.NoError(t, err)
105-
require.Equal(t, paramBool, true)
105+
require.Equal(t, true, paramBool)
106106

107107
paramBool, err = c.QueryParamBoolErr("notfound")
108108
require.Error(t, err)
109-
require.Equal(t, paramBool, false)
109+
require.Equal(t, false, paramBool)
110110

111111
paramBool, err = c.QueryParamBoolErr("other")
112112
require.Error(t, err)
113-
require.Equal(t, paramBool, false)
113+
require.Equal(t, false, paramBool)
114114
})
115115
}
116116

@@ -166,8 +166,8 @@ func TestContext_Body(t *testing.T) {
166166

167167
body, err := c.Body()
168168
require.NoError(t, err)
169-
require.Equal(t, body.Name, "John")
170-
require.Equal(t, body.Age, 30)
169+
require.Equal(t, "John", body.Name)
170+
require.Equal(t, 30, body.Age)
171171
})
172172

173173
t.Run("can read JSON body twice", func(t *testing.T) {
@@ -180,13 +180,13 @@ func TestContext_Body(t *testing.T) {
180180

181181
body, err := c.Body()
182182
require.NoError(t, err)
183-
require.Equal(t, body.Name, "John")
184-
require.Equal(t, body.Age, 30)
183+
require.Equal(t, "John", body.Name)
184+
require.Equal(t, 30, body.Age)
185185

186186
body, err = c.Body()
187187
require.NoError(t, err)
188-
require.Equal(t, body.Name, "John")
189-
require.Equal(t, body.Age, 30)
188+
require.Equal(t, "John", body.Name)
189+
require.Equal(t, 30, body.Age)
190190
})
191191

192192
t.Run("can read and validate valid JSON body", func(t *testing.T) {
@@ -203,8 +203,8 @@ func TestContext_Body(t *testing.T) {
203203

204204
body, err := c.Body()
205205
require.NoError(t, err)
206-
require.Equal(t, body.Name, "John")
207-
require.Equal(t, body.Age, 30)
206+
require.Equal(t, "John", body.Name)
207+
require.Equal(t, 30, body.Age)
208208
})
209209

210210
t.Run("can read and validate invalid JSON body", func(t *testing.T) {
@@ -221,8 +221,8 @@ func TestContext_Body(t *testing.T) {
221221

222222
body, err := c.Body()
223223
require.Error(t, err)
224-
require.Equal(t, body.Name, "VeryLongName")
225-
require.Equal(t, body.Age, 12)
224+
require.Equal(t, "VeryLongName", body.Name)
225+
require.Equal(t, 12, body.Age)
226226
})
227227

228228
t.Run("can transform JSON body with custom method", func(t *testing.T) {
@@ -234,8 +234,8 @@ func TestContext_Body(t *testing.T) {
234234

235235
body, err := c.Body()
236236
require.NoError(t, err)
237-
require.Equal(t, body.Name, "transformed John")
238-
require.Equal(t, body.Age, 60)
237+
require.Equal(t, "transformed John", body.Name)
238+
require.Equal(t, 60, body.Age)
239239
})
240240

241241
t.Run("can transform JSON body with custom method returning error", func(t *testing.T) {
@@ -247,8 +247,8 @@ func TestContext_Body(t *testing.T) {
247247

248248
body, err := c.Body()
249249
require.Error(t, err)
250-
require.Equal(t, body.Name, "John")
251-
require.Equal(t, body.Age, 30)
250+
require.Equal(t, "John", body.Name)
251+
require.Equal(t, 30, body.Age)
252252
})
253253

254254
t.Run("can read XML body", func(t *testing.T) {
@@ -412,8 +412,8 @@ func TestContext_MustBody(t *testing.T) {
412412
c := NewContext[testStruct](w, r, readOptions{})
413413

414414
body := c.MustBody()
415-
require.Equal(t, body.Name, "John")
416-
require.Equal(t, body.Age, 30)
415+
require.Equal(t, "John", body.Name)
416+
require.Equal(t, 30, body.Age)
417417
})
418418

419419
t.Run("cannot read invalid JSON body", func(t *testing.T) {

0 commit comments

Comments
 (0)