Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/cli/docs/generated/errors-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ The `galasactl` tool can generate the following errors:
- GAL1270E: Failed to get tags from the Galasa service. Unexpected http status code {} received from the server. Error details from the server are: '{}'
- GAL1271E: Failed to get tags from the Galasa service. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
- GAL1272E: Failed to get tags from the Galasa service. Sending the put request to the Galasa service failed. Cause is {}
- GAL1273E: Invalid update request. The tag '{}' cannot be added and deleted in the same command.
- GAL1274E: Invalid update request. The flag '{}' must be used when attempting to update a run.
- GAL2000W: Warning: Maven configuration file settings.xml should contain a reference to a Galasa repository so that the galasa OBR can be resolved. The official release repository is '{}', and 'pre-release' repository is '{}'
- GAL2501I: Downloaded {} artifacts to folder '{}'

Expand Down
1 change: 1 addition & 0 deletions modules/cli/docs/generated/galasactl_runs.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ Assembles, submits and monitors test runs in Galasa Ecosystem
* [galasactl runs prepare](galasactl_runs_prepare.md) - prepares a list of tests
* [galasactl runs reset](galasactl_runs_reset.md) - reset an active run in the ecosystem
* [galasactl runs submit](galasactl_runs_submit.md) - submit a list of tests to the ecosystem
* [galasactl runs update](galasactl_runs_update.md) - Update the record of an existing test run on a Galasa service.

35 changes: 35 additions & 0 deletions modules/cli/docs/generated/galasactl_runs_update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## galasactl runs update

Update the record of an existing test run on a Galasa service.

### Synopsis

Update the record of an existing test run on a Galasa service.

```
galasactl runs update [flags]
```

### Options

```
--add-tags strings comma-separated list of tags to add
-h, --help Displays the options for the 'runs update' command.
--name string the name of the test run we want to update
--remove-tags strings comma-separated list of tags to remove
```

### Options inherited from parent commands

```
-b, --bootstrap string Bootstrap URL. Should start with 'http://' or 'file://'. If it starts with neither, it is assumed to be a fully-qualified path. If missing, it defaults to use the 'bootstrap.properties' file in your GALASA_HOME. Example: http://example.com/bootstrap, file:///user/myuserid/.galasa/bootstrap.properties , file://C:/Users/myuserid/.galasa/bootstrap.properties
--galasahome string Path to a folder where Galasa will read and write files and configuration settings. The default is '${HOME}/.galasa'. This overrides the GALASA_HOME environment variable which may be set instead.
-l, --log string File to which log information will be sent. Any folder referred to must exist. An existing file will be overwritten. Specify "-" to log to stderr. Defaults to not logging.
--rate-limit-retries int The maximum number of retries that should be made when requests to the Galasa Service fail due to rate limits being exceeded. Must be a whole number. Defaults to 3 retries (default 3)
--rate-limit-retry-backoff-secs float The amount of time in seconds to wait before retrying a command if it failed due to rate limits being exceeded. Defaults to 1 second. (default 1)
```

### SEE ALSO

* [galasactl runs](galasactl_runs.md) - Manage test runs in the ecosystem

