Skip to content

Commit

Permalink
add nil check and test
Browse files Browse the repository at this point in the history
  • Loading branch information
mitulagr2 committed Nov 23, 2024
1 parent ec07efc commit d2f7db5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ func New() *Client {

// NewWithClient creates and returns a new Client object from an existing client.
func NewWithClient(c *fasthttp.Client) *Client {
if c == nil {
panic("fasthttp.Client must not be nil")
}
return &Client{
fasthttp: c,
header: &Header{
Expand Down
22 changes: 17 additions & 5 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,24 @@ func startTestServerWithPort(t *testing.T, beforeStarting func(app *fiber.App))
func Test_New_With_Client(t *testing.T) {
t.Parallel()

c := &fasthttp.Client{
MaxConnsPerHost: 5,
}
client := NewWithClient(c)
t.Run("with valid client", func(t *testing.T) {
t.Parallel()

c := &fasthttp.Client{
MaxConnsPerHost: 5,
}
client := NewWithClient(c)

require.NotNil(t, client)
})

require.NotNil(t, client)
t.Run("with nil client", func(t *testing.T) {
t.Parallel()

require.PanicsWithValue(t, "fasthttp.Client must not be nil", func() {
NewWithClient(nil)
})
})
}

func Test_Client_Add_Hook(t *testing.T) {
Expand Down

0 comments on commit d2f7db5

Please sign in to comment.