Skip to content

Commit 07f405d

Browse files
authoredAug 23, 2021
chore: stop using deprecated ioutil package (#467)
This package was deprecated in Go 1.16. This chore breaks compatability with Go 1.15 which is out of support.
1 parent afd6b76 commit 07f405d

15 files changed

+67
-76
lines changed
 

‎gexec/build.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"fmt"
88
"go/build"
9-
"io/ioutil"
109
"os"
1110
"os/exec"
1211
"path"
@@ -222,11 +221,11 @@ func temporaryDirectory() (string, error) {
222221
mu.Lock()
223222
defer mu.Unlock()
224223
if tmpDir == "" {
225-
tmpDir, err = ioutil.TempDir("", "gexec_artifacts")
224+
tmpDir, err = os.MkdirTemp("", "gexec_artifacts")
226225
if err != nil {
227226
return "", err
228227
}
229228
}
230229

231-
return ioutil.TempDir(tmpDir, "g")
230+
return os.MkdirTemp(tmpDir, "g")
232231
}

‎gexec/build_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gexec_test
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87

@@ -99,7 +98,7 @@ var _ = Describe(".BuildIn", func() {
9998
BeforeEach(func() {
10099
var err error
101100
original = os.Getenv("GOPATH")
102-
gopath, err = ioutil.TempDir("", "")
101+
gopath, err = os.MkdirTemp("", "")
103102
Expect(err).NotTo(HaveOccurred())
104103
copyFile(filepath.Join("_fixture", "firefly", "main.go"), filepath.Join(gopath, "src", target), "main.go")
105104
Expect(os.Setenv("GOPATH", filepath.Join(os.TempDir(), "emptyFakeGopath"))).To(Succeed())
@@ -235,7 +234,7 @@ var _ = Describe(".CompiledTestIn", func() {
235234
BeforeEach(func() {
236235
var err error
237236
original = os.Getenv("GOPATH")
238-
gopath, err = ioutil.TempDir("", "")
237+
gopath, err = os.MkdirTemp("", "")
239238
Expect(err).NotTo(HaveOccurred())
240239
copyFile(filepath.Join("_fixture", "firefly", "main.go"), filepath.Join(gopath, "src", target), "main.go")
241240
Expect(os.Setenv("GOPATH", filepath.Join(os.TempDir(), "emptyFakeGopath"))).To(Succeed())
@@ -278,7 +277,7 @@ var _ = Describe(".CompiledTestIn", func() {
278277

279278
func copyFile(source, directory, basename string) {
280279
Expect(os.MkdirAll(directory, 0755)).To(Succeed())
281-
content, err := ioutil.ReadFile(source)
280+
content, err := os.ReadFile(source)
282281
Expect(err).NotTo(HaveOccurred())
283-
Expect(ioutil.WriteFile(filepath.Join(directory, basename), content, 0644)).To(Succeed())
282+
Expect(os.WriteFile(filepath.Join(directory, basename), content, 0644)).To(Succeed())
284283
}

‎gexec/session_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package gexec_test
44

55
import (
66
"io"
7-
"io/ioutil"
87
"os/exec"
98
"syscall"
109
"time"
@@ -326,8 +325,8 @@ var _ = Describe("Session", func() {
326325

327326
When("discarding the output of the command", func() {
328327
BeforeEach(func() {
329-
outWriter = ioutil.Discard
330-
errWriter = ioutil.Discard
328+
outWriter = io.Discard
329+
errWriter = io.Discard
331330
})
332331

333332
It("executes succesfuly", func() {
@@ -387,8 +386,8 @@ var _ = Describe("Session", func() {
387386

388387
When("discarding the output of the command", func() {
389388
BeforeEach(func() {
390-
outWriter = ioutil.Discard
391-
errWriter = ioutil.Discard
389+
outWriter = io.Discard
390+
errWriter = io.Discard
392391
})
393392

394393
It("executes succesfuly", func() {

‎ghttp/handlers.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/base64"
77
"encoding/json"
88
"fmt"
9-
"io/ioutil"
9+
"io"
1010
"net/http"
1111
"net/url"
1212
"reflect"
@@ -117,7 +117,7 @@ func (g GHTTPWithGomega) VerifyHeaderKV(key string, values ...string) http.Handl
117117
func (g GHTTPWithGomega) VerifyBody(expectedBody []byte) http.HandlerFunc {
118118
return CombineHandlers(
119119
func(w http.ResponseWriter, req *http.Request) {
120-
body, err := ioutil.ReadAll(req.Body)
120+
body, err := io.ReadAll(req.Body)
121121
req.Body.Close()
122122
g.gomega.Expect(err).ShouldNot(HaveOccurred())
123123
g.gomega.Expect(body).Should(Equal(expectedBody), "Body Mismatch")
@@ -133,7 +133,7 @@ func (g GHTTPWithGomega) VerifyJSON(expectedJSON string) http.HandlerFunc {
133133
return CombineHandlers(
134134
g.VerifyMimeType("application/json"),
135135
func(w http.ResponseWriter, req *http.Request) {
136-
body, err := ioutil.ReadAll(req.Body)
136+
body, err := io.ReadAll(req.Body)
137137
req.Body.Close()
138138
g.gomega.Expect(err).ShouldNot(HaveOccurred())
139139
g.gomega.Expect(body).Should(MatchJSON(expectedJSON), "JSON Mismatch")
@@ -182,7 +182,7 @@ func (g GHTTPWithGomega) VerifyProtoRepresenting(expected proto.Message) http.Ha
182182
return CombineHandlers(
183183
g.VerifyContentType("application/x-protobuf"),
184184
func(w http.ResponseWriter, req *http.Request) {
185-
body, err := ioutil.ReadAll(req.Body)
185+
body, err := io.ReadAll(req.Body)
186186
g.gomega.Expect(err).ShouldNot(HaveOccurred())
187187
req.Body.Close()
188188

‎ghttp/test_server.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ package ghttp
111111
import (
112112
"fmt"
113113
"io"
114-
"io/ioutil"
115114
"net/http"
116115
"net/http/httptest"
117116
"net/http/httputil"
@@ -269,7 +268,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
269268
} else {
270269
s.rwMutex.Unlock()
271270
if s.GetAllowUnhandledRequests() {
272-
ioutil.ReadAll(req.Body)
271+
io.ReadAll(req.Body)
273272
req.Body.Close()
274273
w.WriteHeader(s.GetUnhandledRequestStatusCode())
275274
} else {

‎ghttp/test_server_test.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package ghttp_test
33
import (
44
"bytes"
55
"io"
6-
"io/ioutil"
76
"net/http"
87
"net/url"
98
"regexp"
@@ -60,7 +59,7 @@ var _ = Describe("TestServer", func() {
6059
Expect(err).ShouldNot(HaveOccurred())
6160
Expect(resp.StatusCode).Should(Equal(200))
6261

63-
body, err := ioutil.ReadAll(resp.Body)
62+
body, err := io.ReadAll(resp.Body)
6463
resp.Body.Close()
6564
Expect(err).ShouldNot(HaveOccurred())
6665

@@ -70,7 +69,7 @@ var _ = Describe("TestServer", func() {
7069
Expect(err).ShouldNot(HaveOccurred())
7170
Expect(resp.StatusCode).Should(Equal(200))
7271

73-
body2, err := ioutil.ReadAll(resp.Body)
72+
body2, err := io.ReadAll(resp.Body)
7473
resp.Body.Close()
7574
Expect(err).ShouldNot(HaveOccurred())
7675

@@ -102,7 +101,7 @@ var _ = Describe("TestServer", func() {
102101
Expect(err).ShouldNot(HaveOccurred())
103102
Expect(resp.StatusCode).Should(Equal(http.StatusForbidden))
104103

105-
data, err := ioutil.ReadAll(resp.Body)
104+
data, err := io.ReadAll(resp.Body)
106105
Expect(err).ShouldNot(HaveOccurred())
107106
Expect(data).Should(BeEmpty())
108107
})
@@ -792,7 +791,7 @@ var _ = Describe("TestServer", func() {
792791

793792
Expect(resp.StatusCode).Should(Equal(http.StatusCreated))
794793

795-
body, err := ioutil.ReadAll(resp.Body)
794+
body, err := io.ReadAll(resp.Body)
796795
Expect(err).ShouldNot(HaveOccurred())
797796
Expect(body).Should(Equal([]byte("sweet")))
798797

@@ -801,7 +800,7 @@ var _ = Describe("TestServer", func() {
801800

802801
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
803802

804-
body, err = ioutil.ReadAll(resp.Body)
803+
body, err = io.ReadAll(resp.Body)
805804
Expect(err).ShouldNot(HaveOccurred())
806805
Expect(body).Should(Equal([]byte("sour")))
807806
})
@@ -820,7 +819,7 @@ var _ = Describe("TestServer", func() {
820819
Expect(err).ShouldNot(HaveOccurred())
821820

822821
Expect(resp.StatusCode).Should(Equal(http.StatusCreated))
823-
Expect(ioutil.ReadAll(resp.Body)).Should(Equal([]byte("sweet")))
822+
Expect(io.ReadAll(resp.Body)).Should(Equal([]byte("sweet")))
824823
Expect(resp.Header.Get("X-Custom-Header")).Should(Equal("my header"))
825824
})
826825
})
@@ -854,7 +853,7 @@ var _ = Describe("TestServer", func() {
854853

855854
Expect(resp.StatusCode).Should(Equal(http.StatusCreated))
856855

857-
body, err := ioutil.ReadAll(resp.Body)
856+
body, err := io.ReadAll(resp.Body)
858857
Expect(err).ShouldNot(HaveOccurred())
859858
Expect(body).Should(Equal([]byte("tasty")))
860859

@@ -863,7 +862,7 @@ var _ = Describe("TestServer", func() {
863862

864863
Expect(resp.StatusCode).Should(Equal(http.StatusCreated))
865864

866-
body, err = ioutil.ReadAll(resp.Body)
865+
body, err = io.ReadAll(resp.Body)
867866
Expect(err).ShouldNot(HaveOccurred())
868867
Expect(body).Should(Equal([]byte("treat")))
869868
})
@@ -881,7 +880,7 @@ var _ = Describe("TestServer", func() {
881880

882881
Expect(err).ShouldNot(HaveOccurred())
883882
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
884-
body, err := ioutil.ReadAll(resp.Body)
883+
body, err := io.ReadAll(resp.Body)
885884
Expect(err).ShouldNot(HaveOccurred())
886885
Expect(body).Should(BeEmpty())
887886

@@ -905,7 +904,7 @@ var _ = Describe("TestServer", func() {
905904

906905
Expect(resp.StatusCode).Should(Equal(http.StatusCreated))
907906

908-
body, err := ioutil.ReadAll(resp.Body)
907+
body, err := io.ReadAll(resp.Body)
909908
Expect(err).ShouldNot(HaveOccurred())
910909
Expect(body).Should(MatchJSON("[1,2,3]"))
911910
})
@@ -990,7 +989,7 @@ var _ = Describe("TestServer", func() {
990989

991990
Expect(resp.StatusCode).Should(Equal(http.StatusCreated))
992991

993-
body, err := ioutil.ReadAll(resp.Body)
992+
body, err := io.ReadAll(resp.Body)
994993
Expect(err).ShouldNot(HaveOccurred())
995994
Expect(body).Should(MatchJSON(`{"Key": "Jim", "Value": "Codes"}`))
996995
})
@@ -1071,7 +1070,7 @@ var _ = Describe("TestServer", func() {
10711070
Expect(resp.StatusCode).Should(Equal(http.StatusCreated))
10721071

10731072
var received protobuf.SimpleMessage
1074-
body, err := ioutil.ReadAll(resp.Body)
1073+
body, err := io.ReadAll(resp.Body)
10751074
Expect(err).ShouldNot(HaveOccurred())
10761075
err = proto.Unmarshal(body, &received)
10771076
Expect(err).ShouldNot(HaveOccurred())

‎gmeasure/cache.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"crypto/md5"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
87
"os"
98
"path/filepath"
109
)
@@ -66,16 +65,16 @@ func (cache ExperimentCache) readHeader(filename string) (CachedExperimentHeader
6665
List returns a list of all Cached Experiments found in the cache.
6766
*/
6867
func (cache ExperimentCache) List() ([]CachedExperimentHeader, error) {
69-
out := []CachedExperimentHeader{}
70-
infos, err := ioutil.ReadDir(cache.Path)
68+
var out []CachedExperimentHeader
69+
entries, err := os.ReadDir(cache.Path)
7170
if err != nil {
7271
return out, err
7372
}
74-
for _, info := range infos {
75-
if filepath.Ext(info.Name()) != CACHE_EXT {
73+
for _, entry := range entries {
74+
if filepath.Ext(entry.Name()) != CACHE_EXT {
7675
continue
7776
}
78-
header, err := cache.readHeader(info.Name())
77+
header, err := cache.readHeader(entry.Name())
7978
if err != nil {
8079
return out, err
8180
}
@@ -88,15 +87,15 @@ func (cache ExperimentCache) List() ([]CachedExperimentHeader, error) {
8887
Clear empties out the cache - this will delete any and all detected cache files in the cache directory. Use with caution!
8988
*/
9089
func (cache ExperimentCache) Clear() error {
91-
infos, err := ioutil.ReadDir(cache.Path)
90+
entries, err := os.ReadDir(cache.Path)
9291
if err != nil {
9392
return err
9493
}
95-
for _, info := range infos {
96-
if filepath.Ext(info.Name()) != CACHE_EXT {
94+
for _, entry := range entries {
95+
if filepath.Ext(entry.Name()) != CACHE_EXT {
9796
continue
9897
}
99-
err := os.Remove(filepath.Join(cache.Path, info.Name()))
98+
err := os.Remove(filepath.Join(cache.Path, entry.Name()))
10099
if err != nil {
101100
return err
102101
}

‎matchers/be_a_directory_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package matchers_test
22

33
import (
4-
"io/ioutil"
54
"os"
65

76
. "github.com/onsi/ginkgo"
@@ -14,12 +13,12 @@ var _ = Describe("BeADirectoryMatcher", func() {
1413
It("should do the right thing", func() {
1514
Expect("/dne/test").ShouldNot(BeADirectory())
1615

17-
tmpFile, err := ioutil.TempFile("", "gomega-test-tempfile")
16+
tmpFile, err := os.CreateTemp("", "gomega-test-tempfile")
1817
Expect(err).ShouldNot(HaveOccurred())
1918
defer os.Remove(tmpFile.Name())
2019
Expect(tmpFile.Name()).ShouldNot(BeADirectory())
2120

22-
tmpDir, err := ioutil.TempDir("", "gomega-test-tempdir")
21+
tmpDir, err := os.MkdirTemp("", "gomega-test-tempdir")
2322
Expect(err).ShouldNot(HaveOccurred())
2423
defer os.Remove(tmpDir)
2524
Expect(tmpDir).Should(BeADirectory())

‎matchers/be_a_regular_file_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package matchers_test
22

33
import (
4-
"io/ioutil"
54
"os"
65

76
. "github.com/onsi/ginkgo"
@@ -14,12 +13,12 @@ var _ = Describe("BeARegularFileMatcher", func() {
1413
It("should do the right thing", func() {
1514
Expect("/dne/test").ShouldNot(BeARegularFile())
1615

17-
tmpFile, err := ioutil.TempFile("", "gomega-test-tempfile")
16+
tmpFile, err := os.CreateTemp("", "gomega-test-tempfile")
1817
Expect(err).ShouldNot(HaveOccurred())
1918
defer os.Remove(tmpFile.Name())
2019
Expect(tmpFile.Name()).Should(BeARegularFile())
2120

22-
tmpDir, err := ioutil.TempDir("", "gomega-test-tempdir")
21+
tmpDir, err := os.MkdirTemp("", "gomega-test-tempdir")
2322
Expect(err).ShouldNot(HaveOccurred())
2423
defer os.Remove(tmpDir)
2524
Expect(tmpDir).ShouldNot(BeARegularFile())

‎matchers/be_an_existing_file_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package matchers_test
22

33
import (
4-
"io/ioutil"
54
"os"
65

76
. "github.com/onsi/ginkgo"
@@ -14,12 +13,12 @@ var _ = Describe("BeAnExistingFileMatcher", func() {
1413
It("should do the right thing", func() {
1514
Expect("/dne/test").ShouldNot(BeAnExistingFile())
1615

17-
tmpFile, err := ioutil.TempFile("", "gomega-test-tempfile")
16+
tmpFile, err := os.CreateTemp("", "gomega-test-tempfile")
1817
Expect(err).ShouldNot(HaveOccurred())
1918
defer os.Remove(tmpFile.Name())
2019
Expect(tmpFile.Name()).Should(BeAnExistingFile())
2120

22-
tmpDir, err := ioutil.TempDir("", "gomega-test-tempdir")
21+
tmpDir, err := os.MkdirTemp("", "gomega-test-tempdir")
2322
Expect(err).ShouldNot(HaveOccurred())
2423
defer os.Remove(tmpDir)
2524
Expect(tmpDir).Should(BeAnExistingFile())

‎matchers/have_http_body_matcher.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package matchers
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"net/http/httptest"
88

@@ -81,7 +81,7 @@ func (matcher *HaveHTTPBodyMatcher) body(actual interface{}) ([]byte, error) {
8181
if a.Body != nil {
8282
defer a.Body.Close()
8383
var err error
84-
matcher.cachedBody, err = ioutil.ReadAll(a.Body)
84+
matcher.cachedBody, err = io.ReadAll(a.Body)
8585
if err != nil {
8686
return nil, fmt.Errorf("error reading response body: %w", err)
8787
}

‎matchers/have_http_body_matcher_test.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package matchers_test
22

33
import (
44
"bytes"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"net/http/httptest"
88
"strings"
@@ -15,13 +15,13 @@ var _ = Describe("HaveHTTPBody", func() {
1515
When("ACTUAL is *http.Response", func() {
1616
It("matches the body", func() {
1717
const body = "this is the body"
18-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader(body))}
18+
resp := &http.Response{Body: io.NopCloser(strings.NewReader(body))}
1919
Expect(resp).To(HaveHTTPBody(body))
2020
})
2121

2222
It("mismatches the body", func() {
2323
const body = "this is the body"
24-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader(body))}
24+
resp := &http.Response{Body: io.NopCloser(strings.NewReader(body))}
2525
Expect(resp).NotTo(HaveHTTPBody("something else"))
2626
})
2727
})
@@ -52,33 +52,33 @@ var _ = Describe("HaveHTTPBody", func() {
5252
When("EXPECTED is []byte", func() {
5353
It("matches the body", func() {
5454
const body = "this is the body"
55-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader(body))}
55+
resp := &http.Response{Body: io.NopCloser(strings.NewReader(body))}
5656
Expect(resp).To(HaveHTTPBody([]byte(body)))
5757
})
5858

5959
It("mismatches the body", func() {
6060
const body = "this is the body"
61-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader(body))}
61+
resp := &http.Response{Body: io.NopCloser(strings.NewReader(body))}
6262
Expect(resp).NotTo(HaveHTTPBody([]byte("something else")))
6363
})
6464
})
6565

6666
When("EXPECTED is a submatcher", func() {
6767
It("matches the body", func() {
68-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader(`{"some":"json"}`))}
68+
resp := &http.Response{Body: io.NopCloser(strings.NewReader(`{"some":"json"}`))}
6969
Expect(resp).To(HaveHTTPBody(MatchJSON(`{ "some": "json" }`)))
7070
})
7171

7272
It("mismatches the body", func() {
73-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader(`{"some":"json"}`))}
73+
resp := &http.Response{Body: io.NopCloser(strings.NewReader(`{"some":"json"}`))}
7474
Expect(resp).NotTo(HaveHTTPBody(MatchJSON(`{ "something": "different" }`)))
7575
})
7676
})
7777

7878
When("EXPECTED is something else", func() {
7979
It("errors", func() {
8080
failures := InterceptGomegaFailures(func() {
81-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader("body"))}
81+
resp := &http.Response{Body: io.NopCloser(strings.NewReader("body"))}
8282
Expect(resp).To(HaveHTTPBody(map[int]bool{}))
8383
})
8484
Expect(failures).To(HaveLen(1))
@@ -90,7 +90,7 @@ var _ = Describe("HaveHTTPBody", func() {
9090
Context("EXPECTED is string", func() {
9191
It("returns a match failure message", func() {
9292
failures := InterceptGomegaFailures(func() {
93-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader("this is the body"))}
93+
resp := &http.Response{Body: io.NopCloser(strings.NewReader("this is the body"))}
9494
Expect(resp).To(HaveHTTPBody("this is a different body"))
9595
})
9696
Expect(failures).To(HaveLen(1))
@@ -104,7 +104,7 @@ to equal
104104
Context("EXPECTED is []byte", func() {
105105
It("returns a match failure message", func() {
106106
failures := InterceptGomegaFailures(func() {
107-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader("this is the body"))}
107+
resp := &http.Response{Body: io.NopCloser(strings.NewReader("this is the body"))}
108108
Expect(resp).To(HaveHTTPBody([]byte("this is a different body")))
109109
})
110110
Expect(failures).To(HaveLen(1))
@@ -118,7 +118,7 @@ to equal
118118
Context("EXPECTED is submatcher", func() {
119119
It("returns a match failure message", func() {
120120
failures := InterceptGomegaFailures(func() {
121-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader(`{"some":"json"}`))}
121+
resp := &http.Response{Body: io.NopCloser(strings.NewReader(`{"some":"json"}`))}
122122
Expect(resp).To(HaveHTTPBody(MatchJSON(`{"other":"stuff"}`)))
123123
})
124124
Expect(failures).To(HaveLen(1))
@@ -139,7 +139,7 @@ to match JSON of
139139
It("returns a negated failure message", func() {
140140
const body = "this is the body"
141141
failures := InterceptGomegaFailures(func() {
142-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader(body))}
142+
resp := &http.Response{Body: io.NopCloser(strings.NewReader(body))}
143143
Expect(resp).NotTo(HaveHTTPBody(body))
144144
})
145145
Expect(failures).To(HaveLen(1))
@@ -154,7 +154,7 @@ not to equal
154154
It("returns a match failure message", func() {
155155
const body = "this is the body"
156156
failures := InterceptGomegaFailures(func() {
157-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader(body))}
157+
resp := &http.Response{Body: io.NopCloser(strings.NewReader(body))}
158158
Expect(resp).NotTo(HaveHTTPBody([]byte(body)))
159159
})
160160
Expect(failures).To(HaveLen(1))
@@ -169,7 +169,7 @@ not to equal
169169
It("returns a match failure message", func() {
170170
const body = `{"some":"json"}`
171171
failures := InterceptGomegaFailures(func() {
172-
resp := &http.Response{Body: ioutil.NopCloser(strings.NewReader(body))}
172+
resp := &http.Response{Body: io.NopCloser(strings.NewReader(body))}
173173
Expect(resp).NotTo(HaveHTTPBody(MatchJSON(body)))
174174
})
175175
Expect(failures).To(HaveLen(1))

‎matchers/have_http_status_matcher.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package matchers
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"net/http/httptest"
88
"reflect"
@@ -78,7 +78,7 @@ func formatHttpResponse(input interface{}) string {
7878
body := "<nil>"
7979
if resp.Body != nil {
8080
defer resp.Body.Close()
81-
data, err := ioutil.ReadAll(resp.Body)
81+
data, err := io.ReadAll(resp.Body)
8282
if err != nil {
8383
data = []byte("<error reading body>")
8484
}

‎matchers/have_http_status_matcher_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package matchers_test
22

33
import (
4-
"io/ioutil"
4+
"io"
55
"net/http"
66
"net/http/httptest"
77
"strings"
@@ -121,7 +121,7 @@ var _ = Describe("HaveHTTPStatus", func() {
121121
resp := &http.Response{
122122
StatusCode: http.StatusBadGateway,
123123
Status: "502 Bad Gateway",
124-
Body: ioutil.NopCloser(strings.NewReader("did not like it")),
124+
Body: io.NopCloser(strings.NewReader("did not like it")),
125125
}
126126
Expect(resp).To(HaveHTTPStatus(http.StatusOK))
127127
})
@@ -141,7 +141,7 @@ to have HTTP status
141141
resp := &http.Response{
142142
StatusCode: http.StatusBadGateway,
143143
Status: "502 Bad Gateway",
144-
Body: ioutil.NopCloser(strings.NewReader("did not like it")),
144+
Body: io.NopCloser(strings.NewReader("did not like it")),
145145
}
146146
Expect(resp).To(HaveHTTPStatus(http.StatusOK, http.StatusNotFound, "204 No content"))
147147
})
@@ -165,7 +165,7 @@ to have HTTP status
165165
resp := &http.Response{
166166
StatusCode: http.StatusOK,
167167
Status: "200 OK",
168-
Body: ioutil.NopCloser(strings.NewReader("got it!")),
168+
Body: io.NopCloser(strings.NewReader("got it!")),
169169
}
170170
Expect(resp).NotTo(HaveHTTPStatus(http.StatusOK))
171171
})
@@ -185,7 +185,7 @@ not to have HTTP status
185185
resp := &http.Response{
186186
StatusCode: http.StatusOK,
187187
Status: "200 OK",
188-
Body: ioutil.NopCloser(strings.NewReader("got it!")),
188+
Body: io.NopCloser(strings.NewReader("got it!")),
189189
}
190190
Expect(resp).NotTo(HaveHTTPStatus(http.StatusOK, "204 No content", http.StatusGone))
191191
})

‎matchers/matcher_tests_suite_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package matchers_test
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"os"
77
"testing"
88

@@ -34,7 +34,7 @@ func Test(t *testing.T) {
3434

3535
func readFileContents(filePath string) []byte {
3636
f := openFile(filePath)
37-
b, err := ioutil.ReadAll(f)
37+
b, err := io.ReadAll(f)
3838
if err != nil {
3939
panic(fmt.Errorf("failed to read file contents: %v", err))
4040
}

0 commit comments

Comments
 (0)
Please sign in to comment.