Skip to content

Commit

Permalink
fix linting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhoonbang committed Sep 30, 2024
1 parent f815471 commit 6936a12
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
1 change: 0 additions & 1 deletion core/services/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type gateway struct {

codec api.Codec
httpServer gw_net.HttpServer
httpClient gw_net.HTTPClient
handlers map[string]handlers.Handler
connMgr ConnectionManager
lggr logger.Logger
Expand Down
13 changes: 6 additions & 7 deletions core/services/gateway/handlers/webapicapabilities/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ func (h *handler) sendHTTPMessageToClient(ctx context.Context, req network.HTTPR
resp, err := h.httpClient.Send(ctx, req)
if err != nil {
return nil, err
} else {
payload = TargetResponsePayload{
ExecutionError: false,
StatusCode: uint16(resp.StatusCode),
Headers: resp.Headers,
Body: resp.Body,
}
}
payload = TargetResponsePayload{
ExecutionError: false,
StatusCode: resp.StatusCode,
Headers: resp.Headers,
Body: resp.Body,
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func TestHandler_SendHTTPMessageToClient(t *testing.T) {

require.Eventually(t, func() bool {
// ensure all goroutines close
err := handler.Close()
require.NoError(t, err)
err2 := handler.Close()
require.NoError(t, err2)
return httpClient.AssertExpectations(t) && don.AssertExpectations(t)
}, tests.WaitTimeout(t), 100*time.Millisecond)
})
Expand Down Expand Up @@ -135,8 +135,8 @@ func TestHandler_SendHTTPMessageToClient(t *testing.T) {

require.Eventually(t, func() bool {
// ensure all goroutines close
err := handler.Close()
require.NoError(t, err)
err2 := handler.Close()
require.NoError(t, err2)
return httpClient.AssertExpectations(t) && don.AssertExpectations(t)
}, tests.WaitTimeout(t), 100*time.Millisecond)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type TargetRequestPayload struct {
type TargetResponsePayload struct {
ExecutionError bool `json:"executionError"` // true if there were non-HTTP errors. false if HTTP request was sent regardless of status (2xx, 4xx, 5xx)
ErrorMessage string `json:"errorMessage,omitempty"` // error message in case of failure
StatusCode uint16 `json:"statusCode,omitempty"` // HTTP status code
StatusCode int `json:"statusCode,omitempty"` // HTTP status code
Headers map[string]string `json:"headers,omitempty"` // HTTP headers
Body []byte `json:"body,omitempty"` // HTTP response body
}
12 changes: 8 additions & 4 deletions core/services/gateway/network/httpclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func TestHTTPClient_Send(t *testing.T) {
setupServer: func() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("success"))
_, err2 := w.Write([]byte("success"))
require.NoError(t, err2)
}))
},
request: network.HTTPRequest{
Expand All @@ -61,7 +62,8 @@ func TestHTTPClient_Send(t *testing.T) {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(10 * time.Second)
w.WriteHeader(http.StatusOK)
w.Write([]byte("success"))
_, err2 := w.Write([]byte("success"))
require.NoError(t, err2)
}))
},
request: network.HTTPRequest{
Expand All @@ -79,7 +81,8 @@ func TestHTTPClient_Send(t *testing.T) {
setupServer: func() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("error"))
_, err2 := w.Write([]byte("error"))
require.NoError(t, err2)
}))
},
request: network.HTTPRequest{
Expand All @@ -101,7 +104,8 @@ func TestHTTPClient_Send(t *testing.T) {
setupServer: func() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(make([]byte, 2048)) // Response body longer than MaxResponseBytes
_, err2 := w.Write(make([]byte, 2048))
require.NoError(t, err2)
}))
},
request: network.HTTPRequest{
Expand Down

0 comments on commit 6936a12

Please sign in to comment.