Skip to content

Commit

Permalink
Prevent panic on not providing second argument to check (#2387)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Feb 17, 2022
1 parent bba59df commit 737dfa7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions js/modules/k6/k6.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ func (mi *K6) Check(arg0, checks goja.Value, extras ...goja.Value) (bool, error)
if state == nil {
return false, ErrCheckInInitContext
}
if checks == nil {
return false, errors.New("no checks provided to `check`")
}
ctx := mi.vu.Context()
rt := mi.vu.Runtime()
t := time.Now()
Expand Down
10 changes: 10 additions & 0 deletions js/modules/k6/k6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ func TestCheckLiteral(t *testing.T) {
assert.Len(t, stats.GetBufferedSamples(samples), 0)
}

func TestCheckNull(t *testing.T) {
t.Parallel()
rt, samples, _ := checkTestRuntime(t)

_, err := rt.RunString(`k6.check(5)`)
require.Error(t, err)
assert.Contains(t, err.Error(), "no checks provided")
assert.Len(t, stats.GetBufferedSamples(samples), 0)
}

func TestCheckThrows(t *testing.T) {
t.Parallel()
rt, samples, builtinMetrics := checkTestRuntime(t)
Expand Down

0 comments on commit 737dfa7

Please sign in to comment.