From 7b5e5fd7b65246103b5fbf6ba563ef2c3681d385 Mon Sep 17 00:00:00 2001 From: Brendan Winter Date: Fri, 6 Oct 2023 11:22:45 -0700 Subject: [PATCH] Fix linting issue after Golang upgrade. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Go lang upgrade broke linter, I missed this till CI ran. 🎉 Thanks CI Signed-off-by: Brendan Winter --- alerts_example_test.go | 4 ++-- client.go | 11 +++++------ client_test.go | 9 ++++----- event_test.go | 8 ++++---- query.go | 6 +++--- query_example_test.go | 4 ++-- query_test.go | 8 ++++---- search.go | 4 ++-- search_test.go | 12 ++++++------ target_test.go | 4 ++-- targets_example_test.go | 4 ++-- testing.go | 8 ++++---- usergroup_test.go | 10 +++++----- 13 files changed, 45 insertions(+), 47 deletions(-) diff --git a/alerts_example_test.go b/alerts_example_test.go index 64f04e02..a67c9785 100644 --- a/alerts_example_test.go +++ b/alerts_example_test.go @@ -3,8 +3,8 @@ package wavefront_test import ( "fmt" "github.com/WavefrontHQ/go-wavefront-management-api/v2" - "io/ioutil" "log" + "os" ) func ExampleAlerts() { @@ -75,7 +75,7 @@ func ExampleAlerts() { // Threshold Alerts only accept custom alert targets // Create Alert Targets that can be used for the example - tmpl, _ := ioutil.ReadFile("./target-template.tmpl") + tmpl, _ := os.ReadFile("./target-template.tmpl") targetA := wavefront.Target{ Title: "test target", Description: "testing something A", diff --git a/client.go b/client.go index c5e98894..6b9f2168 100644 --- a/client.go +++ b/client.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "math/rand" "net/http" "net/http/httputil" @@ -142,7 +141,7 @@ func (c Client) NewRequest(method, path string, params *map[string]string, body req.Header.Add("Accept", "application/json") if body != nil { req.Header.Add("Content-Type", "application/json") - req.Body = ioutil.NopCloser(bytes.NewReader(body)) + req.Body = io.NopCloser(bytes.NewReader(body)) } return req, nil } @@ -187,12 +186,12 @@ func (c Client) Do(req *http.Request) (io.ReadCloser, error) { var buf []byte var err error if req.Body != nil { - buf, err = ioutil.ReadAll(req.Body) + buf, err = io.ReadAll(req.Body) if err != nil { return nil, err } // reset the body since we read it already - req.Body = ioutil.NopCloser(bytes.NewReader(buf)) + req.Body = io.NopCloser(bytes.NewReader(buf)) } for { @@ -213,7 +212,7 @@ func (c Client) Do(req *http.Request) (io.ReadCloser, error) { retries++ // replay the buffer back into the body for retry if req.Body != nil { - req.Body = ioutil.NopCloser(bytes.NewReader(buf)) + req.Body = io.NopCloser(bytes.NewReader(buf)) } sleepTime := c.getSleepTime(retries) if c.debug { @@ -223,7 +222,7 @@ func (c Client) Do(req *http.Request) (io.ReadCloser, error) { time.Sleep(sleepTime) continue } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) _ = resp.Body.Close() if err != nil { re := newRestError( diff --git a/client_test.go b/client_test.go index 6d1a3e50..2a63c82b 100644 --- a/client_test.go +++ b/client_test.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "strings" @@ -66,7 +65,7 @@ func TestClientGet(t *testing.T) { if err != nil { t.Fatal("error executing request:", err) } - output, _ := ioutil.ReadAll(resp) + output, _ := io.ReadAll(resp) fmt.Println(string(output)) } @@ -103,7 +102,7 @@ func TestClientPost(t *testing.T) { t.Errorf("no Content-Type header set") } - actualBody, _ := ioutil.ReadAll(r.Body) + actualBody, _ := io.ReadAll(r.Body) // The request body is buffered since we need to replay it on failure // this means the first read will fire this function above with an empty body (because we read it) if string(actualBody) != "" { @@ -141,7 +140,7 @@ func TestClientPost(t *testing.T) { if err != nil { t.Fatal("error executing request:", err) } - output, _ := ioutil.ReadAll(resp) + output, _ := io.ReadAll(resp) fmt.Println(string(output)) } @@ -183,7 +182,7 @@ func (f *fakeWavefronter) Do(_ *http.Request) (io.ReadCloser, error) { if f.doError != nil { return nil, f.doError } - result := ioutil.NopCloser(strings.NewReader(f.response)) + result := io.NopCloser(strings.NewReader(f.response)) return result, nil } diff --git a/event_test.go b/event_test.go index 74f32f23..95910afd 100644 --- a/event_test.go +++ b/event_test.go @@ -4,9 +4,9 @@ import ( "bytes" "encoding/json" "io" - "io/ioutil" "net/http" "net/url" + "os" "testing" "time" @@ -61,7 +61,7 @@ func TestEvents_Find(t *testing.T) { } func (m *MockCrudEventClient) Do(req *http.Request) (io.ReadCloser, error) { - response, err := ioutil.ReadFile("./fixtures/create-event-response.json") + response, err := os.ReadFile("./fixtures/create-event-response.json") if err != nil { m.T.Fatal(err) } @@ -69,14 +69,14 @@ func (m *MockCrudEventClient) Do(req *http.Request) (io.ReadCloser, error) { m.T.Errorf("request method expected '%s' got '%s'", m.method, req.Method) } if req.Body != nil { - body, _ := ioutil.ReadAll(req.Body) + body, _ := io.ReadAll(req.Body) event := Event{} err = json.Unmarshal(body, &event) if err != nil { m.T.Fatal(err) } } - return ioutil.NopCloser(bytes.NewReader(response)), nil + return io.NopCloser(bytes.NewReader(response)), nil } func TestEvents_CreateUpdateDeleteEvent(t *testing.T) { diff --git a/query.go b/query.go index e2ac4416..c64425bd 100644 --- a/query.go +++ b/query.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "reflect" "strconv" "time" @@ -110,7 +110,7 @@ const ( ) // NewQueryParams takes a query string and returns a set of QueryParams with -// a query window of one hour since now and a set of sensible default vakues +// a query window of one hour since now and a set of sensible default values func NewQueryParams(query string) *QueryParams { endTime := time.Now().Unix() startTime := endTime - LastHour @@ -173,7 +173,7 @@ func (q *Query) Execute() (*QueryResponse, error) { } defer resp.Close() - body, err := ioutil.ReadAll(resp) + body, err := io.ReadAll(resp) if err != nil { return nil, err } diff --git a/query_example_test.go b/query_example_test.go index 09b12103..c0db9490 100644 --- a/query_example_test.go +++ b/query_example_test.go @@ -2,7 +2,7 @@ package wavefront_test import ( "fmt" - "io/ioutil" + "io" "log" "github.com/WavefrontHQ/go-wavefront-management-api/v2" @@ -41,7 +41,7 @@ func ExampleQuery() { // The raw JSON response is available as RawResponse. // This can be useful for debugging - b, _ := ioutil.ReadAll(result.RawResponse) + b, _ := io.ReadAll(result.RawResponse) fmt.Println(string(b)) // The timeseries response can now be used to explore the results diff --git a/query_test.go b/query_test.go index d8fa4375..fd1c8722 100644 --- a/query_test.go +++ b/query_test.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" + "os" "strconv" "testing" "time" @@ -21,7 +21,7 @@ type MockWavefrontClient struct { } func (m MockWavefrontClient) Do(req *http.Request) (io.ReadCloser, error) { - return ioutil.NopCloser(bytes.NewReader(m.Response)), nil + return io.NopCloser(bytes.NewReader(m.Response)), nil } func TestQuery(t *testing.T) { @@ -61,7 +61,7 @@ func TestQuery(t *testing.T) { t.Fatal("error executing query:", err) } - raw, err := ioutil.ReadAll(resp.RawResponse) + raw, err := io.ReadAll(resp.RawResponse) if err != nil { t.Error(err) } @@ -74,7 +74,7 @@ func TestQuery(t *testing.T) { func getQueryOutputFromFixture(fixture string) (*QueryResponse, error) { baseurl, _ := url.Parse("http://testing.wavefront.com") - response, err := ioutil.ReadFile(fixture) + response, err := os.ReadFile(fixture) if err != nil { return nil, err } diff --git a/search.go b/search.go index 06d583a1..4912d7c7 100644 --- a/search.go +++ b/search.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "time" ) @@ -153,7 +153,7 @@ func (s *Search) Execute() (*SearchResponse, error) { } defer resp.Close() - body, err := ioutil.ReadAll(resp) + body, err := io.ReadAll(resp) if err != nil { return nil, err } diff --git a/search_test.go b/search_test.go index 620900ac..e73eb1c3 100644 --- a/search_test.go +++ b/search_test.go @@ -4,9 +4,9 @@ import ( "bytes" "encoding/json" "io" - "io/ioutil" "net/http" "net/url" + "os" "testing" asserts "github.com/stretchr/testify/assert" @@ -21,7 +21,7 @@ type MockSearchClient struct { func (m MockSearchClient) Do(req *http.Request) (io.ReadCloser, error) { p := SearchParams{} - b, _ := ioutil.ReadAll(req.Body) + b, _ := io.ReadAll(req.Body) err := json.Unmarshal(b, &p) if err != nil { m.T.Fatal(err) @@ -35,13 +35,13 @@ func (m MockSearchClient) Do(req *http.Request) (io.ReadCloser, error) { m.T.Errorf("deleted search path expected /api/v2/search/alert/deleted, got %s", req.URL.Path) } - return ioutil.NopCloser(bytes.NewReader(m.Response)), nil + return io.NopCloser(bytes.NewReader(m.Response)), nil } func TestDefensiveCopy(t *testing.T) { assert := asserts.New(t) baseurl, _ := url.Parse("http://testing.wavefront.com") - response, err := ioutil.ReadFile("./fixtures/search-alert-response.json") + response, err := os.ReadFile("./fixtures/search-alert-response.json") if err != nil { t.Fatal(err) } @@ -88,7 +88,7 @@ func TestSearch(t *testing.T) { sp := &SearchParams{ Conditions: []*SearchCondition{sc}, } - response, err := ioutil.ReadFile("./fixtures/search-alert-response.json") + response, err := os.ReadFile("./fixtures/search-alert-response.json") if err != nil { t.Fatal(err) } @@ -113,7 +113,7 @@ func TestSearch(t *testing.T) { t.Fatal("error executing query:", err) } - raw, err := ioutil.ReadAll(resp.RawResponse) + raw, err := io.ReadAll(resp.RawResponse) if err != nil { t.Error(err) } diff --git a/target_test.go b/target_test.go index 5a07e1e7..41a25843 100644 --- a/target_test.go +++ b/target_test.go @@ -2,9 +2,9 @@ package wavefront import ( "io" - "io/ioutil" "net/http" "net/url" + "os" "testing" asserts "github.com/stretchr/testify/assert" @@ -67,7 +67,7 @@ func TestTargets_CreateUpdateDeleteTarget(t *testing.T) { }, } - tmpl, _ := ioutil.ReadFile("./target-template.tmpl") + tmpl, _ := os.ReadFile("./target-template.tmpl") target := Target{ Title: "test target", diff --git a/targets_example_test.go b/targets_example_test.go index e4b39cb1..b61d5257 100644 --- a/targets_example_test.go +++ b/targets_example_test.go @@ -1,8 +1,8 @@ package wavefront_test import ( - "io/ioutil" "log" + "os" "github.com/WavefrontHQ/go-wavefront-management-api/v2" ) @@ -22,7 +22,7 @@ func ExampleTargets() { targets := client.Targets() - tmpl, _ := ioutil.ReadFile("./target-template.tmpl") + tmpl, _ := os.ReadFile("./target-template.tmpl") target := wavefront.Target{ Title: "test target", diff --git a/testing.go b/testing.go index 0d25dbb5..ad444437 100644 --- a/testing.go +++ b/testing.go @@ -5,8 +5,8 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" + "os" "reflect" "testing" ) @@ -15,13 +15,13 @@ import ( // iface is the destination type we need marshal data into from the request // iface can be utilized to ensure the request body is properly being marshalled and values are set as expected func testDo(t *testing.T, req *http.Request, fixture, method string, iface interface{}) (io.ReadCloser, error) { - response, err := ioutil.ReadFile(fixture) + response, err := os.ReadFile(fixture) if err != nil { t.Fatal(err) } assertEqual(t, method, req.Method) if req.Body != nil { - body, _ := ioutil.ReadAll(req.Body) + body, _ := io.ReadAll(req.Body) err = json.Unmarshal(body, iface) if err != nil { t.Fatal(err) @@ -29,7 +29,7 @@ func testDo(t *testing.T, req *http.Request, fixture, method string, iface inter } else { t.Log("Request body was nil, if this is expected please ignore...") } - return ioutil.NopCloser(bytes.NewReader(response)), nil + return io.NopCloser(bytes.NewReader(response)), nil } // Helps expedite the boilerplate code for testing client requests against paginated results diff --git a/usergroup_test.go b/usergroup_test.go index 23b7b02f..a63c32f9 100644 --- a/usergroup_test.go +++ b/usergroup_test.go @@ -4,9 +4,9 @@ import ( "bytes" "encoding/json" "io" - "io/ioutil" "net/http" "net/url" + "os" "testing" ) @@ -49,7 +49,7 @@ func TestUserGroups_Find(t *testing.T) { } func (m *MockCrudUserGroupClient) Do(req *http.Request) (io.ReadCloser, error) { - resp, err := ioutil.ReadFile("./fixtures/crud-usergroup-response.json") + resp, err := os.ReadFile("./fixtures/crud-usergroup-response.json") if err != nil { m.T.Fatal(err) } @@ -59,13 +59,13 @@ func (m *MockCrudUserGroupClient) Do(req *http.Request) (io.ReadCloser, error) { } if req.Body != nil { - body, _ := ioutil.ReadAll(req.Body) + body, _ := io.ReadAll(req.Body) // The calls for adding/removing users only transmit an array of strings // Not an actual UserGroup object. var addRemoveBody []string if err := json.Unmarshal(body, &addRemoveBody); err == nil { - return ioutil.NopCloser(bytes.NewReader(resp)), nil + return io.NopCloser(bytes.NewReader(resp)), nil } userGroup := UserGroup{} @@ -75,7 +75,7 @@ func (m *MockCrudUserGroupClient) Do(req *http.Request) (io.ReadCloser, error) { } } - return ioutil.NopCloser(bytes.NewReader(resp)), nil + return io.NopCloser(bytes.NewReader(resp)), nil } func Test_CreatReadUpdateDelete(t *testing.T) {