Skip to content

Commit dec77b0

Browse files
authored
Skip binary provisioning for the run command (#4731)
1 parent 2fea117 commit dec77b0

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

internal/cmd/launcher.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,20 @@ func NewLauncher(gs *state.GlobalState) *Launcher {
5656
func (l *Launcher) Launch() {
5757
// If binary provisioning is not enabled, continue with the regular k6 execution path
5858
if !l.gs.Flags.BinaryProvisioning {
59-
l.gs.Logger.Debug("Binary provisioning feature is disabled")
59+
l.gs.Logger.Debug("Binary provisioning feature is disabled.")
6060
l.commandExecutor.run(l.gs)
6161
return
6262
}
6363

64-
l.gs.Logger.Info("Binary provisioning feature is enabled. If it's required, k6 will provision a new binary")
64+
l.gs.Logger.
65+
Debug("Binary provisioning feature is enabled.")
6566

6667
deps, err := analyze(l.gs, l.gs.CmdArgs[1:])
6768
if err != nil {
6869
l.gs.Logger.
6970
WithError(err).
70-
Error("Failed to analyze the required dependencies. Please, make sure to report this issue by" +
71-
" opening a bug report.")
71+
Error("Binary provisioning is enabled but it failed to analyze the dependencies." +
72+
" Please, make sure to report this issue by opening a bug report.")
7273
l.gs.OSExit(1)
7374
return // this is required for testing
7475
}
@@ -84,14 +85,14 @@ func (l *Launcher) Launch() {
8485

8586
l.gs.Logger.
8687
WithField("deps", deps).
87-
Info("The current k6 binary doesn't satisfy all the required dependencies, it is required to" +
88-
" provision a new binary.")
88+
Info("The current k6 binary doesn't satisfy all dependencies, it is required to" +
89+
" provision a custom binary.")
8990

9091
customBinary, err := l.provision(l.gs, deps)
9192
if err != nil {
9293
l.gs.Logger.
9394
WithError(err).
94-
Error("Failed to provision a new k6 binary with required dependencies." +
95+
Error("Failed to provision a k6 binary with required dependencies." +
9596
" Please, make sure to report this issue by opening a bug report.")
9697
l.gs.OSExit(1)
9798
return
@@ -194,7 +195,7 @@ func k6buildProvision(gs *state.GlobalState, deps k6deps.Dependencies) (commandE
194195
}
195196

196197
if config.BuildServiceAuth == "" {
197-
return nil, errors.New("k6 cloud token is required when Binary provisioning feature is enabled." +
198+
return nil, errors.New("k6 cloud token is required when the Binary provisioning feature is enabled." +
198199
" Set K6_CLOUD_TOKEN environment variable or execute the `k6 cloud login` command")
199200
}
200201

@@ -249,6 +250,8 @@ func analyze(gs *state.GlobalState, args []string) (k6deps.Dependencies, error)
249250
}
250251

251252
if !isScriptRequired(args) {
253+
gs.Logger.
254+
Debug("The command to execute does not require Binary provisioning")
252255
return k6deps.Dependencies{}, nil
253256
}
254257

@@ -300,7 +303,7 @@ func isScriptRequired(args []string) bool {
300303
}
301304
}
302305
return true
303-
case "run", "archive", "inspect":
306+
case "archive", "inspect":
304307
return true
305308
}
306309
}

internal/cmd/launcher_test.go

+34-16
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestLauncherLaunch(t *testing.T) {
9090
}{
9191
{
9292
name: "disable binary provisioning",
93-
k6Cmd: "run",
93+
k6Cmd: "cloud",
9494
disableBP: true,
9595
script: fakerTest,
9696
expectProvision: false,
@@ -100,7 +100,7 @@ func TestLauncherLaunch(t *testing.T) {
100100
},
101101
{
102102
name: "execute binary provisioned",
103-
k6Cmd: "run",
103+
k6Cmd: "cloud",
104104
script: fakerTest,
105105
expectProvision: true,
106106
expectK6Run: true,
@@ -109,7 +109,7 @@ func TestLauncherLaunch(t *testing.T) {
109109
},
110110
{
111111
name: "require unsatisfied k6 version",
112-
k6Cmd: "run",
112+
k6Cmd: "cloud",
113113
script: requireUnsatisfiedK6Version,
114114
expectProvision: true,
115115
expectK6Run: true,
@@ -118,7 +118,7 @@ func TestLauncherLaunch(t *testing.T) {
118118
},
119119
{
120120
name: "require satisfied k6 version",
121-
k6Cmd: "run",
121+
k6Cmd: "cloud",
122122
script: requireSatisfiedK6Version,
123123
expectProvision: false,
124124
expectK6Run: false,
@@ -127,7 +127,7 @@ func TestLauncherLaunch(t *testing.T) {
127127
},
128128
{
129129
name: "script with no dependencies",
130-
k6Cmd: "run",
130+
k6Cmd: "cloud",
131131
script: noDepsTest,
132132
expectProvision: false,
133133
expectK6Run: false,
@@ -143,8 +143,16 @@ func TestLauncherLaunch(t *testing.T) {
143143
expectOsExit: 0,
144144
},
145145
{
146-
name: "failed binary provisioning",
146+
name: "binary provisioning is not enabled for run command",
147147
k6Cmd: "run",
148+
expectProvision: false,
149+
expectK6Run: false,
150+
expectDefault: true,
151+
expectOsExit: 0,
152+
},
153+
{
154+
name: "failed binary provisioning",
155+
k6Cmd: "cloud",
148156
script: fakerTest,
149157
provisionError: errors.New("test error"),
150158
expectProvision: true,
@@ -154,7 +162,7 @@ func TestLauncherLaunch(t *testing.T) {
154162
},
155163
{
156164
name: "failed k6 execution",
157-
k6Cmd: "run",
165+
k6Cmd: "cloud",
158166
script: fakerTest,
159167
k6ReturnCode: 108,
160168
expectProvision: true,
@@ -164,7 +172,7 @@ func TestLauncherLaunch(t *testing.T) {
164172
},
165173
{
166174
name: "missing input script",
167-
k6Cmd: "run",
175+
k6Cmd: "cloud",
168176
k6Args: []string{},
169177
script: "",
170178
expectProvision: false,
@@ -174,7 +182,7 @@ func TestLauncherLaunch(t *testing.T) {
174182
},
175183
{
176184
name: "script in stdin",
177-
k6Cmd: "run",
185+
k6Cmd: "cloud",
178186
k6Args: []string{"-"},
179187
script: "",
180188
expectProvision: false,
@@ -314,7 +322,7 @@ func TestScriptNameFromArgs(t *testing.T) {
314322
},
315323
{
316324
name: "complex case with multiple flags",
317-
args: []string{"-v", "--quiet", "run", "-o", "output.json", "--console-output", "loadtest.log", "script.js", "--tag", "env=staging"},
325+
args: []string{"-v", "--quiet", "cloud", "run", "-o", "output.json", "--console-output", "loadtest.log", "script.js", "--tag", "env=staging"},
318326
expected: "script.js",
319327
},
320328
{
@@ -370,26 +378,36 @@ func TestIsScriptRequired(t *testing.T) {
370378
{
371379
name: "run command",
372380
args: []string{"run", "script.js"},
381+
expected: false,
382+
},
383+
{
384+
name: "cloud command",
385+
args: []string{"cloud", "script.js"},
386+
expected: true,
387+
},
388+
{
389+
name: "cloud run command",
390+
args: []string{"cloud", "run", "script.js"},
373391
expected: true,
374392
},
375393
{
376394
name: "flag before command",
377-
args: []string{"-v", "run", "script.js"},
395+
args: []string{"-v", "cloud", "script.js"},
378396
expected: true,
379397
},
380398
{
381399
name: "verbose flag before command",
382-
args: []string{"--verbose", "run", "script.js"},
400+
args: []string{"--verbose", "cloud", "script.js"},
383401
expected: true,
384402
},
385403
{
386404
name: "cloud run with flag in the middle",
387-
args: []string{"cloud", "-v", "run", "archive.tar"},
405+
args: []string{"cloud", "-v", "cloud", "archive.tar"},
388406
expected: true,
389407
},
390408
{
391-
name: "cloud command",
392-
args: []string{"cloud", "script.js"},
409+
name: "cloud upload command",
410+
args: []string{"cloud", "upload", "script.js"},
393411
expected: true,
394412
},
395413
{
@@ -409,7 +427,7 @@ func TestIsScriptRequired(t *testing.T) {
409427
},
410428
{
411429
name: "complex case with multiple flags",
412-
args: []string{"-v", "--quiet", "run", "-o", "output.json", "--console-output", "loadtest.log", "script.js", "--tag", "env=staging"},
430+
args: []string{"-v", "--quiet", "cloud", "run", "-o", "output.json", "--console-output", "loadtest.log", "script.js", "--tag", "env=staging"},
413431
expected: true,
414432
},
415433
}

0 commit comments

Comments
 (0)