Skip to content

Commit

Permalink
clear golangci-lint warnings/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
casualjim committed Nov 28, 2022
1 parent 93d335a commit da56347
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 71 deletions.
3 changes: 1 addition & 2 deletions client/keepalive.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package client

import (
"io"
"io/ioutil"
"net/http"
"sync/atomic"
)
Expand Down Expand Up @@ -50,7 +49,7 @@ func (d *drainingReadCloser) Close() error {
// some bytes, but the closer ignores them to keep the underling
// connection open.
//nolint:errcheck
io.Copy(ioutil.Discard, d.rdr)
io.Copy(io.Discard, d.rdr)
}
return d.rdr.Close()
}
13 changes: 6 additions & 7 deletions client/keepalive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"bytes"
"io"
"io/ioutil"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -39,10 +38,10 @@ func (c *countingReadCloser) Close() error {

func TestDrainingReadCloser(t *testing.T) {
rdr := newCountingReader(bytes.NewBufferString("There are many things to do"), false)
prevDisc := ioutil.Discard
prevDisc := io.Discard
disc := bytes.NewBuffer(nil)
ioutil.Discard = disc
defer func() { ioutil.Discard = prevDisc }()
io.Discard = disc
defer func() { io.Discard = prevDisc }()

buf := make([]byte, 5)
ts := &drainingReadCloser{rdr: rdr}
Expand All @@ -57,10 +56,10 @@ func TestDrainingReadCloser(t *testing.T) {

func TestDrainingReadCloser_SeenEOF(t *testing.T) {
rdr := newCountingReader(bytes.NewBufferString("There are many things to do"), true)
prevDisc := ioutil.Discard
prevDisc := io.Discard
disc := bytes.NewBuffer(nil)
ioutil.Discard = disc
defer func() { ioutil.Discard = prevDisc }()
io.Discard = disc
defer func() { io.Discard = prevDisc }()

buf := make([]byte, 5)
ts := &drainingReadCloser{rdr: rdr}
Expand Down
5 changes: 0 additions & 5 deletions client/opentelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,3 @@ func newConfig(opts ...OpenTelemetryOpt) *config {
func version() string {
return instrumentationVersion
}

// SemVersion is the semantic version to be supplied to tracer/meter creation.
func semVersion() string {
return "semver:" + version()
}
3 changes: 2 additions & 1 deletion client/opentelemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ func Test_injectOpenTelemetrySpanContext(t *testing.T) {
header := map[string][]string{}
tr := newOpenTelemetryTransport(&mockRuntime{runtime.TestClientRequest{Headers: header}}, "", nil)
tr.config.Propagator = propagation.TraceContext{}
tr.Submit(operation)
_, err := tr.Submit(operation)
assert.NoError(t, err)

assert.Len(t, header, 1)
}
Expand Down
3 changes: 1 addition & 2 deletions client/opentracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"testing"

"github.com/go-openapi/strfmt"
Expand Down Expand Up @@ -33,7 +32,7 @@ func (r tres) GetHeaders(_ string) []string {
return []string{"the headers", "the headers2"}
}
func (r tres) Body() io.ReadCloser {
return ioutil.NopCloser(bytes.NewBufferString("the content"))
return io.NopCloser(bytes.NewBufferString("the content"))
}

type mockRuntime struct {
Expand Down
35 changes: 17 additions & 18 deletions client/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/xml"
"errors"
"io"
"io/ioutil"
"mime"
"mime/multipart"
"net/http"
Expand Down Expand Up @@ -165,7 +164,7 @@ func TestBuildRequest_BuildHTTP_Payload(t *testing.T) {
assert.Equal(t, "world", req.URL.Query().Get("hello"))
assert.Equal(t, "/flats/1234/", req.URL.Path)
expectedBody, _ := json.Marshal(bd)
actualBody, _ := ioutil.ReadAll(req.Body)
actualBody, _ := io.ReadAll(req.Body)
assert.Equal(t, append(expectedBody, '\n'), actualBody)
}
}
Expand Down Expand Up @@ -197,7 +196,7 @@ func TestBuildRequest_BuildHTTP_SetsInAuth(t *testing.T) {
assert.Equal(t, "world", req.URL.Query().Get("hello"))
assert.Equal(t, "/flats/1234/", req.URL.Path)
expectedBody, _ := json.Marshal(bd)
actualBody, _ := ioutil.ReadAll(req.Body)
actualBody, _ := io.ReadAll(req.Body)
assert.Equal(t, append(expectedBody, '\n'), actualBody)
}
}
Expand All @@ -224,7 +223,7 @@ func TestBuildRequest_BuildHTTP_XMLPayload(t *testing.T) {
assert.Equal(t, "world", req.URL.Query().Get("hello"))
assert.Equal(t, "/flats/1234/", req.URL.Path)
expectedBody, _ := xml.Marshal(bd)
actualBody, _ := ioutil.ReadAll(req.Body)
actualBody, _ := io.ReadAll(req.Body)
assert.Equal(t, expectedBody, actualBody)
}
}
Expand All @@ -247,7 +246,7 @@ func TestBuildRequest_BuildHTTP_TextPayload(t *testing.T) {
assert.Equal(t, "world", req.URL.Query().Get("hello"))
assert.Equal(t, "/flats/1234/", req.URL.Path)
expectedBody := []byte(bd)
actualBody, _ := ioutil.ReadAll(req.Body)
actualBody, _ := io.ReadAll(req.Body)
assert.Equal(t, expectedBody, actualBody)
}
}
Expand All @@ -269,7 +268,7 @@ func TestBuildRequest_BuildHTTP_Form(t *testing.T) {
assert.Equal(t, "world", req.URL.Query().Get("hello"))
assert.Equal(t, "/flats/1234/", req.URL.Path)
expected := []byte("something=some+value")
actual, _ := ioutil.ReadAll(req.Body)
actual, _ := io.ReadAll(req.Body)
assert.Equal(t, expected, actual)
}
}
Expand All @@ -292,7 +291,7 @@ func TestBuildRequest_BuildHTTP_Form_URLEncoded(t *testing.T) {
assert.Equal(t, "world", req.URL.Query().Get("hello"))
assert.Equal(t, "/flats/1234/", req.URL.Path)
expected := []byte("something=some+value")
actual, _ := ioutil.ReadAll(req.Body)
actual, _ := io.ReadAll(req.Body)
assert.Equal(t, expected, actual)
}
}
Expand All @@ -316,7 +315,7 @@ func TestBuildRequest_BuildHTTP_Form_Content_Length(t *testing.T) {
assert.Condition(t, func() bool { return req.ContentLength > 0 },
"ContentLength must great than 0. got %d", req.ContentLength)
expected := []byte("something=some+value")
actual, _ := ioutil.ReadAll(req.Body)
actual, _ := io.ReadAll(req.Body)
assert.Equal(t, expected, actual)
}
}
Expand All @@ -339,7 +338,7 @@ func TestBuildRequest_BuildHTTP_FormMultipart(t *testing.T) {
assert.Equal(t, "/flats/1234/", req.URL.Path)
expected1 := []byte("Content-Disposition: form-data; name=\"something\"")
expected2 := []byte("some value")
actual, _ := ioutil.ReadAll(req.Body)
actual, _ := io.ReadAll(req.Body)
actuallines := bytes.Split(actual, []byte("\r\n"))
assert.Equal(t, 6, len(actuallines))
boundary := string(actuallines[0])
Expand Down Expand Up @@ -371,7 +370,7 @@ func TestBuildRequest_BuildHTTP_FormMultiples(t *testing.T) {
expected1 := []byte("Content-Disposition: form-data; name=\"something\"")
expected2 := []byte("some value")
expected3 := []byte("another value")
actual, _ := ioutil.ReadAll(req.Body)
actual, _ := io.ReadAll(req.Body)
actuallines := bytes.Split(actual, []byte("\r\n"))
assert.Equal(t, 10, len(actuallines))
boundary := string(actuallines[0])
Expand All @@ -388,8 +387,8 @@ func TestBuildRequest_BuildHTTP_FormMultiples(t *testing.T) {
}

func TestBuildRequest_BuildHTTP_Files(t *testing.T) {
cont, _ := ioutil.ReadFile("./runtime.go")
cont2, _ := ioutil.ReadFile("./request.go")
cont, _ := os.ReadFile("./runtime.go")
cont2, _ := os.ReadFile("./request.go")
reqWrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, reg strfmt.Registry) error {
_ = req.SetFormParam("something", "some value")
_ = req.SetFileParam("file", mustGetFile("./runtime.go"))
Expand Down Expand Up @@ -420,7 +419,7 @@ func TestBuildRequest_BuildHTTP_Files(t *testing.T) {
mpf, _ := mpff.Open()
defer mpf.Close()
assert.Equal(t, filename, mpff.Filename)
actual, _ := ioutil.ReadAll(mpf)
actual, _ := io.ReadAll(mpf)
assert.Equal(t, content, actual)
}
fileverifier("file", 0, "runtime.go", cont)
Expand All @@ -432,8 +431,8 @@ func TestBuildRequest_BuildHTTP_Files(t *testing.T) {
}
}
func TestBuildRequest_BuildHTTP_Files_URLEncoded(t *testing.T) {
cont, _ := ioutil.ReadFile("./runtime.go")
cont2, _ := ioutil.ReadFile("./request.go")
cont, _ := os.ReadFile("./runtime.go")
cont2, _ := os.ReadFile("./request.go")
reqWrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, reg strfmt.Registry) error {
_ = req.SetFormParam("something", "some value")
_ = req.SetFileParam("file", mustGetFile("./runtime.go"))
Expand Down Expand Up @@ -464,7 +463,7 @@ func TestBuildRequest_BuildHTTP_Files_URLEncoded(t *testing.T) {
mpf, _ := mpff.Open()
defer mpf.Close()
assert.Equal(t, filename, mpff.Filename)
actual, _ := ioutil.ReadAll(mpf)
actual, _ := io.ReadAll(mpf)
assert.Equal(t, content, actual)
}
fileverifier("file", 0, "runtime.go", cont)
Expand Down Expand Up @@ -611,15 +610,15 @@ func TestGetBodyCallsBeforeRoundTrip(t *testing.T) {
// Read the body once before sending the request
body, err := req.GetBody()
require.NoError(t, err)
bodyContent, err := ioutil.ReadAll(io.Reader(body))
bodyContent, err := io.ReadAll(io.Reader(body))
require.EqualValues(t, req.ContentLength, len(bodyContent))
require.NoError(t, err)
require.EqualValues(t, "\"test body\"\n", string(bodyContent))

// Read the body a second time before sending the request
body, err = req.GetBody()
require.NoError(t, err)
bodyContent, err = ioutil.ReadAll(io.Reader(body))
bodyContent, err = io.ReadAll(io.Reader(body))
require.NoError(t, err)
require.EqualValues(t, req.ContentLength, len(bodyContent))
require.EqualValues(t, "\"test body\"\n", string(bodyContent))
Expand Down
4 changes: 2 additions & 2 deletions client/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package client

import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"

Expand All @@ -31,7 +31,7 @@ func TestResponse(t *testing.T) {
under.StatusCode = 392
under.Header = make(http.Header)
under.Header.Set("Blah", "blah blah")
under.Body = ioutil.NopCloser(bytes.NewBufferString("some content"))
under.Body = io.NopCloser(bytes.NewBufferString("some content"))

var resp runtime.ClientResponse = response{under}
assert.EqualValues(t, under.StatusCode, resp.Code())
Expand Down
6 changes: 2 additions & 4 deletions client/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"mime"
"net/http"
"net/http/httputil"
"os"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -164,7 +164,7 @@ func TLSClientAuth(opts TLSClientOptions) (*tls.Config, error) {
cfg.RootCAs = caCertPool
} else if opts.CA != "" {
// load ca cert
caCert, err := ioutil.ReadFile(opts.CA)
caCert, err := os.ReadFile(opts.CA)
if err != nil {
return nil, fmt.Errorf("tls client ca: %v", err)
}
Expand All @@ -181,8 +181,6 @@ func TLSClientAuth(opts TLSClientOptions) (*tls.Config, error) {
cfg.ServerName = opts.ServerName
}

cfg.BuildNameToCertificate()

return cfg, nil
}

Expand Down
22 changes: 11 additions & 11 deletions client/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"encoding/json"
"encoding/xml"
"errors"
"io/ioutil"
"io"
"net/http"
"net/http/cookiejar"
"net/http/httptest"
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestRuntime_TLSAuthConfig(t *testing.T) {
}

func TestRuntime_TLSAuthConfigWithRSAKey(t *testing.T) {
keyPem, err := ioutil.ReadFile("../fixtures/certs/myclient.key")
keyPem, err := os.ReadFile("../fixtures/certs/myclient.key")
require.NoError(t, err)

keyDer, _ := pem.Decode(keyPem)
Expand All @@ -79,7 +79,7 @@ func TestRuntime_TLSAuthConfigWithRSAKey(t *testing.T) {
key, err := x509.ParsePKCS1PrivateKey(keyDer.Bytes)
require.NoError(t, err)

certPem, err := ioutil.ReadFile("../fixtures/certs/myclient.crt")
certPem, err := os.ReadFile("../fixtures/certs/myclient.crt")
require.NoError(t, err)

certDer, _ := pem.Decode(certPem)
Expand All @@ -101,7 +101,7 @@ func TestRuntime_TLSAuthConfigWithRSAKey(t *testing.T) {
}

func TestRuntime_TLSAuthConfigWithECKey(t *testing.T) {
keyPem, err := ioutil.ReadFile("../fixtures/certs/myclient-ecc.key")
keyPem, err := os.ReadFile("../fixtures/certs/myclient-ecc.key")
require.NoError(t, err)

_, remainder := pem.Decode(keyPem)
Expand All @@ -111,7 +111,7 @@ func TestRuntime_TLSAuthConfigWithECKey(t *testing.T) {
key, err := x509.ParseECPrivateKey(keyDer.Bytes)
require.NoError(t, err)

certPem, err := ioutil.ReadFile("../fixtures/certs/myclient-ecc.crt")
certPem, err := os.ReadFile("../fixtures/certs/myclient-ecc.crt")
require.NoError(t, err)

certDer, _ := pem.Decode(certPem)
Expand All @@ -133,7 +133,7 @@ func TestRuntime_TLSAuthConfigWithECKey(t *testing.T) {
}

func TestRuntime_TLSAuthConfigWithLoadedCA(t *testing.T) {
certPem, err := ioutil.ReadFile("../fixtures/certs/myCA.crt")
certPem, err := os.ReadFile("../fixtures/certs/myCA.crt")
require.NoError(t, err)

block, _ := pem.Decode(certPem)
Expand All @@ -154,7 +154,7 @@ func TestRuntime_TLSAuthConfigWithLoadedCA(t *testing.T) {
}

func TestRuntime_TLSAuthConfigWithLoadedCAPool(t *testing.T) {
certPem, err := ioutil.ReadFile("../fixtures/certs/myCA.crt")
certPem, err := os.ReadFile("../fixtures/certs/myCA.crt")
require.NoError(t, err)

block, _ := pem.Decode(certPem)
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestRuntime_TLSAuthConfigWithLoadedCAPool(t *testing.T) {
}

func TestRuntime_TLSAuthConfigWithLoadedCAPoolAndLoadedCA(t *testing.T) {
certPem, err := ioutil.ReadFile("../fixtures/certs/myCA.crt")
certPem, err := os.ReadFile("../fixtures/certs/myCA.crt")
require.NoError(t, err)

block, _ := pem.Decode(certPem)
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestRuntime_ManualCertificateValidation(t *testing.T) {

// root cert
rootCertFile := "../fixtures/certs/myCA.crt"
rootCertPem, err := ioutil.ReadFile(rootCertFile)
rootCertPem, err := os.ReadFile(rootCertFile)
require.NoError(t, err)
rootCertRaw, _ := pem.Decode(rootCertPem)
require.NotNil(t, rootCertRaw)
Expand Down Expand Up @@ -623,7 +623,7 @@ func TestRuntime_CustomTransport(t *testing.T) {
buf := bytes.NewBuffer(nil)
enc := json.NewEncoder(buf)
_ = enc.Encode(result)
resp.Body = ioutil.NopCloser(buf)
resp.Body = io.NopCloser(buf)
return &resp, nil
})

Expand Down Expand Up @@ -969,7 +969,7 @@ func (o *overrideRoundTripper) RoundTrip(req *http.Request) (*http.Response, err
o.overriden = true
res := new(http.Response)
res.StatusCode = 200
res.Body = ioutil.NopCloser(bytes.NewBufferString("OK"))
res.Body = io.NopCloser(bytes.NewBufferString("OK"))
return res, nil
}

Expand Down
3 changes: 1 addition & 2 deletions client_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package runtime

import (
"io"
"io/ioutil"
"net/http"
"net/url"
"time"
Expand Down Expand Up @@ -79,7 +78,7 @@ type NamedReadCloser interface {
func NamedReader(name string, rdr io.Reader) NamedReadCloser {
rc, ok := rdr.(io.ReadCloser)
if !ok {
rc = ioutil.NopCloser(rdr)
rc = io.NopCloser(rdr)
}
return &namedReadCloser{
name: name,
Expand Down
Loading

0 comments on commit da56347

Please sign in to comment.