Skip to content

Commit

Permalink
chore: remove refs to deprecated io/ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
testwill committed Jun 18, 2023
1 parent 3062446 commit 0cb62a4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions http_prettifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"compress/gzip"
"fmt"
"github.com/buger/goreplay/proto"
"io/ioutil"
"io"
"net/http/httputil"
"strconv"
)
Expand All @@ -31,7 +31,7 @@ func prettifyHTTP(p []byte) []byte {
if tEnc {
buf := bytes.NewReader(content)
r := httputil.NewChunkedReader(buf)
content, _ = ioutil.ReadAll(r)
content, _ = io.ReadAll(r)

headers = proto.DeleteHeader(headers, []byte("Transfer-Encoding"))

Expand All @@ -48,7 +48,7 @@ func prettifyHTTP(p []byte) []byte {
return []byte{}
}

content, err = ioutil.ReadAll(g)
content, err = io.ReadAll(g)
if err != nil {
Debug(1, fmt.Sprintf("[HTTP-PRETTIFIER] %q", err))
return p
Expand Down
3 changes: 1 addition & 2 deletions input_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"os"
"sync"
Expand Down Expand Up @@ -288,7 +287,7 @@ func (expectedCaptureFile *CaptureFile) PayloadsEqual(other []*Message) bool {
}

func CreateCaptureFile(requestGenerator *RequestGenerator) *CaptureFile {
f, err := ioutil.TempFile("", "testmainconf")
f, err := os.CreateTemp("", "testmainconf")
if err != nil {
panic(err)
}
Expand Down
9 changes: 5 additions & 4 deletions input_raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"github.com/buger/goreplay/internal/capture"
"github.com/buger/goreplay/internal/tcp"
"github.com/buger/goreplay/proto"
"io/ioutil"
"io"
"os"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -222,12 +223,12 @@ func TestRAWInputIPv6(t *testing.T) {
func TestInputRAWChunkedEncoding(t *testing.T) {
wg := new(sync.WaitGroup)

fileContent, _ := ioutil.ReadFile("README.md")
fileContent, _ := os.ReadFile("README.md")

// Origing and Replay server initialization
origin := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
ioutil.ReadAll(r.Body)
io.ReadAll(r.Body)

wg.Done()
}))
Expand All @@ -244,7 +245,7 @@ func TestInputRAWChunkedEncoding(t *testing.T) {

replay := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
body, _ := ioutil.ReadAll(r.Body)
body, _ := io.ReadAll(r.Body)

if !bytes.Equal(body, fileContent) {
buf, _ := httputil.DumpRequest(r, true)
Expand Down
5 changes: 2 additions & 3 deletions input_tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"log"
"math/big"
"net"
Expand Down Expand Up @@ -86,11 +85,11 @@ func TestTCPInputSecure(t *testing.T) {
IPAddresses: []net.IP{net.ParseIP("127.0.0.1"), net.ParseIP("::")},
})

serverCertPemFile, _ := ioutil.TempFile("", "server.crt")
serverCertPemFile, _ := os.CreateTemp("", "server.crt")
serverCertPemFile.Write(serverCertPem)
serverCertPemFile.Close()

serverPrivPemFile, _ := ioutil.TempFile("", "server.key")
serverPrivPemFile, _ := os.CreateTemp("", "server.key")
serverPrivPemFile.Write(serverPrivPem)
serverPrivPemFile.Close()

Expand Down
4 changes: 2 additions & 2 deletions kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"errors"
"fmt"
"github.com/buger/goreplay/proto"
"io/ioutil"
"os"
"log"

"github.com/Shopify/sarama"
Expand Down Expand Up @@ -82,7 +82,7 @@ func NewTLSConfig(clientCertFile, clientKeyFile, caCertFile string) (*tls.Config
}
// Load CA cert
if caCertFile != "" {
caCert, err := ioutil.ReadFile(caCertFile)
caCert, err := os.ReadFile(caCertFile)
if err != nil {
return &tlsConfig, err
}
Expand Down
4 changes: 2 additions & 2 deletions output_http_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package goreplay

import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
_ "net/http/httputil"
Expand All @@ -25,7 +25,7 @@ func TestHTTPOutput(t *testing.T) {

if req.Method == "POST" {
defer req.Body.Close()
body, _ := ioutil.ReadAll(req.Body)
body, _ := io.ReadAll(req.Body)

if string(body) != "a=1&b=2" {
t.Error("Wrong POST body:", string(body))
Expand Down

0 comments on commit 0cb62a4

Please sign in to comment.