Skip to content

Commit

Permalink
fix: removes the GET '404' condition based on the 'Content-Length' he…
Browse files Browse the repository at this point in the history
…ader.

Closes #26

Signed-off-by: Dmitry Kisler <[email protected]>
  • Loading branch information
kislerdm committed Sep 19, 2023
1 parent 7c1bca5 commit 8824f60
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 74 deletions.
12 changes: 0 additions & 12 deletions generator/templates/sdk.go.templ
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,6 @@ func (c *client) requestHandler(url string, t string, reqPayload interface{}, re
return convertErrorResponse(res)
}

// cover non-existing object which will have 200+ status code
// see the ticket https://github.com/neondatabase/neon/issues/2159
if req.Method == "GET" && res.ContentLength < 4 {
return Error{
HTTPCode: 404,
errorResp: errorResp{
Code: "",
Message: "object not found",
},
}
}

if responsePayload != nil {
buf, err := io.ReadAll(res.Body)
defer func() { _ = res.Body.Close() }()
Expand Down
30 changes: 0 additions & 30 deletions generator/templates/sdk_test.go.templ
Original file line number Diff line number Diff line change
Expand Up @@ -264,36 +264,6 @@ func Test_client_requestHandler(t *testing.T) {
},
},
},
{
name: "unhappy path: https://github.com/neondatabase/neon/issues/2159",
fields: fields{
options: options{
key: "bar",
httpClient: &mockHttp{
err: Error{HTTPCode: http.StatusOK},
},
},
baseURL: "",
},
args: args{
url: "",
t: "GET",
responsePayload: &respPayload,
},
wantRequestHeaders: http.Header{
"Accept": []string{"application/json"},
"Content-Type": []string{"application/json"},
"Authorization": []string{"Bearer bar"},
},
wantResp: mockPayload{},
wantErr: Error{
HTTPCode: http.StatusNotFound,
errorResp: errorResp{
Code: "",
Message: "object not found",
},
},
},
}
for _, tt := range tests {
t.Run(
Expand Down
4 changes: 2 additions & 2 deletions mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ var endpointResponseExamples = map[string]map[string]mockResponse{
// Mock client return the response as per API spec, except for the errors: 404 and 401 status codes are covered only.
// - 401 is returned when the string `invalidApiKey` is used as the API key;
// - 404 is returned if either of the following:
// - the string value `notFound` is used as the string argument, e.g. projectID
// - a negative int/float value is used as the int/float argument, e.g. database ID
// - the string value `notFound` is used as the string argument, e.g. projectID
// - a negative int/float value is used as the int/float argument, e.g. database ID
func NewMockHTTPClient() HTTPClient {
u, _ := url.Parse(baseURL)
return mockHTTPClient{
Expand Down
30 changes: 0 additions & 30 deletions sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,36 +264,6 @@ func Test_client_requestHandler(t *testing.T) {
},
},
},
{
name: "unhappy path: https://github.com/neondatabase/neon/issues/2159",
fields: fields{
options: options{
key: "bar",
httpClient: &mockHttp{
err: Error{HTTPCode: http.StatusOK},
},
},
baseURL: "",
},
args: args{
url: "",
t: "GET",
responsePayload: &respPayload,
},
wantRequestHeaders: http.Header{
"Accept": []string{"application/json"},
"Content-Type": []string{"application/json"},
"Authorization": []string{"Bearer bar"},
},
wantResp: mockPayload{},
wantErr: Error{
HTTPCode: http.StatusNotFound,
errorResp: errorResp{
Code: "",
Message: "object not found",
},
},
},
}
for _, tt := range tests {
t.Run(
Expand Down

0 comments on commit 8824f60

Please sign in to comment.