Skip to content

Commit fd81209

Browse files
committed
Rename test loading helpers to make their local nature explicit
1 parent a7e26ad commit fd81209

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

cmd/archive.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type cmdArchive struct {
1616
}
1717

1818
func (c *cmdArchive) run(cmd *cobra.Command, args []string) error {
19-
test, err := loadAndConfigureTest(c.gs, cmd, args, getPartialConfig)
19+
test, err := loadAndConfigureLocalTest(c.gs, cmd, args, getPartialConfig)
2020
if err != nil {
2121
return err
2222
}

cmd/cloud.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error {
8484
)
8585
printBar(c.gs, progressBar)
8686

87-
test, err := loadAndConfigureTest(c.gs, cmd, args, getPartialConfig)
87+
test, err := loadAndConfigureLocalTest(c.gs, cmd, args, getPartialConfig)
8888
if err != nil {
8989
return err
9090
}

cmd/inspect.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func getCmdInspect(gs *state.GlobalState) *cobra.Command {
2121
Long: `Inspect a script or archive.`,
2222
Args: cobra.ExactArgs(1),
2323
RunE: func(cmd *cobra.Command, args []string) error {
24-
test, err := loadTest(gs, cmd, args)
24+
test, err := loadLocalTest(gs, cmd, args)
2525
if err != nil {
2626
return err
2727
}

cmd/run.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ import (
4040
// cmdRun handles the `k6 run` sub-command
4141
type cmdRun struct {
4242
gs *state.GlobalState
43+
44+
// TODO: figure out something more elegant?
45+
loadConfiguredTest func(cmd *cobra.Command, args []string) (*loadedAndConfiguredTest, execution.Controller, error)
4346
}
4447

4548
const (
@@ -101,7 +104,7 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
101104
c.gs.Events.UnsubscribeAll()
102105
}()
103106

104-
test, err := loadAndConfigureTest(c.gs, cmd, args, getConfig)
107+
test, controller, err := c.loadConfiguredTest(cmd, args)
105108
if err != nil {
106109
return err
107110
}
@@ -133,7 +136,7 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
133136

134137
// Create a local execution scheduler wrapping the runner.
135138
logger.Debug("Initializing the execution scheduler...")
136-
execScheduler, err := execution.NewScheduler(testRunState, local.NewController())
139+
execScheduler, err := execution.NewScheduler(testRunState, controller)
137140
if err != nil {
138141
return err
139142
}
@@ -460,6 +463,10 @@ func (c *cmdRun) setupTracerProvider(ctx context.Context, test *loadedAndConfigu
460463
func getCmdRun(gs *state.GlobalState) *cobra.Command {
461464
c := &cmdRun{
462465
gs: gs,
466+
loadConfiguredTest: func(cmd *cobra.Command, args []string) (*loadedAndConfiguredTest, execution.Controller, error) {
467+
test, err := loadAndConfigureLocalTest(gs, cmd, args, getConfig)
468+
return test, local.NewController(), err
469+
},
463470
}
464471

465472
exampleText := getExampleText(gs, `

cmd/test_load.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type loadedTest struct {
4141
keyLogger io.Closer
4242
}
4343

44-
func loadTest(gs *state.GlobalState, cmd *cobra.Command, args []string) (*loadedTest, error) {
44+
func loadLocalTest(gs *state.GlobalState, cmd *cobra.Command, args []string) (*loadedTest, error) {
4545
if len(args) < 1 {
4646
return nil, fmt.Errorf("k6 needs at least one argument to load the test")
4747
}
@@ -236,11 +236,11 @@ type loadedAndConfiguredTest struct {
236236
derivedConfig Config
237237
}
238238

239-
func loadAndConfigureTest(
239+
func loadAndConfigureLocalTest(
240240
gs *state.GlobalState, cmd *cobra.Command, args []string,
241241
cliConfigGetter func(flags *pflag.FlagSet) (Config, error),
242242
) (*loadedAndConfiguredTest, error) {
243-
test, err := loadTest(gs, cmd, args)
243+
test, err := loadLocalTest(gs, cmd, args)
244244
if err != nil {
245245
return nil, err
246246
}

0 commit comments

Comments
 (0)