Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2/2] Make k6 cloud run --local-execution upload test archive #3931

Merged
merged 12 commits into from
Sep 13, 2024
Prev Previous commit
Next Next commit
Apply pull request review suggestions
  • Loading branch information
oleiade committed Sep 11, 2024
commit dffb25f84fffe5072ab9cd919da5fd8aa5e8e525
19 changes: 16 additions & 3 deletions cmd/cloud_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package cmd
import (
"fmt"

"go.k6.io/k6/errext/exitcodes"

"go.k6.io/k6/errext"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.k6.io/k6/execution"
Expand Down Expand Up @@ -93,18 +97,27 @@ Use the "k6 cloud login" command to authenticate.`,
func (c *cmdCloudRun) preRun(cmd *cobra.Command, args []string) error {
if c.localExecution {
if cmd.Flags().Changed("exit-on-running") {
return fmt.Errorf("the --local-execution flag is not compatible with the --exit-on-running flag")
return errext.WithExitCodeIfNone(
fmt.Errorf("the --local-execution flag is not compatible with the --exit-on-running flag"),
exitcodes.InvalidConfig,
)
}

if cmd.Flags().Changed("show-logs") {
return fmt.Errorf("the --local-execution flag is not compatible with the --show-logs flag")
return errext.WithExitCodeIfNone(
fmt.Errorf("the --local-execution flag is not compatible with the --show-logs flag"),
exitcodes.InvalidConfig,
)
}

return nil
}

if c.linger {
return fmt.Errorf("the --linger flag can only be used in conjunction with the --local-execution flag")
return errext.WithExitCodeIfNone(
fmt.Errorf("the --linger flag can only be used in conjunction with the --local-execution flag"),
exitcodes.InvalidConfig,
)
}

return c.deprecatedCloudCmd.preRun(cmd, args)
Expand Down
4 changes: 3 additions & 1 deletion cmd/tests/cmd_cloud_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tests
import (
"testing"

"go.k6.io/k6/errext/exitcodes"

"github.com/stretchr/testify/assert"
"go.k6.io/k6/cmd"
)
Expand Down Expand Up @@ -48,7 +50,7 @@ func TestCloudRunCommandIncompatibleFlags(t *testing.T) {
t.Parallel()

ts := getSimpleCloudTestState(t, nil, setupK6CloudRunCmd, tc.cliArgs, nil, nil)
ts.ExpectedExitCode = -1
ts.ExpectedExitCode = int(exitcodes.InvalidConfig)
cmd.ExecuteWithGlobalState(ts.GlobalState)

stderr := ts.Stderr.String()
Expand Down