From 58cac58f48d1f904acf187e059582d46bdfbbac4 Mon Sep 17 00:00:00 2001 From: Feargus O'Gorman Date: Fri, 24 Nov 2023 18:00:56 +0000 Subject: [PATCH] Make http client public --- alert_test.go | 6 +++--- client.go | 12 ++++++------ cloud_integrations_test.go | 6 +++--- dashboard_test.go | 4 ++-- derivedmetrics_test.go | 4 ++-- event_test.go | 4 ++-- externallinks_test.go | 4 ++-- ingestionpolicies_test.go | 7 ++++--- metrics_policy_test.go | 7 ++++--- query_test.go | 4 ++-- role_test.go | 4 ++-- search_test.go | 4 ++-- serviceaccount_test.go | 4 ++-- target_test.go | 4 ++-- user_test.go | 6 +++--- usergroup_test.go | 4 ++-- 16 files changed, 43 insertions(+), 41 deletions(-) diff --git a/alert_test.go b/alert_test.go index 87f4a7c7..272edc32 100644 --- a/alert_test.go +++ b/alert_test.go @@ -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, @@ -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", @@ -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", diff --git a/client.go b/client.go index 6b9f2168..2f07c2a7 100644 --- a/client.go +++ b/client.go @@ -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 @@ -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{}, @@ -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{}, } @@ -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 @@ -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 } diff --git a/cloud_integrations_test.go b/cloud_integrations_test.go index c70114ab..9f60fba0 100644 --- a/cloud_integrations_test.go +++ b/cloud_integrations_test.go @@ -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, @@ -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, @@ -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, diff --git a/dashboard_test.go b/dashboard_test.go index e9815bfc..15624dec 100644 --- a/dashboard_test.go +++ b/dashboard_test.go @@ -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, @@ -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", diff --git a/derivedmetrics_test.go b/derivedmetrics_test.go index 36fb7e2c..0e1b75bf 100644 --- a/derivedmetrics_test.go +++ b/derivedmetrics_test.go @@ -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, @@ -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, diff --git a/event_test.go b/event_test.go index 95910afd..c6b880b4 100644 --- a/event_test.go +++ b/event_test.go @@ -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, @@ -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", diff --git a/externallinks_test.go b/externallinks_test.go index c31513c0..d8d4f9ff 100644 --- a/externallinks_test.go +++ b/externallinks_test.go @@ -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, @@ -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, diff --git a/ingestionpolicies_test.go b/ingestionpolicies_test.go index c95a4462..6b22a115 100644 --- a/ingestionpolicies_test.go +++ b/ingestionpolicies_test.go @@ -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" @@ -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, @@ -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, diff --git a/metrics_policy_test.go b/metrics_policy_test.go index f11fc12a..c8470c0c 100644 --- a/metrics_policy_test.go +++ b/metrics_policy_test.go @@ -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 { @@ -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, @@ -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, diff --git a/query_test.go b/query_test.go index fd1c8722..8febd9fa 100644 --- a/query_test.go +++ b/query_test.go @@ -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, }, }, @@ -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, }, }, diff --git a/role_test.go b/role_test.go index 59489daa..a68509b4 100644 --- a/role_test.go +++ b/role_test.go @@ -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, @@ -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, diff --git a/search_test.go b/search_test.go index e73eb1c3..62403bee 100644 --- a/search_test.go +++ b/search_test.go @@ -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{ @@ -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, diff --git a/serviceaccount_test.go b/serviceaccount_test.go index 7f5af25a..d2ac4b3a 100644 --- a/serviceaccount_test.go +++ b/serviceaccount_test.go @@ -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, @@ -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, diff --git a/target_test.go b/target_test.go index 41a25843..5f0eed1f 100644 --- a/target_test.go +++ b/target_test.go @@ -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, @@ -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", diff --git a/user_test.go b/user_test.go index 88ae5feb..bd321193 100644 --- a/user_test.go +++ b/user_test.go @@ -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, @@ -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, @@ -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, diff --git a/usergroup_test.go b/usergroup_test.go index a63c32f9..c4eb6d5e 100644 --- a/usergroup_test.go +++ b/usergroup_test.go @@ -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, @@ -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,