This repository was archived by the owner on May 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Added streams delete command #357
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 by the given name from the API Server | ||
aashir21 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ``` | ||
| galasactl streams delete [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Displays the options for the 'streams delete' command. | ||
| --name string An optional field indicating the name of a test stream | ||
aashir21 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ### 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 by the given name from the API Server", | ||
| Aliases: []string{COMMAND_NAME_STREAMS_DELETE}, | ||
| RunE: func(cobraCommand *cobra.Command, args []string) error { | ||
| return cmd.executeStreamsDelete( | ||
| factory, streamsCommand.Values().(*StreamsCmdValues), commsFlagSetValues, | ||
| ) | ||
| }, | ||
| } | ||
|
|
||
| addStreamNameFlag(streamsDeleteCobraCmd, false, 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 | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * 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) | ||
| } | ||
aashir21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * Copyright contributors to the Galasa project | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
|
|
||
| package streams | ||
|
|
||
| import ( | ||
| "context" | ||
| "log" | ||
| "net/http" | ||
|
|
||
| "github.com/galasa-dev/cli/pkg/embedded" | ||
| galasaErrors "github.com/galasa-dev/cli/pkg/errors" | ||
| "github.com/galasa-dev/cli/pkg/galasaapi" | ||
| "github.com/galasa-dev/cli/pkg/spi" | ||
| ) | ||
|
|
||
| func DeleteStream(streamName string, apiClient *galasaapi.APIClient, byteReader spi.ByteReader) error { | ||
|
|
||
| streams, err := getStreamsFromRestApi(streamName, apiClient, byteReader) | ||
aashir21 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if err == nil { | ||
|
|
||
| if len(streams) != 0 { | ||
| err = deleteStreamFromRestApi(streams[0], apiClient, byteReader) | ||
| } else { | ||
| err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_DELETE_STREAMS_NOT_FOUND) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return err | ||
|
|
||
| } | ||
|
|
||
| func deleteStreamFromRestApi( | ||
| stream galasaapi.Stream, | ||
aashir21 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| apiClient *galasaapi.APIClient, | ||
| byteReader spi.ByteReader, | ||
| ) error { | ||
|
|
||
| var context context.Context = nil | ||
| var resp *http.Response | ||
|
|
||
| restApiVersion, err := embedded.GetGalasactlRestApiVersion() | ||
|
|
||
| if err == nil { | ||
|
|
||
| streamName := stream.Metadata.GetName() | ||
| apiCall := apiClient.StreamsAPIApi.DeleteStreamByName(context, streamName).ClientApiVersion(restApiVersion) | ||
| resp, err = apiCall.Execute() | ||
|
|
||
| if resp != nil { | ||
| defer resp.Body.Close() | ||
| } | ||
|
|
||
| if err != nil { | ||
|
|
||
| if resp == nil { | ||
|
|
||
| err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_FAILED_TO_DELETE_STREAM, err.Error()) | ||
|
|
||
| } else { | ||
|
|
||
| err = galasaErrors.HttpResponseToGalasaError( | ||
| resp, | ||
| streamName, | ||
| byteReader, | ||
| galasaErrors.GALASA_ERROR_GET_STREAMS_NO_RESPONSE_CONTENT, | ||
| galasaErrors.GALASA_ERROR_GET_STREAMS_RESPONSE_BODY_UNREADABLE, | ||
| galasaErrors.GALASA_ERROR_GET_STREAMS_UNPARSEABLE_CONTENT, | ||
| galasaErrors.GALASA_ERROR_GET_STREAMS_SERVER_REPORTED_ERROR, | ||
| galasaErrors.GALASA_ERROR_GET_STREAMS_EXPLANATION_NOT_JSON, | ||
aashir21 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| } | ||
|
|
||
| log.Printf("Test stream with name '%s', was deleted OK.\n", streamName) | ||
| } | ||
| } | ||
|
|
||
| return err | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.