Skip to content

Commit

Permalink
Refactor Drop method and extend test coverage.
Browse files Browse the repository at this point in the history
Simplified the Drop method by inlining the connection close call. Added new test cases to ensure proper handling of no-response scenarios and improved overall test coverage.
  • Loading branch information
ryanbekhen committed Dec 20, 2024
1 parent e4bede2 commit f0528ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,6 @@ func (c *DefaultCtx) setRoute(route *Route) {
}

func (c *DefaultCtx) Drop() error {
conn := c.RequestCtx().Conn()
//nolint:wrapcheck // This must not be wrapped
return conn.Close()
return c.RequestCtx().Conn().Close()
}
15 changes: 15 additions & 0 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5852,13 +5852,28 @@ func Test_Ctx_Drop(t *testing.T) {
t.Parallel()

app := New()

// Handler that calls Drop
app.Get("/block-me", func(c Ctx) error {
return c.Drop()
})

// Additional handler that just calls return
app.Get("/no-response", func(c Ctx) error {

Check failure on line 5862 in ctx_test.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'c' seems to be unused, consider removing or renaming it as _ (revive)
return nil
})

// Test the Drop method
resp, err := app.Test(httptest.NewRequest(MethodGet, "/block-me", nil))
require.Error(t, err)
require.Nil(t, resp)

// Test the no-response handler
resp, err = app.Test(httptest.NewRequest(MethodGet, "/no-response", nil))
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, 200, resp.StatusCode)
require.Equal(t, "0", resp.Header.Get("Content-Length"))
}

// go test -run Test_GenericParseTypeString
Expand Down

0 comments on commit f0528ad

Please sign in to comment.