Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated ioutil package #112

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions envelope_stream_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package loggregator
import (
"context"
"crypto/tls"
"io/ioutil"
"io"
"log"
"time"

Expand Down Expand Up @@ -41,7 +41,7 @@ func NewEnvelopeStreamConnector(
addr: addr,
tlsConf: t,

log: log.New(ioutil.Discard, "", 0),
log: log.New(io.Discard, "", 0),
}

for _, o := range opts {
Expand Down
4 changes: 2 additions & 2 deletions fixtures_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package loggregator_test

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

//go:generate go get github.com/loggregator/go-bindata/...
Expand All @@ -13,7 +13,7 @@ import (
func fixture(filename string) string {
contents := MustAsset(filename)

tmpfile, err := ioutil.TempFile("", "")
tmpfile, err := os.CreateTemp("", "")
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions ingress_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package loggregator
import (
"crypto/tls"
"fmt"
"io/ioutil"
"io"
"log"
"strconv"
"time"
Expand Down Expand Up @@ -121,7 +121,7 @@ func NewIngressClient(tlsConfig *tls.Config, opts ...IngressOption) (*IngressCli
batchMaxSize: 100,
batchFlushInterval: 100 * time.Millisecond,
addr: "localhost:3458",
logger: log.New(ioutil.Discard, "", 0),
logger: log.New(io.Discard, "", 0),
closeErrors: make(chan error),
ctx: context.Background(),
}
Expand Down
5 changes: 3 additions & 2 deletions pulseemitter/pulseemitter_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pulseemitter_test

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

. "github.com/onsi/ginkgo/v2"
Expand All @@ -12,8 +12,9 @@ import (
)

func TestMetricemitter(t *testing.T) {
grpclog.SetLoggerV2(grpclog.NewLoggerV2(GinkgoWriter, ioutil.Discard, ioutil.Discard))
grpclog.SetLoggerV2(grpclog.NewLoggerV2(GinkgoWriter, io.Discard, io.Discard))
log.SetOutput(GinkgoWriter)

RegisterFailHandler(Fail)
RunSpecs(t, "Pulse Emitter Suite")
}
3 changes: 1 addition & 2 deletions rfc5424/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rfc5424
import (
"fmt"
"io"
"io/ioutil"
"strconv"
)

Expand Down Expand Up @@ -48,7 +47,7 @@ func (m *Message) ReadFrom(r io.Reader) (int64, error) {
return 0, err
}
r2 := io.LimitReader(r, int64(length))
buf, err := ioutil.ReadAll(r2)
buf, err := io.ReadAll(r2)
if err != nil {
return int64(n1 + len(buf)), err
}
Expand Down
7 changes: 3 additions & 4 deletions rlp_gateway_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"strings"
Expand All @@ -33,7 +32,7 @@ type GatewayLogger interface {
func NewRLPGatewayClient(addr string, opts ...RLPGatewayClientOption) *RLPGatewayClient {
c := &RLPGatewayClient{
addr: addr,
log: log.New(ioutil.Discard, "", 0),
log: log.New(io.Discard, "", 0),
doer: http.DefaultClient,
maxRetries: 10,
}
Expand Down Expand Up @@ -159,12 +158,12 @@ func (c *RLPGatewayClient) connect(
}

defer func() {
_, _ = io.Copy(ioutil.Discard, resp.Body)
_, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close()
}()

if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
c.log.Printf("failed to read body: %s", err)
return false
Expand Down
25 changes: 12 additions & 13 deletions rlp_gateway_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"sync"
Expand Down Expand Up @@ -43,7 +42,7 @@ var _ = Describe("RlpGatewayClient", func() {
defer close(ch)
spyDoer.resps = append(spyDoer.resps, &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(channelReader(ch)),
Body: io.NopCloser(channelReader(ch)),
})
spyDoer.errs = []error{nil}

Expand Down Expand Up @@ -79,7 +78,7 @@ var _ = Describe("RlpGatewayClient", func() {
defer close(ch)
spyDoer.resps = append(spyDoer.resps, &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(channelReader(ch)),
Body: io.NopCloser(channelReader(ch)),
})
spyDoer.errs = []error{nil}

Expand Down Expand Up @@ -184,7 +183,7 @@ var _ = Describe("RlpGatewayClient", func() {
defer close(ch)
spyDoer.resps = append(spyDoer.resps, &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(channelReader(ch)),
Body: io.NopCloser(channelReader(ch)),
})
spyDoer.errs = []error{nil}

Expand Down Expand Up @@ -222,7 +221,7 @@ var _ = Describe("RlpGatewayClient", func() {
ch := make(chan []byte, 100)
spyDoer.resps = append(spyDoer.resps, &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(channelReader(ch)),
Body: io.NopCloser(channelReader(ch)),
})
spyDoer.errs = []error{nil}

Expand Down Expand Up @@ -251,11 +250,11 @@ var _ = Describe("RlpGatewayClient", func() {
spyDoer.resps = append(spyDoer.resps,
&http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(channelReader(ch)),
Body: io.NopCloser(channelReader(ch)),
},
&http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(channelReader(noCloseCh)),
Body: io.NopCloser(channelReader(noCloseCh)),
})
spyDoer.errs = []error{nil, nil}

Expand All @@ -278,7 +277,7 @@ var _ = Describe("RlpGatewayClient", func() {
spyDoer.resps = append(spyDoer.resps, &http.Response{StatusCode: 500})
spyDoer.resps = append(spyDoer.resps, &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(channelReader(ch)),
Body: io.NopCloser(channelReader(ch)),
})
spyDoer.errs = []error{nil, nil, nil}
ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -300,7 +299,7 @@ var _ = Describe("RlpGatewayClient", func() {
defer close(ch)
spyDoer.resps = append(spyDoer.resps, &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(channelReader(ch)),
Body: io.NopCloser(channelReader(ch)),
})
spyDoer.errs = append(spyDoer.errs, nil)
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -395,7 +394,7 @@ var _ = Describe("RlpGatewayClient", func() {
ch := make(chan []byte, 100)
spyDoer.resps = append(spyDoer.resps, &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(channelReader(ch)),
Body: io.NopCloser(channelReader(ch)),
})
spyDoer.errs = append(spyDoer.errs, nil)

Expand Down Expand Up @@ -446,22 +445,22 @@ func (s *spyDoer) Do(r *http.Request) (*http.Response, error) {
if s.onlyErrs {
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(nil)),
Body: io.NopCloser(bytes.NewReader(nil)),
}, errors.New("default error")
}

if len(s.resps) == 0 {
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(nil)),
Body: io.NopCloser(bytes.NewReader(nil)),
}, nil
}

resp, err := s.resps[0], s.errs[0]
s.resps, s.errs = s.resps[1:], s.errs[1:]

if resp.Body == nil {
resp.Body = ioutil.NopCloser(bytes.NewReader(nil))
resp.Body = io.NopCloser(bytes.NewReader(nil))
}

return resp, err
Expand Down
5 changes: 3 additions & 2 deletions suite_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package loggregator_test

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

. "github.com/onsi/ginkgo/v2"
Expand All @@ -12,8 +12,9 @@ import (
)

func TestGoLoggregator(t *testing.T) {
grpclog.SetLoggerV2(grpclog.NewLoggerV2(GinkgoWriter, ioutil.Discard, ioutil.Discard))
grpclog.SetLoggerV2(grpclog.NewLoggerV2(GinkgoWriter, io.Discard, io.Discard))
log.SetOutput(GinkgoWriter)

RegisterFailHandler(Fail)
RunSpecs(t, "GoLoggregator Suite")
}