Skip to content

Commit

Permalink
Fix panic on http.batch()
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Mar 8, 2022
1 parent fea17a1 commit c31e840
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions js/modules/k6/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ func (c *Client) Batch(reqsV goja.Value) (interface{}, error) {
results interface{} // either []*Response or map[string]*Response
)

if reqsV == nil {
return nil, errors.New("no argument was provided to http.batch()")
}
switch v := reqsV.Export().(type) {
case []interface{}:
batchReqs, results, err = c.prepareBatchArray(v)
Expand Down
14 changes: 13 additions & 1 deletion js/modules/k6/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,19 @@ func TestRequestAndBatch(t *testing.T) {
throw bool
}{
{
name: "invalid arg", code: `"https://somevalidurl.com"`,
name: "no arg", code: ``,
expErr: `no argument was provided to http.batch()`, throw: true,
},
{
name: "invalid null arg", code: `null`,
expErr: `invalid http.batch() argument type <nil>`, throw: true,
},
{
name: "invalid undefined arg", code: `undefined`,
expErr: `invalid http.batch() argument type <nil>`, throw: true,
},
{
name: "invalid string arg", code: `"https://somevalidurl.com"`,
expErr: `invalid http.batch() argument type string`, throw: true,
},
{
Expand Down

0 comments on commit c31e840

Please sign in to comment.