10 changes: 8 additions & 2 deletions modules/cli/pkg/cmd/commandCollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
COMMAND_NAME_RUNS_SUBMIT = "runs submit"
COMMAND_NAME_RUNS_SUBMIT_LOCAL = "runs submit local"
COMMAND_NAME_RUNS_RESET = "runs reset"
COMMAND_NAME_RUNS_UPDATE = "runs update"
COMMAND_NAME_RUNS_CANCEL = "runs cancel"
COMMAND_NAME_RUNS_CLEANUP = "runs cleanup"
COMMAND_NAME_RUNS_CLEANUP_LOCAL = "runs cleanup local"
Expand Down Expand Up @@ -344,6 +345,7 @@ func (commands *commandCollectionImpl) addRunsCommands(factory spi.Factory, root
var runsSubmitCommand spi.GalasaCommand
var runsSubmitLocalCommand spi.GalasaCommand
var runsResetCommand spi.GalasaCommand
var runsUpdateCommand spi.GalasaCommand
var runsCancelCommand spi.GalasaCommand
var runsDeleteCommand spi.GalasaCommand
var runsCleanupCommand spi.GalasaCommand
Expand All @@ -363,9 +365,12 @@ func (commands *commandCollectionImpl) addRunsCommands(factory spi.Factory, root
if err == nil {
runsResetCommand, err = NewRunsResetCommand(factory, runsCommand, commsFlagSet)
if err == nil {
runsCancelCommand, err = NewRunsCancelCommand(factory, runsCommand, commsFlagSet)
runsUpdateCommand, err = NewRunsUpdateCommand(factory, runsCommand, commsFlagSet)
if err == nil {
runsDeleteCommand, err = NewRunsDeleteCommand(factory, runsCommand, commsFlagSet)
runsCancelCommand, err = NewRunsCancelCommand(factory, runsCommand, commsFlagSet)
if err == nil {
runsDeleteCommand, err = NewRunsDeleteCommand(factory, runsCommand, commsFlagSet)
}
}
}
}
Expand All @@ -389,6 +394,7 @@ func (commands *commandCollectionImpl) addRunsCommands(factory spi.Factory, root
commands.commandMap[runsSubmitCommand.Name()] = runsSubmitCommand
commands.commandMap[runsSubmitLocalCommand.Name()] = runsSubmitLocalCommand
commands.commandMap[runsResetCommand.Name()] = runsResetCommand
commands.commandMap[runsUpdateCommand.Name()] = runsUpdateCommand
commands.commandMap[runsCancelCommand.Name()] = runsCancelCommand
commands.commandMap[runsDeleteCommand.Name()] = runsDeleteCommand
commands.commandMap[runsCleanupCommand.Name()] = runsCleanupCommand
Expand Down
143 changes: 143 additions & 0 deletions modules/cli/pkg/cmd/runsUpdate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package cmd

import (
"github.com/galasa-dev/cli/pkg/api"
"github.com/galasa-dev/cli/pkg/runs"
"github.com/galasa-dev/cli/pkg/spi"
"github.com/galasa-dev/cli/pkg/utils"
"github.com/spf13/cobra"
)

// Objective: Allow the user to do this:
// runs update --name U12345 --add-tags tag1,tag2 --remove-tags tag3

// Variables set by cobra's command-line parsing.
type RunsUpdateCmdValues struct {
runName string
addTags []string
removeTags []string
}

type RunsUpdateCommand struct {
values *RunsUpdateCmdValues
cobraCommand *cobra.Command
}

func NewRunsUpdateCommand(factory spi.Factory, runsCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) (spi.GalasaCommand, error) {
cmd := new(RunsUpdateCommand)
err := cmd.init(factory, runsCommand, commsFlagSet)
return cmd, err
}

// ------------------------------------------------------------------------------------------------
// Public methods
// ------------------------------------------------------------------------------------------------
func (cmd *RunsUpdateCommand) Name() string {
return COMMAND_NAME_RUNS_UPDATE
}

func (cmd *RunsUpdateCommand) CobraCommand() *cobra.Command {
return cmd.cobraCommand
}

func (cmd *RunsUpdateCommand) Values() interface{} {
return cmd.values
}

// ------------------------------------------------------------------------------------------------
// Private methods
// ------------------------------------------------------------------------------------------------
func (cmd *RunsUpdateCommand) init(factory spi.Factory, runsCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) error {
var err error
cmd.values = &RunsUpdateCmdValues{}
cmd.cobraCommand, err = cmd.createCobraCommand(factory, runsCommand, commsFlagSet.Values().(*CommsFlagSetValues))
return err
}

func (cmd *RunsUpdateCommand) createCobraCommand(
factory spi.Factory,
runsCommand spi.GalasaCommand,
commsFlagSetValues *CommsFlagSetValues,
) (*cobra.Command, error) {

var err error

runsUpdateCobraCmd := &cobra.Command{
Use: "update",
Short: "Update the record of an existing test run on a Galasa service.",
Long: "Update the record of an existing test run on a Galasa service.",
Args: cobra.NoArgs,
Aliases: []string{"runs update"},
RunE: func(cobraCmd *cobra.Command, args []string) error {
return cmd.executeRunsUpdate(factory, commsFlagSetValues)
},
}

runsUpdateCobraCmd.Flags().StringVar(&cmd.values.runName, "name", "", "the name of the test run we want to update")
runsUpdateCobraCmd.MarkFlagRequired("name")

runsUpdateCobraCmd.Flags().StringSliceVar(&cmd.values.addTags, "add-tags", nil, "Comma-separated list of tags to add. Multiple uses of this flag are permitted.")
runsUpdateCobraCmd.Flags().StringSliceVar(&cmd.values.removeTags, "remove-tags", nil, "Comma-separated list of tags to remove. Multiple uses of this flag are permitted.")

runsCommand.CobraCommand().AddCommand(runsUpdateCobraCmd)

return runsUpdateCobraCmd, err
}

func (cmd *RunsUpdateCommand) executeRunsUpdate(
factory spi.Factory,
commsFlagSetValues *CommsFlagSetValues,
) error {

var err error

// Operations on the file system will all be relative to the current folder.
fileSystem := factory.GetFileSystem()

err = utils.CaptureLog(fileSystem, commsFlagSetValues.logFileName)
if err == nil {
commsFlagSetValues.isCapturingLogs = true

// Get the ability to query environment variables.
env := factory.GetEnvironment()

var galasaHome spi.GalasaHome
galasaHome, err = utils.NewGalasaHome(fileSystem, env, commsFlagSetValues.CmdParamGalasaHomePath)
if err == nil {

var commsClient api.APICommsClient
commsClient, err = api.NewAPICommsClient(
commsFlagSetValues.bootstrap,
commsFlagSetValues.maxRetries,
commsFlagSetValues.retryBackoffSeconds,
factory,
galasaHome,
)

if err == nil {

var console = factory.GetStdOutConsole()
byteReader := factory.GetByteReader()
timeService := factory.GetTimeService()

// Call to process the command in a unit-testable way.
err = runs.RunsUpdate(
cmd.values.runName,
cmd.values.addTags,
cmd.values.removeTags,
console,
commsClient,
timeService,
byteReader,
)
}
}
}

return err
}
Loading