diff --git a/cmd/archive.go b/cmd/archive.go index 24bddf5ff49..bb3dfbcb568 100644 --- a/cmd/archive.go +++ b/cmd/archive.go @@ -16,7 +16,7 @@ type cmdArchive struct { } func (c *cmdArchive) run(cmd *cobra.Command, args []string) error { - test, err := loadAndConfigureTest(c.gs, cmd, args, getPartialConfig) + test, err := loadAndConfigureLocalTest(c.gs, cmd, args, getPartialConfig) if err != nil { return err } diff --git a/cmd/cloud.go b/cmd/cloud.go index edc124e69f1..9712d335b6e 100644 --- a/cmd/cloud.go +++ b/cmd/cloud.go @@ -84,7 +84,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { ) printBar(c.gs, progressBar) - test, err := loadAndConfigureTest(c.gs, cmd, args, getPartialConfig) + test, err := loadAndConfigureLocalTest(c.gs, cmd, args, getPartialConfig) if err != nil { return err } diff --git a/cmd/inspect.go b/cmd/inspect.go index 8d963633909..de646ab5440 100644 --- a/cmd/inspect.go +++ b/cmd/inspect.go @@ -21,7 +21,7 @@ func getCmdInspect(gs *state.GlobalState) *cobra.Command { Long: `Inspect a script or archive.`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - test, err := loadTest(gs, cmd, args) + test, err := loadLocalTest(gs, cmd, args) if err != nil { return err } diff --git a/cmd/run.go b/cmd/run.go index d6172921f61..953869912a6 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -40,6 +40,9 @@ import ( // cmdRun handles the `k6 run` sub-command type cmdRun struct { gs *state.GlobalState + + // TODO: figure out something more elegant? + loadConfiguredTest func(cmd *cobra.Command, args []string) (*loadedAndConfiguredTest, execution.Controller, error) } const ( @@ -101,7 +104,7 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) { c.gs.Events.UnsubscribeAll() }() - test, err := loadAndConfigureTest(c.gs, cmd, args, getConfig) + test, controller, err := c.loadConfiguredTest(cmd, args) if err != nil { return err } @@ -133,7 +136,7 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) { // Create a local execution scheduler wrapping the runner. logger.Debug("Initializing the execution scheduler...") - execScheduler, err := execution.NewScheduler(testRunState, local.NewController()) + execScheduler, err := execution.NewScheduler(testRunState, controller) if err != nil { return err } @@ -460,6 +463,10 @@ func (c *cmdRun) setupTracerProvider(ctx context.Context, test *loadedAndConfigu func getCmdRun(gs *state.GlobalState) *cobra.Command { c := &cmdRun{ gs: gs, + loadConfiguredTest: func(cmd *cobra.Command, args []string) (*loadedAndConfiguredTest, execution.Controller, error) { + test, err := loadAndConfigureLocalTest(gs, cmd, args, getConfig) + return test, local.NewController(), err + }, } exampleText := getExampleText(gs, ` diff --git a/cmd/test_load.go b/cmd/test_load.go index 6dd1d6b6665..86e1d815b2c 100644 --- a/cmd/test_load.go +++ b/cmd/test_load.go @@ -41,7 +41,7 @@ type loadedTest struct { keyLogger io.Closer } -func loadTest(gs *state.GlobalState, cmd *cobra.Command, args []string) (*loadedTest, error) { +func loadLocalTest(gs *state.GlobalState, cmd *cobra.Command, args []string) (*loadedTest, error) { if len(args) < 1 { return nil, fmt.Errorf("k6 needs at least one argument to load the test") } @@ -236,11 +236,11 @@ type loadedAndConfiguredTest struct { derivedConfig Config } -func loadAndConfigureTest( +func loadAndConfigureLocalTest( gs *state.GlobalState, cmd *cobra.Command, args []string, cliConfigGetter func(flags *pflag.FlagSet) (Config, error), ) (*loadedAndConfiguredTest, error) { - test, err := loadTest(gs, cmd, args) + test, err := loadLocalTest(gs, cmd, args) if err != nil { return nil, err }