Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions docs/generated/errors-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ The `galasactl` tool can generate the following errors:
- GAL1238E: Failed to get streams. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
- GAL1239E: Failed to get streams. Unexpected http status code {} received from the server. Error details from the server are: '{}'
- GAL1240E: Failed to get streams. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
- GAL12412E: Failed to delete test stream with the given name from the Galasa service
- GAL1242E: Failed to delete stream {}. Unexpected http status code {} received from the server.
- GAL1243E: Failed to delete stream {}. Unexpected http status code {} received from the server. Error details from the server could not be read. Cause: {}
- GAL1244E: Failed to delete stream {}. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
- GAL1245E: Failed to delete stream {}. Unexpected http status code {} received from the server. Error details from the server are: '{}'
- GAL1246E: Failed to delete stream {}. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
- 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 docs/generated/galasactl_streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ Parent command for managing test streams in a Galasa service
### SEE ALSO

* [galasactl](galasactl.md) - CLI for Galasa
* [galasactl streams delete](galasactl_streams_delete.md) - Deletes a test stream by name
* [galasactl streams get](galasactl_streams_get.md) - Gets a list of test streams

33 changes: 33 additions & 0 deletions docs/generated/galasactl_streams_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## galasactl streams delete

Deletes a test stream by name

### Synopsis

Deletes a single test stream with the given name from the Galasa service

```
galasactl streams delete [flags]
```

### Options

```
-h, --help Displays the options for the 'streams delete' command.
--name string A mandatory field indicating the name of a test stream.
```

### 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 streams](galasactl_streams.md) - Manages test streams in a Galasa service

13 changes: 12 additions & 1 deletion pkg/cmd/commandCollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const (
COMMAND_NAME_ROLES_GET = "roles get"
COMMAND_NAME_STREAMS = "streams"
COMMAND_NAME_STREAMS_GET = "streams get"
COMMAND_NAME_STREAMS_DELETE = "streams delete"
)

