Skip to content

Commit 647311a

Browse files
authored
refactor(context): refactor context handling and improve test robustness (#4066)
Use assert.InDelta for float comparison with tolerance in TestContextGetFloat32 Remove unnecessary blank line in TestContextInitQueryCache Replace anonymous struct with named contextKey type in TestContextWithFallbackValueFromRequestContext Update context key handling in TestContextWithFallbackValueFromRequestContext to use contextKey type
1 parent 299c6f3 commit 647311a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ func (c *Context) ShouldBindBodyWithTOML(obj any) error {
951951
return c.ShouldBindBodyWith(obj, binding.TOML)
952952
}
953953

954-
// ShouldBindBodyWithJSON is a shortcut for c.ShouldBindBodyWith(obj, binding.JSON).
954+
// ShouldBindBodyWithPlain is a shortcut for c.ShouldBindBodyWith(obj, binding.Plain).
955955
func (c *Context) ShouldBindBodyWithPlain(obj any) error {
956956
return c.ShouldBindBodyWith(obj, binding.Plain)
957957
}

context_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func TestContextGetFloat32(t *testing.T) {
323323
key := "float32"
324324
value := float32(3.14)
325325
c.Set(key, value)
326-
assert.Equal(t, value, c.GetFloat32(key))
326+
assert.InDelta(t, value, c.GetFloat32(key), 0.01)
327327
}
328328

329329
func TestContextGetFloat64(t *testing.T) {
@@ -2857,7 +2857,8 @@ func TestContextWithFallbackValueFromRequestContext(t *testing.T) {
28572857
{
28582858
name: "c with struct context key",
28592859
getContextAndKey: func() (*Context, any) {
2860-
var key struct{}
2860+
type KeyStruct struct{} // https://staticcheck.dev/docs/checks/#SA1029
2861+
var key KeyStruct
28612862
c, _ := CreateTestContext(httptest.NewRecorder())
28622863
// enable ContextWithFallback feature flag
28632864
c.engine.ContextWithFallback = true

0 commit comments

Comments
 (0)