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 1 commit
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
8 changes: 6 additions & 2 deletions docs/generated/errors-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +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.
- GAL1241E: The test stream could not be deleted by name because it was not found by the Galasa service. Try listing streams using 'galasactl streams get' to identify the one you wish to delete
- GAL1242E: Failed to test stream from database by stream name.
- GAL12412E: Failed to delete test stream with the given name from the Galasa service
- GAL1242E: Failed to delete streams. Unexpected http status code {} received from the server.
- GAL1243E: Failed to delete streams. Unexpected http status code {} received from the server. Error details from the server could not be read. Cause: {}
- GAL1244E: Failed to delete streams. 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 streams. Unexpected http status code {} received from the server. Error details from the server are: '{}'
- GAL1246E: Failed to delete streams. 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
4 changes: 2 additions & 2 deletions docs/generated/galasactl_streams_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Deletes a test stream by name

### Synopsis

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

```
galasactl streams delete [flags]
Expand All @@ -14,7 +14,7 @@ galasactl streams delete [flags]

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

### Options inherited from parent commands
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/streamsDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (cmd *StreamsDeleteCommand) createCobraCmd(
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",
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(
Expand All @@ -91,7 +91,7 @@ func (cmd *StreamsDeleteCommand) createCobraCmd(
},
}

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

return streamsDeleteCobraCmd, err
Expand Down
18 changes: 18 additions & 0 deletions pkg/cmd/streamsDelete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,21 @@ func TestStreamsDeleteNamespaceNameFlagsReturnsOk(t *testing.T) {

assert.Nil(t, err)
}

func TestStreamsDeleteNamespaceWithoutNameFlagReturnsError(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)
}
10 changes: 8 additions & 2 deletions pkg/errors/errorMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,14 @@ var (
GALASA_ERROR_GET_STREAMS_UNPARSEABLE_CONTENT = NewMessageType("GAL1238E: Failed to get streams. Unexpected http status code %v received from the server. Error details from the server are not in a valid json format. Cause: '%s'", 1238, STACK_TRACE_NOT_WANTED)
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)
GALASA_ERROR_DELETE_STREAMS_NOT_FOUND = NewMessageType("GAL1241E: The test stream could not be deleted by name because it was not found by the Galasa service. Try listing streams using 'galasactl streams get' to identify the one you wish to delete", 1241, STACK_TRACE_NOT_WANTED)
GALASA_ERROR_FAILED_TO_DELETE_STREAM = NewMessageType("GAL1242E: Failed to test stream from database by stream name.", 1242, 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 streams. 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 streams. 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 streams. 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 streams. 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 streams. 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)
Expand Down
25 changes: 10 additions & 15 deletions pkg/streams/streamsDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,20 @@ import (

func DeleteStream(streamName string, apiClient *galasaapi.APIClient, byteReader spi.ByteReader) error {

streams, err := getStreamsFromRestApi(streamName, apiClient, byteReader)
var err error

if err == nil {

if len(streams) != 0 {
err = deleteStreamFromRestApi(streams[0], apiClient, byteReader)
} else {
err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_DELETE_STREAMS_NOT_FOUND)
}
streamName, err = validateStreamName(streamName)

if err == nil {
err = deleteStreamFromRestApi(streamName, apiClient, byteReader)
}

return err

}

func deleteStreamFromRestApi(
stream galasaapi.Stream,
streamName string,
apiClient *galasaapi.APIClient,
byteReader spi.ByteReader,
) error {
Expand All @@ -48,7 +44,6 @@ func deleteStreamFromRestApi(

if err == nil {

streamName := stream.Metadata.GetName()
apiCall := apiClient.StreamsAPIApi.DeleteStreamByName(context, streamName).ClientApiVersion(restApiVersion)
resp, err = apiCall.Execute()

Expand All @@ -68,11 +63,11 @@ func deleteStreamFromRestApi(
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,
galasaErrors.GALASA_ERROR_DELETE_STREAMS_NO_RESPONSE_CONTENT,
galasaErrors.GALASA_ERROR_DELETE_STREAMS_RESPONSE_BODY_UNREADABLE,
galasaErrors.GALASA_ERROR_DELETE_STREAMS_UNPARSEABLE_CONTENT,
galasaErrors.GALASA_ERROR_DELETE_STREAMS_SERVER_REPORTED_ERROR,
galasaErrors.GALASA_ERROR_DELETE_STREAMS_EXPLANATION_NOT_JSON,
)

}
Expand Down
58 changes: 34 additions & 24 deletions pkg/streams/streamsDelete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package streams

import (
"encoding/json"
"fmt"
"net/http"
"strconv"
Expand Down Expand Up @@ -57,28 +56,17 @@ func WriteMockStreamResponse(

}

func TestStreamUserDeleteAUser(t *testing.T) {
func TestStreamDeleteAStream(t *testing.T) {

//Given...
name := "mystream"
description := "This is a dummy stream"

streamToDelete := createMockStream(name, description)
streamToDeleteBytes, _ := json.Marshal(streamToDelete)
streamToDeleteJson := string(streamToDeleteBytes)

getStreamInteraction := utils.NewHttpInteraction("/streams/"+name, http.MethodGet)
getStreamInteraction.WriteHttpResponseFunc = func(writer http.ResponseWriter, req *http.Request) {
WriteMockStreamResponse(t, writer, req, name, []string{streamToDeleteJson})
}

deleteStreamInteraction := utils.NewHttpInteraction("/streams/"+name, http.MethodDelete)
deleteStreamInteraction.WriteHttpResponseFunc = func(writer http.ResponseWriter, req *http.Request) {
writer.WriteHeader(http.StatusNoContent)
}

interactions := []utils.HttpInteraction{
getStreamInteraction,
deleteStreamInteraction,
}

Expand All @@ -101,21 +89,44 @@ func TestStreamUserDeleteAUser(t *testing.T) {
assert.Empty(t, console.ReadText(), "The console was written to on a successful deletion, it should be empty")
}

func TestStreamDeleteThrowsAnUnexpectedError(t *testing.T) {
func TestStreamDeleteAnInvalidStreamNameReturnsError(t *testing.T) {

//Given...
name := "mystream"
description := "This is a dummy stream"
name := "my.stream"

streamToDelete := createMockStream(name, description)
streamToDeleteBytes, _ := json.Marshal(streamToDelete)
streamToDeleteJson := string(streamToDeleteBytes)
deleteStreamInteraction := utils.NewHttpInteraction("/streams/"+name, http.MethodDelete)
deleteStreamInteraction.WriteHttpResponseFunc = func(writer http.ResponseWriter, req *http.Request) {
writer.WriteHeader(http.StatusBadRequest)
}

getStreamInteraction := utils.NewHttpInteraction("/streams/"+name, http.MethodGet)
getStreamInteraction.WriteHttpResponseFunc = func(writer http.ResponseWriter, req *http.Request) {
WriteMockStreamResponse(t, writer, req, name, []string{streamToDeleteJson})
interactions := []utils.HttpInteraction{
deleteStreamInteraction,
}

server := utils.NewMockHttpServer(t, interactions)
defer server.Server.Close()

apiServerUrl := server.Server.URL
apiClient := api.InitialiseAPI(apiServerUrl)
mockByteReader := utils.NewMockByteReader()

// When...
err := DeleteStream(
name,
apiClient,
mockByteReader)

// Then...
assert.NotNil(t, err, "DeleteStream returned an unexpected error")
assert.Contains(t, err.Error(), "GAL1235E")
assert.Contains(t, err.Error(), "he name provided with the --name flag cannot be empty and must only contain characters in the following ranges:")
}

func TestStreamDeleteThrowsAnUnexpectedError(t *testing.T) {

//Given...
name := "mystream"

deleteStreamInteraction := utils.NewHttpInteraction("/streams/"+name, http.MethodDelete)
deleteStreamInteraction.WriteHttpResponseFunc = func(writer http.ResponseWriter, req *http.Request) {
writer.Header().Set("Content-Type", "application/json")
Expand All @@ -124,7 +135,6 @@ func TestStreamDeleteThrowsAnUnexpectedError(t *testing.T) {
}

interactions := []utils.HttpInteraction{
getStreamInteraction,
deleteStreamInteraction,
}

Expand All @@ -144,5 +154,5 @@ func TestStreamDeleteThrowsAnUnexpectedError(t *testing.T) {
// Then...
assert.NotNil(t, err, "DeleteStream returned an unexpected error")
assert.Contains(t, err.Error(), strconv.Itoa(http.StatusInternalServerError))
assert.Contains(t, err.Error(), "GAL1239E")
assert.Contains(t, err.Error(), "GAL1245E")
}