Skip to content

Commit

Permalink
Make http client public
Browse files Browse the repository at this point in the history
  • Loading branch information
FeargusOG committed Nov 24, 2023
1 parent 15aa1db commit 58cac58
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 41 deletions.
6 changes: 3 additions & 3 deletions alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestAlerts_PaginatedFind(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestAlerts_CRUDAlert(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
method: "PUT",
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestMultiThresholdAlerts_CreateUpdateDeleteAlert(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
method: "PUT",
Expand Down
12 changes: 6 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ type Client struct {
// The maximum amount of time we will wait
MaxRetryDurationInMS int

// httpClient is the client that will be used to make requests against the API.
httpClient *http.Client
// HttpClient is the client that will be used to make requests against the API.
HttpClient *http.Client

// debug, if set, will cause all requests to be dumped to the screen before sending.
debug bool
Expand All @@ -80,7 +80,7 @@ func NewClient(config *Config) (*Client, error) {
c := &Client{
Config: &configCopy,
BaseURL: baseURL,
httpClient: &http.Client{
HttpClient: &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSNextProto: map[string]func(authority string, c *tls.Conn) http.RoundTripper{},
Expand All @@ -94,7 +94,7 @@ func NewClient(config *Config) (*Client, error) {
// ENABLE HTTP Proxy
if config.HttpProxy != "" {
proxyUrl, _ := url.Parse(config.HttpProxy)
c.httpClient.Transport = &http.Transport{
c.HttpClient.Transport = &http.Transport{
Proxy: http.ProxyURL(proxyUrl),
TLSNextProto: map[string]func(authority string, c *tls.Conn) http.RoundTripper{},
}
Expand All @@ -105,7 +105,7 @@ func NewClient(config *Config) (*Client, error) {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
c.httpClient.Transport = tr
c.HttpClient.Transport = tr
}

return c, nil
Expand Down Expand Up @@ -195,7 +195,7 @@ func (c Client) Do(req *http.Request) (io.ReadCloser, error) {
}

for {
resp, err := c.httpClient.Do(req)
resp, err := c.HttpClient.Do(req)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions cloud_integrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestCloudIntegration_Search(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestCloudIntegrations_AwsExternalID(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestCloudIntegrations_CRUD(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down
4 changes: 2 additions & 2 deletions dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestDashboards_PaginatedFind(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestDashboards_CreateUpdateDeleteDashboard(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
method: "PUT",
Expand Down
4 changes: 2 additions & 2 deletions derivedmetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestDerivedMetrics_Find(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand All @@ -56,7 +56,7 @@ func TestDerivedMetrics_CRUD(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down
4 changes: 2 additions & 2 deletions event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestEvents_Find(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestEvents_CreateUpdateDeleteEvent(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
method: "PUT",
Expand Down
4 changes: 2 additions & 2 deletions externallinks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestExternalLinks_Find(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand All @@ -56,7 +56,7 @@ func TestExternalLinks_CreateUpdateDelete(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down
7 changes: 4 additions & 3 deletions ingestionpolicies_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package wavefront

import (
"github.com/stretchr/testify/assert"
"io"
"net/http"
"net/url"
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

const SharedPolicyName = "test ingestion policy"
Expand Down Expand Up @@ -288,7 +289,7 @@ func TestIngestionPolicies_Find(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand All @@ -312,7 +313,7 @@ func TestIngestionPolicies_CreateUpdateDelete(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down
7 changes: 4 additions & 3 deletions metrics_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package wavefront

import (
"fmt"
"github.com/stretchr/testify/assert"
"io"
"net/http"
"net/url"
"testing"

"github.com/stretchr/testify/assert"
)

type MockMetricsPolicyClient struct {
Expand Down Expand Up @@ -34,7 +35,7 @@ func TestMetricsPolicy_Get(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down Expand Up @@ -68,7 +69,7 @@ func TestMetricsPolicy_Put(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down
4 changes: 2 additions & 2 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestQuery(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
},
Expand Down Expand Up @@ -85,7 +85,7 @@ func getQueryOutputFromFixture(fixture string) (*QueryResponse, error) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
},
Expand Down
4 changes: 2 additions & 2 deletions role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestRole_Find(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestRole_CreateUpdateDelete(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down
4 changes: 2 additions & 2 deletions search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestDefensiveCopy(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
},
}
sc := &SearchCondition{
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestSearch(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down
4 changes: 2 additions & 2 deletions serviceaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestServiceAccounts_Find(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand All @@ -61,7 +61,7 @@ func testClient(t *testing.T) *ServiceAccounts {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down
4 changes: 2 additions & 2 deletions target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestTargets_Find(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand All @@ -59,7 +59,7 @@ func TestTargets_CreateUpdateDeleteTarget(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
method: "PUT",
Expand Down
6 changes: 3 additions & 3 deletions user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestUsers_Find(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestUsers_NilID(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand All @@ -110,7 +110,7 @@ func TestUsers_CreateUpdateDelete(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down
4 changes: 2 additions & 2 deletions usergroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestUserGroups_Find(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down Expand Up @@ -85,7 +85,7 @@ func Test_CreatReadUpdateDelete(t *testing.T) {
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
HttpClient: http.DefaultClient,
debug: true,
},
T: t,
Expand Down

0 comments on commit 58cac58

Please sign in to comment.