Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmtszr committed Jan 12, 2023
1 parent 6f3ce90 commit cb791a3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
20 changes: 20 additions & 0 deletions internal/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func TestCollectorRequest(t *testing.T) {
},
Logger: logger.ShimLogger{IsDebugEnabled: true},
AgentVersion: "agent_version",
GzipWriterPool: &sync.Pool{
New: func() interface{} {
return gzip.NewWriter(io.Discard)
},
},
}
resp := CollectorRequest(cmd, cs)
if nil != resp.Err {
Expand Down Expand Up @@ -141,6 +146,11 @@ func TestCollectorBadRequest(t *testing.T) {
},
Logger: logger.ShimLogger{IsDebugEnabled: true},
AgentVersion: "agent_version",
GzipWriterPool: &sync.Pool{
New: func() interface{} {
return gzip.NewWriter(io.Discard)
},
},
}
u := ":" // bad url
resp := collectorRequestInternal(u, cmd, cs)
Expand Down Expand Up @@ -244,6 +254,11 @@ func testConnectHelper(cm connectMock) (*ConnectReply, RPMResponse) {
Client: &http.Client{Transport: cm},
Logger: logger.ShimLogger{IsDebugEnabled: true},
AgentVersion: "1",
GzipWriterPool: &sync.Pool{
New: func() interface{} {
return gzip.NewWriter(io.Discard)
},
},
}

return ConnectAttempt(config, "", false, cs)
Expand Down Expand Up @@ -487,6 +502,11 @@ func TestCollectorRequestRespectsMaxPayloadSize(t *testing.T) {
}),
},
Logger: logger.ShimLogger{IsDebugEnabled: true},
GzipWriterPool: &sync.Pool{
New: func() interface{} {
return gzip.NewWriter(io.Discard)
},
},
}
resp := CollectorRequest(cmd, cs)
if nil == resp.Err {
Expand Down
38 changes: 38 additions & 0 deletions v3/newrelic/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
package newrelic

import (
"compress/gzip"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -105,6 +108,11 @@ func TestCollectorRequest(t *testing.T) {
}),
},
Logger: logger.ShimLogger{IsDebugEnabled: true},
GzipWriterPool: &sync.Pool{
New: func() interface{} {
return gzip.NewWriter(io.Discard)
},
},
}
resp := collectorRequest(cmd, cs)
if nil != resp.Err {
Expand All @@ -131,6 +139,11 @@ func TestCollectorBadRequest(t *testing.T) {
}),
},
Logger: logger.ShimLogger{IsDebugEnabled: true},
GzipWriterPool: &sync.Pool{
New: func() interface{} {
return gzip.NewWriter(io.Discard)
},
},
}
u := ":" // bad url
resp := collectorRequestInternal(u, cmd, cs)
Expand All @@ -154,6 +167,11 @@ func TestCollectorTimeout(t *testing.T) {
Timeout: time.Nanosecond, // force a timeout
},
Logger: logger.ShimLogger{IsDebugEnabled: true},
GzipWriterPool: &sync.Pool{
New: func() interface{} {
return gzip.NewWriter(io.Discard)
},
},
}
u := "https://example.com"
resp := collectorRequestInternal(u, cmd, cs)
Expand All @@ -174,6 +192,11 @@ func TestUrl(t *testing.T) {
License: "123abc",
Client: nil,
Logger: nil,
GzipWriterPool: &sync.Pool{
New: func() interface{} {
return gzip.NewWriter(io.Discard)
},
},
}

out := rpmURL(cmd, cs)
Expand Down Expand Up @@ -235,6 +258,11 @@ func testConnectHelper(cm connectMock) (*internal.ConnectReply, rpmResponse) {
License: "12345",
Client: &http.Client{Transport: cm},
Logger: logger.ShimLogger{IsDebugEnabled: true},
GzipWriterPool: &sync.Pool{
New: func() interface{} {
return gzip.NewWriter(io.Discard)
},
},
}

return connectAttempt(cm.config, cs)
Expand Down Expand Up @@ -403,6 +431,11 @@ func TestCollectorRequestRespectsMaxPayloadSize(t *testing.T) {
}),
},
Logger: logger.ShimLogger{IsDebugEnabled: true},
GzipWriterPool: &sync.Pool{
New: func() interface{} {
return gzip.NewWriter(io.Discard)
},
},
}
resp := collectorRequest(cmd, cs)
if nil == resp.Err {
Expand Down Expand Up @@ -439,6 +472,11 @@ func TestConnectReplyMaxPayloadSize(t *testing.T) {
}),
},
Logger: logger.ShimLogger{IsDebugEnabled: true},
GzipWriterPool: &sync.Pool{
New: func() interface{} {
return gzip.NewWriter(io.Discard)
},
},
}
}

Expand Down

0 comments on commit cb791a3

Please sign in to comment.