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 authored and dnaeon committed Jul 3, 2023
1 parent 64ebe73 commit ebbeaca
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions cassette/cassette.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -260,7 +259,7 @@ func New(name string) *Cassette {
// Load reads a cassette file from disk
func Load(name string) (*Cassette, error) {
c := New(name)
data, err := ioutil.ReadFile(c.File)
data, err := os.ReadFile(c.File)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions examples/https_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package vcr_test

import (
"io/ioutil"
"io"
"strings"
"testing"

Expand All @@ -51,7 +51,7 @@ func TestHTTPS(t *testing.T) {
t.Fatalf("Failed to get url %s: %s", url, err)
}

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("Failed to read response body: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package vcr_test

import (
"io/ioutil"
"io"
"strings"
"testing"

Expand All @@ -50,7 +50,7 @@ func TestSimple(t *testing.T) {
t.Fatalf("Failed to get url %s: %s", url, err)
}

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("Failed to read response body: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions recorder/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"bytes"
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httputil"
"os"
Expand Down Expand Up @@ -330,7 +329,7 @@ func (rec *Recorder) requestHandler(r *http.Request) (*cassette.Interaction, err
requestDuration := time.Since(start)
defer resp.Body.Close()

respBody, err := ioutil.ReadAll(resp.Body)
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
13 changes: 6 additions & 7 deletions recorder/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -65,7 +64,7 @@ func (tc testCase) run(client *http.Client, ctx context.Context, serverUrl strin
}
defer resp.Body.Close()

respBody, err := ioutil.ReadAll(resp.Body)
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
Expand Down Expand Up @@ -103,7 +102,7 @@ func newEchoHttpServer() *httptest.Server {
// newCassettePath creates a new path to be used for test cassettes,
// which reside in a temporary location.
func newCassettePath(name string) (string, error) {
dir, err := ioutil.TempDir(os.TempDir(), "go-vcr-")
dir, err := os.MkdirTemp(os.TempDir(), "go-vcr-")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -649,7 +648,7 @@ func TestPassthroughHandler(t *testing.T) {
if _, err := b.ReadFrom(r.Body); err != nil {
return false
}
r.Body = ioutil.NopCloser(&b)
r.Body = io.NopCloser(&b)

return r.Method == http.MethodPost && b.String() == "passthrough request"
})
Expand Down Expand Up @@ -1112,7 +1111,7 @@ func TestWithCustomMatcher(t *testing.T) {
defer resp.Body.Close()

// Body should be the same as the first recorded interaction
respBody, err := ioutil.ReadAll(resp.Body)
respBody, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
Expand All @@ -1131,12 +1130,12 @@ func TestWithCustomMatcher(t *testing.T) {

var reqBody []byte
var err error
reqBody, err = ioutil.ReadAll(r.Body)
reqBody, err = io.ReadAll(r.Body)
if err != nil {
t.Fatal("failed to read request body")
}
r.Body.Close()
r.Body = ioutil.NopCloser(bytes.NewBuffer(reqBody))
r.Body = io.NopCloser(bytes.NewBuffer(reqBody))

return r.Method == i.Method && r.URL.String() == i.URL && string(reqBody) == i.Body
}
Expand Down

0 comments on commit ebbeaca

Please sign in to comment.