// -----------------------------------------------------------------
Expand Down Expand Up @@ -519,14 +520,24 @@ func (commands *commandCollectionImpl) addStreamsCommands(factory spi.Factory, r
var err error
var streamsCommand spi.GalasaCommand
var streamsGetCommand spi.GalasaCommand
var streamsDeleteCommand spi.GalasaCommand

streamsCommand, err = NewStreamsCommand(rootCommand, commsFlagSet)

if err == nil {

commands.commandMap[streamsCommand.Name()] = streamsCommand
streamsGetCommand, err = NewStreamsGetCommand(factory, streamsCommand, commsFlagSet)

if err == nil {
commands.commandMap[streamsCommand.Name()] = streamsCommand

commands.commandMap[streamsGetCommand.Name()] = streamsGetCommand
streamsDeleteCommand, err = NewStreamsDeleteCommand(factory, streamsCommand, commsFlagSet)

if err == nil {
commands.commandMap[streamsDeleteCommand.Name()] = streamsDeleteCommand
}

}
}

Expand Down
149 changes: 149 additions & 0 deletions pkg/cmd/streamsDelete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/

package cmd

import (
"log"

"github.com/galasa-dev/cli/pkg/api"
"github.com/galasa-dev/cli/pkg/galasaapi"
"github.com/galasa-dev/cli/pkg/spi"
"github.com/galasa-dev/cli/pkg/streams"
"github.com/galasa-dev/cli/pkg/utils"
"github.com/spf13/cobra"
)

// Objective: Allow user to do this:
//
// streams delete
type StreamsDeleteCommand struct {
cobraCommand *cobra.Command
}

// ------------------------------------------------------------------------------------------------
// Constructors methods
// ------------------------------------------------------------------------------------------------
func NewStreamsDeleteCommand(
factory spi.Factory,
streamsDeleteCommand spi.GalasaCommand,
commsFlagSet GalasaFlagSet,
) (spi.GalasaCommand, error) {

cmd := new(StreamsDeleteCommand)
err := cmd.init(factory, streamsDeleteCommand, commsFlagSet)
return cmd, err

}

// ------------------------------------------------------------------------------------------------
// Public methods
// ------------------------------------------------------------------------------------------------
func (cmd *StreamsDeleteCommand) Name() string {
return COMMAND_NAME_STREAMS_DELETE
}

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

func (cmd *StreamsDeleteCommand) Values() interface{} {
return nil
}

// ------------------------------------------------------------------------------------------------
// Private methods
// ------------------------------------------------------------------------------------------------

func (cmd *StreamsDeleteCommand) init(factory spi.Factory, streamsCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) error {

var err error

cmd.cobraCommand, err = cmd.createCobraCmd(factory, streamsCommand, commsFlagSet)

return err

}

func (cmd *StreamsDeleteCommand) createCobraCmd(
factory spi.Factory,
streamsCommand spi.GalasaCommand,
commsFlagSet GalasaFlagSet,
) (*cobra.Command, error) {

var err error

commsFlagSetValues := commsFlagSet.Values().(*CommsFlagSetValues)
streamsCommandValues := streamsCommand.Values().(*StreamsCmdValues)

streamsDeleteCobraCmd := &cobra.Command{
Use: "delete",
Short: "Deletes a test stream by name",
Long: "Deletes a single test stream with the given name from the Galasa service",
Aliases: []string{COMMAND_NAME_STREAMS_DELETE},
RunE: func(cobraCommand *cobra.Command, args []string) error {
return cmd.executeStreamsDelete(
factory, streamsCommand.Values().(*StreamsCmdValues), commsFlagSetValues,
)
},
}

addStreamNameFlag(streamsDeleteCobraCmd, true, streamsCommandValues)
streamsCommand.CobraCommand().AddCommand(streamsDeleteCobraCmd)

return streamsDeleteCobraCmd, err

}

func (cmd *StreamsDeleteCommand) executeStreamsDelete(
factory spi.Factory,
streamsCmdValues *StreamsCmdValues,
commsFlagSetValues *CommsFlagSetValues,
) error {

var err error

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

err = utils.CaptureLog(fileSystem, commsFlagSetValues.logFileName)

if err == nil {

commsFlagSetValues.isCapturingLogs = true

log.Println("Galasa CLI - Delete test stream from the Galasa service")

// 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 {
deleteStreamFunc := func(apiClient *galasaapi.APIClient) error {
// Call to process the command in a unit-testable way.
return streams.DeleteStream(streamsCmdValues.name, apiClient, byteReader)
}
err = commsClient.RunAuthenticatedCommandWithRateLimitRetries(deleteStreamFunc)
}
}
}

return err

}
80 changes: 80 additions & 0 deletions pkg/cmd/streamsDelete_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/

package cmd

import (
"testing"

"github.com/galasa-dev/cli/pkg/utils"
"github.com/stretchr/testify/assert"
)

func TestStreamsDeleteCommandInCommandCollectionHasName(t *testing.T) {

factory := utils.NewMockFactory()
commands, _ := NewCommandCollection(factory)

StreamsDeleteCommand, err := commands.GetCommand(COMMAND_NAME_STREAMS_DELETE)
assert.Nil(t, err)

assert.Equal(t, COMMAND_NAME_STREAMS_DELETE, StreamsDeleteCommand.Name())
assert.NotNil(t, StreamsDeleteCommand.CobraCommand())

}

func TestStreamsDeleteHelpFlagSetCorrectly(t *testing.T) {
// Given...
factory := utils.NewMockFactory()

var args []string = []string{"streams", "delete", "--help"}

// When...
err := Execute(factory, args)

// Then...
// Check what the user saw is reasonable.
checkOutput("Displays the options for the 'streams delete' command.", "", factory, t)

assert.Nil(t, err)
}

