From fd812092630e1782228b1b7cf9648553013dea17 Mon Sep 17 00:00:00 2001 From: Nedyalko Andreev Date: Wed, 12 Jul 2023 17:01:28 +0300 Subject: [PATCH] Rename test loading helpers to make their local nature explicit --- cmd/archive.go | 2 +- cmd/cloud.go | 2 +- cmd/inspect.go | 2 +- cmd/run.go | 11 +++++++++-- cmd/test_load.go | 6 +++--- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cmd/archive.go b/cmd/archive.go index 24bddf5ff498..bb3dfbcb5683 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 edc124e69f1e..9712d335b6e9 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 8d963633909b..de646ab5440d 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 d6172921f61f..953869912a64 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 6dd1d6b66651..86e1d815b2cb 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 }