forked from grafana/k6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot_test.go
38 lines (31 loc) · 934 Bytes
/
root_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package cmd
import (
"testing"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"go.k6.io/k6/cmd/tests"
"go.k6.io/k6/errext/exitcodes"
"go.k6.io/k6/lib/testutils"
)
func TestMain(m *testing.M) {
tests.Main(m)
}
func TestPanicHandling(t *testing.T) {
t.Parallel()
ts := tests.NewGlobalTestState(t)
ts.CmdArgs = []string{"k6", "panic"}
ts.ExpectedExitCode = int(exitcodes.GoPanic)
rootCmd := newRootCommand(ts.GlobalState)
rootCmd.cmd.AddCommand(&cobra.Command{
Use: "panic",
RunE: func(_ *cobra.Command, _ []string) error {
panic("oh no, oh no, oh no,no,no,no,no")
},
})
rootCmd.execute()
t.Log(ts.Stderr.String())
logMsgs := ts.LoggerHook.Drain()
assert.True(t, testutils.LogContains(logMsgs, logrus.ErrorLevel, "unexpected k6 panic: oh no"))
assert.True(t, testutils.LogContains(logMsgs, logrus.ErrorLevel, "cmd.TestPanicHandling")) // check stacktrace
}