func TestStreamsDeleteNamespaceNameFlagsReturnsOk(t *testing.T) {
// Given...
factory := utils.NewMockFactory()
commandCollection, _ := setupTestCommandCollection(COMMAND_NAME_STREAMS_DELETE, factory, t)

var args []string = []string{"streams", "delete", "--name", "mystream"}

// When...
err := commandCollection.Execute(args)

// Then...
assert.Nil(t, err)

// Check what the user saw was reasonable
checkOutput("", "", factory, t)

assert.Nil(t, err)
}

func TestStreamsDeleteWithoutNameFlagReturnsError(t *testing.T) {
// Given...
factory := utils.NewMockFactory()
commandCollection, _ := setupTestCommandCollection(COMMAND_NAME_STREAMS_DELETE, factory, t)

var args []string = []string{"streams", "delete"}

// When...
err := commandCollection.Execute(args)

// Then...
assert.NotNil(t, err)

checkOutput("", "Error: required flag(s) \"name\" not set", factory, t)

assert.NotNil(t, err)
}
8 changes: 8 additions & 0 deletions pkg/errors/errorMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ var (
GALASA_ERROR_GET_STREAMS_SERVER_REPORTED_ERROR = NewMessageType("GAL1239E: Failed to get streams. Unexpected http status code %v received from the server. Error details from the server are: '%s'", 1239, STACK_TRACE_NOT_WANTED)
GALASA_ERROR_GET_STREAMS_EXPLANATION_NOT_JSON = NewMessageType("GAL1240E: Failed to get streams. Unexpected http status code %v received from the server. Error details from the server are not in the json format.", 1240, STACK_TRACE_NOT_WANTED)

// Streams delete errors
GALASA_ERROR_FAILED_TO_DELETE_STREAM = NewMessageType("GAL12412E: Failed to delete test stream with the given name from the Galasa service", 1241, STACK_TRACE_NOT_WANTED)
GALASA_ERROR_DELETE_STREAMS_NO_RESPONSE_CONTENT = NewMessageType("GAL1242E: Failed to delete stream %s. Unexpected http status code %v received from the server.", 1242, STACK_TRACE_NOT_WANTED)
GALASA_ERROR_DELETE_STREAMS_RESPONSE_BODY_UNREADABLE = NewMessageType("GAL1243E: Failed to delete stream %s. Unexpected http status code %v received from the server. Error details from the server could not be read. Cause: %s", 1243, STACK_TRACE_NOT_WANTED)
GALASA_ERROR_DELETE_STREAMS_UNPARSEABLE_CONTENT = NewMessageType("GAL1244E: Failed to delete stream %s. Unexpected http status code %v received from the server. Error details from the server are not in a valid json format. Cause: '%s'", 1244, STACK_TRACE_NOT_WANTED)
GALASA_ERROR_DELETE_STREAMS_SERVER_REPORTED_ERROR = NewMessageType("GAL1245E: Failed to delete stream %s. Unexpected http status code %v received from the server. Error details from the server are: '%s'", 1245, STACK_TRACE_NOT_WANTED)
GALASA_ERROR_DELETE_STREAMS_EXPLANATION_NOT_JSON = NewMessageType("GAL1246E: Failed to delete stream %s. Unexpected http status code %v received from the server. Error details from the server are not in the json format.", 1246, STACK_TRACE_NOT_WANTED)

// When getting multiple monitors...
GALASA_ERROR_GET_MONITORS_REQUEST_FAILED = NewMessageType("GAL1218E: Failed to get monitors. Sending the get request to the Galasa service failed. Cause is %v", 1218, STACK_TRACE_NOT_WANTED)
GALASA_ERROR_GET_MONITORS_NO_RESPONSE_CONTENT = NewMessageType("GAL1219E: Failed to get monitors. Unexpected http status code %v received from the server.", 1219, STACK_TRACE_NOT_WANTED)
Expand Down
Loading