diff --git a/js/modules/k6/execution/execution_test.go b/js/modules/k6/execution/execution_test.go index a822e6d7eeb..f949be4344c 100644 --- a/js/modules/k6/execution/execution_test.go +++ b/js/modules/k6/execution/execution_test.go @@ -211,7 +211,7 @@ func TestOptionsTestFull(t *testing.T) { Tags: map[string]string{ "tagkey": "tagvalue", }, - Options: executor.ScenarioOptions{ + Options: lib.ScenarioOptions{ Browser: map[string]any{ "someOption": true, }, diff --git a/lib/executor/base_config.go b/lib/executor/base_config.go index 9c20e9f91f6..bcb8c3ce5af 100644 --- a/lib/executor/base_config.go +++ b/lib/executor/base_config.go @@ -8,6 +8,7 @@ import ( "gopkg.in/guregu/null.v3" + "go.k6.io/k6/lib" "go.k6.io/k6/lib/consts" "go.k6.io/k6/lib/types" ) @@ -20,22 +21,16 @@ var DefaultGracefulStopValue = 30 * time.Second //nolint:gochecknoglobals var executorNameWhitelist = regexp.MustCompile(`^[0-9a-zA-Z_-]+$`) //nolint:gochecknoglobals const executorNameErr = "the executor name should contain only numbers, latin letters, underscores, and dashes" -// ScenarioOptions are options specific to a scenario. These include k6 browser -// options, which are validated by the browser module, and not by k6 core. -type ScenarioOptions struct { - Browser map[string]any `json:"browser"` -} - // BaseConfig contains the common config fields for all executors type BaseConfig struct { - Name string `json:"-"` // set via the JS object key - Type string `json:"executor"` - StartTime types.NullDuration `json:"startTime"` - GracefulStop types.NullDuration `json:"gracefulStop"` - Env map[string]string `json:"env"` - Exec null.String `json:"exec"` // function name, externally validated - Tags map[string]string `json:"tags"` - Options ScenarioOptions `json:"options"` + Name string `json:"-"` // set via the JS object key + Type string `json:"executor"` + StartTime types.NullDuration `json:"startTime"` + GracefulStop types.NullDuration `json:"gracefulStop"` + Env map[string]string `json:"env"` + Exec null.String `json:"exec"` // function name, externally validated + Tags map[string]string `json:"tags"` + Options lib.ScenarioOptions `json:"options"` // TODO: future extensions like distribution, others? } @@ -116,6 +111,11 @@ func (bc BaseConfig) GetExec() string { return exec } +// GetScenarioOptions returns the options specific to a scenario. +func (bc BaseConfig) GetScenarioOptions() *lib.ScenarioOptions { + return &bc.Options +} + // GetTags returns any custom tags configured for the executor. func (bc BaseConfig) GetTags() map[string]string { return bc.Tags diff --git a/lib/executors.go b/lib/executors.go index 725345c4016..ae50a907fe7 100644 --- a/lib/executors.go +++ b/lib/executors.go @@ -80,6 +80,7 @@ type ExecutorConfig interface { // execution, including any extensions caused by waiting for iterations to // finish with graceful stops or ramp-downs. GetExecutionRequirements(*ExecutionTuple) []ExecutionStep + GetScenarioOptions() *ScenarioOptions // Return a human-readable description of the executor GetDescription(*ExecutionTuple) string @@ -90,6 +91,12 @@ type ExecutorConfig interface { HasWork(*ExecutionTuple) bool } +// ScenarioOptions are options specific to a scenario. These include k6 browser +// options, which are validated by the browser module, and not by k6 core. +type ScenarioOptions struct { + Browser map[string]any `json:"browser"` +} + // ScenarioState holds runtime scenario information returned by the k6/execution // JS module. type ScenarioState struct {