From 8e2be7326b5fe966aeef4697c8f17d6ab3fc42c4 Mon Sep 17 00:00:00 2001 From: Michael Hoffman Date: Fri, 7 Feb 2025 16:51:19 -0500 Subject: [PATCH] Improve http error test cases --- pkg/cmd/repo/autolink/delete/http_test.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/pkg/cmd/repo/autolink/delete/http_test.go b/pkg/cmd/repo/autolink/delete/http_test.go index 928e561c7..a2676178d 100644 --- a/pkg/cmd/repo/autolink/delete/http_test.go +++ b/pkg/cmd/repo/autolink/delete/http_test.go @@ -28,17 +28,21 @@ func TestAutolinkDeleter_Delete(t *testing.T) { stubStatus: http.StatusNoContent, }, { - name: "404 repo or autolink not found", - id: "123", - stubStatus: http.StatusNotFound, - stubRespJSON: `{ - "message": "Not Found", - "documentation_url": "https://docs.github.com/rest/repos/autolinks#get-an-autolink-reference-of-a-repository", - "status": "404" - }`, + name: "404 repo or autolink not found", + id: "123", + stubStatus: http.StatusNotFound, + stubRespJSON: `{}`, // API response not used in output expectErr: true, expectedErrMsg: "error deleting autolink: HTTP 404: Perhaps you are missing admin rights to the repository? (https://api.github.com/repos/OWNER/REPO/autolinks/123)", }, + { + name: "500 unexpected error", + id: "123", + stubRespJSON: `{"messsage": "arbitrary error"}`, + stubStatus: http.StatusInternalServerError, + expectErr: true, + expectedErrMsg: "HTTP 500 (https://api.github.com/repos/OWNER/REPO/autolinks/123)", + }, } for _, tt := range tests { @@ -49,7 +53,7 @@ func TestAutolinkDeleter_Delete(t *testing.T) { http.MethodDelete, fmt.Sprintf("repos/%s/%s/autolinks/%s", repo.RepoOwner(), repo.RepoName(), tt.id), ), - httpmock.StatusStringResponse(tt.stubStatus, tt.stubRespJSON), + httpmock.StatusJSONResponse(tt.stubStatus, tt.stubRespJSON), ) defer reg.Verify(t)