Skip to content

Commit

Permalink
Refactor cloud run command and tests to leverage existing code
Browse files Browse the repository at this point in the history
  • Loading branch information
oleiade committed Jul 23, 2024
1 parent 3965239 commit 2b0bc1f
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 798 deletions.
29 changes: 16 additions & 13 deletions cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import (
"time"

"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"go.k6.io/k6/cloudapi"
"go.k6.io/k6/cmd/state"
"go.k6.io/k6/errext"
"go.k6.io/k6/errext/exitcodes"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/ui/pb"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"go.k6.io/k6/cmd/state"
)

// cmdCloud handles the `k6 cloud` sub-command
Expand All @@ -34,7 +35,6 @@ type cmdCloud struct {
uploadOnly bool
}

//nolint:dupl // function duplicated from the deprecated `k6 cloud` command, stmt can go when the command is remove
func (c *cmdCloud) preRun(cmd *cobra.Command, _ []string) error {
// TODO: refactor (https:/loadimpact/k6/issues/883)
//
Expand Down Expand Up @@ -119,7 +119,10 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error {
return err
}
if !cloudConfig.Token.Valid {
return errors.New("Not logged in, please use `k6 cloud login`") //nolint:golint,stylecheck
return errors.New( //nolint:golint
"not logged in, please login to the Grafana Cloud k6 " +
"using the \"k6 cloud login\" command",
)
}

// Display config warning if needed
Expand Down Expand Up @@ -345,20 +348,20 @@ func getCmdCloud(gs *state.GlobalState) *cobra.Command {
}

exampleText := getExampleText(gs, `
# [deprecated] Run a k6 script in the Grafana Cloud k6
$ {{.}} cloud script.js
# [deprecated] Run a k6 archive in the Grafana Cloud k6
$ {{.}} cloud archive.tar
# Authenticate with Grafana Cloud k6
$ {{.}} cloud login
# Run a k6 script in the Grafana Cloud k6
$ {{.}} cloud run script.js
# Run a k6 archive in the Grafana Cloud k6
$ {{.}} cloud run archive.tar
# [deprecated] Run a k6 script in the Grafana Cloud k6
$ {{.}} cloud script.js
# [deprecated] Run a k6 archive in the Grafana Cloud k6
$ {{.}} cloud archive.tar`[1:])
$ {{.}} cloud run archive.tar`[1:])

cloudCmd := &cobra.Command{
Use: "cloud",
Expand Down
Loading

0 comments on commit 2b0bc1f

Please sign in to comment.