From 3b421cdb2870bb0ec7d54fea62dc034cb584c373 Mon Sep 17 00:00:00 2001 From: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:03:24 +0100 Subject: [PATCH] Close the test server in runs delete tests Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> --- docs/generated/errors-list.md | 5 +++-- pkg/runs/runsDelete_test.go | 16 +++++++++++----- pkg/utils/httpInteractionMock.go | 5 +---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/generated/errors-list.md b/docs/generated/errors-list.md index a22a2879..3b75dd85 100644 --- a/docs/generated/errors-list.md +++ b/docs/generated/errors-list.md @@ -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. diff --git a/pkg/runs/runsDelete_test.go b/pkg/runs/runsDelete_test.go index 99e161a8..eb7b4aff 100644 --- a/pkg/runs/runsDelete_test.go +++ b/pkg/runs/runsDelete_test.go @@ -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() @@ -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() @@ -136,6 +138,7 @@ func TestRunsDeleteFailsWithNoExplanationErrorPayloadGivesCorrectMessage(t *test } server := utils.NewMockHttpServer(t, interactions) + defer server.Server.Close() console := utils.NewMockConsole() apiServerUrl := server.Server.URL @@ -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() @@ -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() @@ -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() diff --git a/pkg/utils/httpInteractionMock.go b/pkg/utils/httpInteractionMock.go index ef776b02..c4f44821 100644 --- a/pkg/utils/httpInteractionMock.go +++ b/pkg/utils/httpInteractionMock.go @@ -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) } @@ -71,7 +72,3 @@ func NewMockHttpServer(t *testing.T, interactions []HttpInteraction) MockHttpSer })) return mockHttpServer } - -func (mockServer *MockHttpServer) GetServerURL() string { - return mockServer.Server.URL -} \ No newline at end of file