Skip to content

Commit

Permalink
[chore] close http responses and preallocate slices (#24926)
Browse files Browse the repository at this point in the history
These changes only affect tests.
  • Loading branch information
atoulme authored Sep 22, 2023
1 parent 5356349 commit 458dc1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions receiver/signalfxreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func Test_sfxReceiver_handleReq(t *testing.T) {

resp := w.Result()
respBytes, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
assert.NoError(t, err)

var bodyStr string
Expand Down Expand Up @@ -521,6 +522,7 @@ func Test_sfxReceiver_handleEventReq(t *testing.T) {
resp := w.Result()
respBytes, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
defer resp.Body.Close()

var bodyStr string
assert.NoError(t, json.Unmarshal(respBytes, &bodyStr))
Expand Down Expand Up @@ -600,6 +602,7 @@ func Test_sfxReceiver_TLS(t *testing.T) {

resp, err := client.Do(req)
require.NoErrorf(t, err, "should not have failed when sending to signalFx receiver %v", err)
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
t.Log("SignalFx Request Received")

Expand Down Expand Up @@ -664,6 +667,7 @@ func Test_sfxReceiver_DatapointAccessTokenPassthrough(t *testing.T) {
resp := w.Result()
respBytes, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
defer resp.Body.Close()

var bodyStr string
assert.NoError(t, json.Unmarshal(respBytes, &bodyStr))
Expand Down Expand Up @@ -742,6 +746,7 @@ func Test_sfxReceiver_EventAccessTokenPassthrough(t *testing.T) {
resp := w.Result()
respBytes, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
defer resp.Body.Close()

var bodyStr string
assert.NoError(t, json.Unmarshal(respBytes, &bodyStr))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestSignalFxV2EventsToLogData(t *testing.T) {
}

func mapToEventProps(m map[string]interface{}) []*sfxpb.Property {
var out []*sfxpb.Property
out := make([]*sfxpb.Property, 0, len(m))
for k, v := range m {
var pval sfxpb.PropertyValue

Expand Down

0 comments on commit 458dc1a

Please sign in to comment.