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

chore: remove refs to deprecated io/ioutil #1202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
chore: remove refs to deprecated io/ioutil
testwill committed Jun 18, 2023
commit 0cb62a41ee3a1cfefae9f64825cac0aa84ad80ef
6 changes: 3 additions & 3 deletions http_prettifier.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import (
"compress/gzip"
"fmt"
"github.com/buger/goreplay/proto"
"io/ioutil"
"io"
"net/http/httputil"
"strconv"
)
@@ -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"))

@@ -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
3 changes: 1 addition & 2 deletions input_file_test.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"os"
"sync"
@@ -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)
}
9 changes: 5 additions & 4 deletions input_raw_test.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -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()
}))
@@ -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)
5 changes: 2 additions & 3 deletions input_tcp_test.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"log"
"math/big"
"net"
@@ -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()

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

"github.com/Shopify/sarama"
@@ -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
}
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"
@@ -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))