Skip to content

Commit

Permalink
Rename test loading helpers to make their local nature explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
na-- committed Dec 13, 2023
1 parent a7e26ad commit fd81209
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 9 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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, `
Expand Down
6 changes: 3 additions & 3 deletions cmd/test_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit fd81209

Please sign in to comment.