Skip to content

Commit

Permalink
Fix linting issue after Golang upgrade.
Browse files Browse the repository at this point in the history
- Go lang upgrade broke linter, I missed this till CI ran. 🎉 Thanks CI

Signed-off-by: Brendan Winter <[email protected]>
  • Loading branch information
bwinter committed Oct 6, 2023
1 parent 9745e17 commit 7b5e5fd
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 47 deletions.
4 changes: 2 additions & 2 deletions alerts_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package wavefront_test
import (
"fmt"
"github.com/WavefrontHQ/go-wavefront-management-api/v2"
"io/ioutil"
"log"
"os"
)

func ExampleAlerts() {
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 5 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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(
Expand Down
9 changes: 4 additions & 5 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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) != "" {
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"testing"
"time"

Expand Down Expand Up @@ -61,22 +61,22 @@ 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)
}
if req.Method != m.method {
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) {
Expand Down
6 changes: 3 additions & 3 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"reflect"
"strconv"
"time"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions query_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package wavefront_test

import (
"fmt"
"io/ioutil"
"io"
"log"

"github.com/WavefrontHQ/go-wavefront-management-api/v2"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"strconv"
"testing"
"time"
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"time"
)

Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"testing"

asserts "github.com/stretchr/testify/assert"
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package wavefront

import (
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"testing"

asserts "github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions targets_example_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package wavefront_test

import (
"io/ioutil"
"log"
"os"

"github.com/WavefrontHQ/go-wavefront-management-api/v2"
)
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"reflect"
"testing"
)
Expand All @@ -15,21 +15,21 @@ 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)
}
} 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
Expand Down
Loading

0 comments on commit 7b5e5fd

Please sign in to comment.