diff --git a/cmd/tests/cmd_run_test.go b/cmd/tests/cmd_run_test.go index 321fb896f25..7a21424ccf2 100644 --- a/cmd/tests/cmd_run_test.go +++ b/cmd/tests/cmd_run_test.go @@ -2073,7 +2073,7 @@ func TestEventSystemOK(t *testing.T) { `got event IterStart with data '{Iteration:4 VUID:1 ScenarioName:default Error:}'`, `got event IterEnd with data '{Iteration:4 VUID:1 ScenarioName:default Error:}'`, `got event TestEnd with data ''`, - `got event TestSummaryGenerated with data '&{Summary:map[stdout:]}'`, + `got event TestSummaryGenerated with data '&{Summary:map[...]...}'`, `got event Exit with data '&{Error:}'`, } log := ts.LoggerHook.Lines() @@ -2108,7 +2108,7 @@ func TestEventSystemError(t *testing.T) { "got event IterStart with data '{Iteration:0 VUID:1 ScenarioName:default Error:}'", "got event IterEnd with data '{Iteration:0 VUID:1 ScenarioName:default Error:test aborted: oops! at file:///-:11:16(6)}'", "got event TestEnd with data ''", - "got event TestSummaryGenerated with data '&{Summary:map[stdout:]}'", + "got event TestSummaryGenerated with data '&{Summary:map[...]...}'", "got event Exit with data '&{Error:test aborted: oops! at file:///-:11:16(6)}'", "test aborted: oops! at file:///-:11:16(6)", }, @@ -2145,7 +2145,7 @@ func TestEventSystemError(t *testing.T) { "got event IterEnd with data '{Iteration:1 VUID:1 ScenarioName:default Error:Error: oops!\n\tat file:///-:9:11(3)\n}'", "Error: oops!\n\tat file:///-:9:11(3)\n", "got event TestEnd with data ''", - "got event TestSummaryGenerated with data '&{Summary:map[stdout:]}'", + "got event TestSummaryGenerated with data '&{Summary:map[...]...}'", "got event Exit with data '&{Error:}'", }, expExitCode: 0, diff --git a/event/type.go b/event/type.go index dcc4bdc0a7e..bfbddf95bca 100644 --- a/event/type.go +++ b/event/type.go @@ -1,6 +1,5 @@ package event - // Type represents the different event types emitted by k6. // //go:generate enumer -type=Type -trimprefix Type -output type_gen.go @@ -49,3 +48,8 @@ type IterData struct { type SummaryData struct { Summary map[string]interface{} } + +// Overiding for tests +func (s *SummaryData) String() string { + return "&{Summary:map[...]...}" +} diff --git a/js/runner.go b/js/runner.go index a704debed1c..316ba222670 100644 --- a/js/runner.go +++ b/js/runner.go @@ -362,7 +362,9 @@ func (r *Runner) IsExecutable(name string) bool { } // HandleSummary calls the specified summary callback, if supplied. -func (r *Runner) HandleSummary(ctx context.Context, summary *lib.Summary) (map[string]io.Reader,map[string]interface{}, error) { +func (r *Runner) HandleSummary(ctx context.Context, summary *lib.Summary) ( + map[string]io.Reader, map[string]interface{}, error, +) { summaryDataForJS := summarizeMetricsToObject(summary, r.Bundle.Options, r.setupData) out := make(chan metrics.SampleContainer, 100) @@ -378,7 +380,7 @@ func (r *Runner) HandleSummary(ctx context.Context, summary *lib.Summary) (map[s vu, err := r.newVU(summaryCtx, 0, 0, out) if err != nil { - return nil,nil, err + return nil, nil, err } go func() { @@ -392,7 +394,7 @@ func (r *Runner) HandleSummary(ctx context.Context, summary *lib.Summary) (map[s if fn != nil { handleSummaryFn, ok := goja.AssertFunction(fn) if !ok { - return nil,nil, fmt.Errorf("exported identifier %s must be a function", consts.HandleSummaryFn) + return nil, nil, fmt.Errorf("exported identifier %s must be a function", consts.HandleSummaryFn) } callbackResult, _, _, err = vu.runFn(summaryCtx, false, handleSummaryFn, nil, vu.Runtime.ToValue(summaryDataForJS)) @@ -405,11 +407,11 @@ func (r *Runner) HandleSummary(ctx context.Context, summary *lib.Summary) (map[s wrapper := strings.Replace(summaryWrapperLambdaCode, "/*JSLIB_SUMMARY_CODE*/", jslibSummaryCode, 1) handleSummaryWrapperRaw, err := vu.Runtime.RunString(wrapper) if err != nil { - return nil,nil, fmt.Errorf("unexpected error while getting the summary wrapper: %w", err) + return nil, nil, fmt.Errorf("unexpected error while getting the summary wrapper: %w", err) } handleSummaryWrapper, ok := goja.AssertFunction(handleSummaryWrapperRaw) if !ok { - return nil,nil, fmt.Errorf("unexpected error did not get a callable summary wrapper") + return nil, nil, fmt.Errorf("unexpected error did not get a callable summary wrapper") } wrapperArgs := []goja.Value{ @@ -420,14 +422,14 @@ func (r *Runner) HandleSummary(ctx context.Context, summary *lib.Summary) (map[s rawResult, _, _, err := vu.runFn(summaryCtx, false, handleSummaryWrapper, nil, wrapperArgs...) if deadlineError := r.checkDeadline(summaryCtx, consts.HandleSummaryFn, rawResult, err); deadlineError != nil { - return nil,nil, deadlineError + return nil, nil, deadlineError } if err != nil { - return nil,nil, fmt.Errorf("unexpected error while generating the summary: %w", err) + return nil, nil, fmt.Errorf("unexpected error while generating the summary: %w", err) } res, err := getSummaryResult(rawResult) - return res,summaryDataForJS, err + return res, summaryDataForJS, err } func (r *Runner) checkDeadline(ctx context.Context, name string, result goja.Value, err error) error { diff --git a/js/summary_test.go b/js/summary_test.go index 93b614e32de..be86047633e 100644 --- a/js/summary_test.go +++ b/js/summary_test.go @@ -62,7 +62,7 @@ func TestTextSummary(t *testing.T) { ) require.NoError(t, err) - result, err := runner.HandleSummary(context.Background(), summary) + result, _, err := runner.HandleSummary(context.Background(), summary) require.NoError(t, err) require.Len(t, result, 1) @@ -116,7 +116,7 @@ func TestTextSummaryWithSubMetrics(t *testing.T) { ) require.NoError(t, err) - result, err := runner.HandleSummary(context.Background(), summary) + result, _, err := runner.HandleSummary(context.Background(), summary) require.NoError(t, err) require.Len(t, result, 1) @@ -307,7 +307,7 @@ func TestOldJSONExport(t *testing.T) { require.NoError(t, err) summary := createTestSummary(t) - result, err := runner.HandleSummary(context.Background(), summary) + result, _, err := runner.HandleSummary(context.Background(), summary) require.NoError(t, err) require.Len(t, result, 2) @@ -577,7 +577,7 @@ func TestRawHandleSummaryData(t *testing.T) { require.NoError(t, err) summary := createTestSummary(t) - result, err := runner.HandleSummary(context.Background(), summary) + result, _, err := runner.HandleSummary(context.Background(), summary) require.NoError(t, err) require.Len(t, result, 2) @@ -612,7 +612,7 @@ func TestRawHandleSummaryDataWithSetupData(t *testing.T) { runner.SetSetupData([]byte("5")) summary := createTestSummary(t) - result, err := runner.HandleSummary(context.Background(), summary) + result, _, err := runner.HandleSummary(context.Background(), summary) require.NoError(t, err) dataWithSetup, err := io.ReadAll(result["dataWithSetup.json"]) require.NoError(t, err) @@ -635,7 +635,7 @@ func TestRawHandleSummaryPromise(t *testing.T) { runner.SetSetupData([]byte("5")) summary := createTestSummary(t) - result, err := runner.HandleSummary(context.Background(), summary) + result, _, err := runner.HandleSummary(context.Background(), summary) require.NoError(t, err) dataWithSetup, err := io.ReadAll(result["dataWithSetup.json"]) require.NoError(t, err) @@ -660,7 +660,7 @@ func TestWrongSummaryHandlerExportTypes(t *testing.T) { require.NoError(t, err) summary := createTestSummary(t) - _, err = runner.HandleSummary(context.Background(), summary) + _, _, err = runner.HandleSummary(context.Background(), summary) require.Error(t, err) }) } @@ -685,7 +685,7 @@ func TestExceptionInHandleSummaryFallsBackToTextSummary(t *testing.T) { require.NoError(t, err) summary := createTestSummary(t) - result, err := runner.HandleSummary(context.Background(), summary) + result, _, err := runner.HandleSummary(context.Background(), summary) require.NoError(t, err) require.Len(t, result, 1) diff --git a/lib/testutils/minirunner/minirunner.go b/lib/testutils/minirunner/minirunner.go index 47e4457e6d1..6d016ef05df 100644 --- a/lib/testutils/minirunner/minirunner.go +++ b/lib/testutils/minirunner/minirunner.go @@ -24,7 +24,7 @@ type MiniRunner struct { Fn func(ctx context.Context, state *lib.State, out chan<- metrics.SampleContainer) error SetupFn func(ctx context.Context, out chan<- metrics.SampleContainer) ([]byte, error) TeardownFn func(ctx context.Context, out chan<- metrics.SampleContainer) error - HandleSummaryFn func(context.Context, *lib.Summary) (map[string]io.Reader, error) + HandleSummaryFn func(context.Context, *lib.Summary) (map[string]io.Reader, map[string]interface{}, error) SetupData []byte @@ -117,11 +117,13 @@ func (r *MiniRunner) SetOptions(opts lib.Options) error { } // HandleSummary calls the specified summary callback, if supplied. -func (r *MiniRunner) HandleSummary(ctx context.Context, s *lib.Summary) (map[string]io.Reader, error) { +func (r *MiniRunner) HandleSummary(ctx context.Context, s *lib.Summary) ( + map[string]io.Reader, map[string]interface{}, error, +) { if r.HandleSummaryFn != nil { return r.HandleSummaryFn(ctx, s) } - return nil, nil //nolint:nilnil + return nil, nil, nil //nolint:nilnilnil } // VU is a mock VU, spawned by a MiniRunner.