Skip to content

Commit

Permalink
Close the test server in runs delete tests
Browse files Browse the repository at this point in the history
Signed-off-by: Eamonn Mansour <[email protected]>
  • Loading branch information
eamansour committed Sep 4, 2024
1 parent d6f61c9 commit 3b421cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
5 changes: 3 additions & 2 deletions docs/generated/errors-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,12 @@ The `galasactl` tool can generate the following errors:
- GAL1154E: The provided token ID, '{}', does not match formatting requirements. The token ID can contain any character in the 'a'-'z', 'A'-'Z', '0'-'9', '-' (dash), or '_' (underscore) ranges only.
- GAL1155E: The id provided by the --id field cannot be an empty string.
- GAL1156E: '{}' is not supported as a valid value. Valid values are 'me'.
- GAL1157E: An attempt to delete a run named '{}' failed. Sending the delete request to the Galasa service failed. Cause is {}
- GAL1157E: An attempt to delete a run named '{}' failed. Cause is {}
- GAL1158E: An attempt to delete a run named '{}' failed. Sending the delete request to the Galasa service failed. Cause is {}
- GAL1159E: An attempt to delete a run named '{}' failed. Unexpected http status code {} received from the server.
- GAL1160E: An attempt to delete a run named '{}' failed. Unexpected http status code {} received from the server. Error details from the server could not be read. Cause: {}
- GAL1161E: An attempt to delete a run named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
- GAL1162E: An attempt to delete a run named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are: {}
- GAL1162E: An attempt to delete a run named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are: '{}'
- GAL1163E: The run named '{}' could not be deleted because it was not found by the Galasa service. Try listing runs using 'galasactl runs get' to identify the one you wish to delete
- GAL1164E: An attempt to delete a run named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
- GAL1225E: Failed to open file '{}' cause: {}. Check that this file exists, and that you have read permissions.
Expand Down
16 changes: 11 additions & 5 deletions pkg/runs/runsDelete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func TestCanDeleteARun(t *testing.T) {
}

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

console := utils.NewMockConsole()
apiServerUrl := server.GetServerURL()
apiServerUrl := server.Server.URL
apiClient := api.InitialiseAPI(apiServerUrl)
mockTimeService := utils.NewMockTimeService()

Expand Down Expand Up @@ -87,9 +88,10 @@ func TestDeleteNonExistantRunDisplaysError(t *testing.T) {
interactions := []utils.HttpInteraction{ getRunsInteraction }

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

console := utils.NewMockConsole()
apiServerUrl := server.GetServerURL()
apiServerUrl := server.Server.URL
apiClient := api.InitialiseAPI(apiServerUrl)
mockTimeService := utils.NewMockTimeService()

Expand Down Expand Up @@ -136,6 +138,7 @@ func TestRunsDeleteFailsWithNoExplanationErrorPayloadGivesCorrectMessage(t *test
}

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

console := utils.NewMockConsole()
apiServerUrl := server.Server.URL
Expand Down Expand Up @@ -186,9 +189,10 @@ func TestRunsDeleteFailsWithNonJsonContentTypeExplanationErrorPayloadGivesCorrec
}

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

console := utils.NewMockConsole()
apiServerUrl := server.GetServerURL()
apiServerUrl := server.Server.URL
apiClient := api.InitialiseAPI(apiServerUrl)
mockTimeService := utils.NewMockTimeService()

Expand Down Expand Up @@ -238,9 +242,10 @@ func TestRunsDeleteFailsWithBadlyFormedJsonContentExplanationErrorPayloadGivesCo
}

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

console := utils.NewMockConsole()
apiServerUrl := server.GetServerURL()
apiServerUrl := server.Server.URL
apiClient := api.InitialiseAPI(apiServerUrl)
mockTimeService := utils.NewMockTimeService()

Expand Down Expand Up @@ -299,9 +304,10 @@ func TestRunsDeleteFailsWithValidErrorResponsePayloadGivesCorrectMessage(t *test
}

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

console := utils.NewMockConsole()
apiServerUrl := server.GetServerURL()
apiServerUrl := server.Server.URL
apiClient := api.InitialiseAPI(apiServerUrl)
mockTimeService := utils.NewMockTimeService()

Expand Down
5 changes: 1 addition & 4 deletions pkg/utils/httpInteractionMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewHttpInteraction(expectedPath string, expectedHttpMethod string) HttpInte
ExpectedHttpMethod: expectedHttpMethod,
}

// Set a basic implementation of the lambda to write a default response, which can be overridden by tests
httpInteraction.WriteHttpResponseLambda = func(writer http.ResponseWriter, req *http.Request) {
writer.WriteHeader(http.StatusOK)
}
Expand Down Expand Up @@ -71,7 +72,3 @@ func NewMockHttpServer(t *testing.T, interactions []HttpInteraction) MockHttpSer
}))
return mockHttpServer
}

func (mockServer *MockHttpServer) GetServerURL() string {
return mockServer.Server.URL
}

0 comments on commit 3b421cd

Please sign in to comment.