diff options
author | KallyDev <36319157+kallydev@users.noreply.github.com> | 2021-09-30 01:17:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-29 11:17:48 -0600 |
commit | c48fadc4a7655008d13076c7f757c36368e2ca13 (patch) | |
tree | 3fe2837e02e9b664dd5b86afbe42494ac20997f8 /caddytest | |
parent | 059fc32f002d00e980b438b3edbdf7b8bcdf9a90 (diff) |
Move from deprecated ioutil to os and io packages (#4364)
Diffstat (limited to 'caddytest')
-rw-r--r-- | caddytest/caddytest.go | 10 | ||||
-rw-r--r-- | caddytest/integration/caddyfile_adapt_test.go | 6 | ||||
-rw-r--r-- | caddytest/integration/reverseproxy_test.go | 7 | ||||
-rw-r--r-- | caddytest/integration/stream_test.go | 11 |
4 files changed, 16 insertions, 18 deletions
diff --git a/caddytest/caddytest.go b/caddytest/caddytest.go index 094e45c..3be332e 100644 --- a/caddytest/caddytest.go +++ b/caddytest/caddytest.go @@ -7,7 +7,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "log" "net" "net/http" @@ -129,7 +129,7 @@ func (tc *Tester) initServer(rawConfig string, configType string) error { return } defer res.Body.Close() - body, _ := ioutil.ReadAll(res.Body) + body, _ := io.ReadAll(res.Body) var out bytes.Buffer _ = json.Indent(&out, body, "", " ") @@ -162,7 +162,7 @@ func (tc *Tester) initServer(rawConfig string, configType string) error { timeElapsed(start, "caddytest: config load time") defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { tc.t.Errorf("unable to read response. %s", err) return err @@ -202,7 +202,7 @@ func (tc *Tester) ensureConfigRunning(rawConfig string, configType string) error return nil } defer resp.Body.Close() - actualBytes, err := ioutil.ReadAll(resp.Body) + actualBytes, err := io.ReadAll(resp.Body) if err != nil { return nil } @@ -471,7 +471,7 @@ func (tc *Tester) AssertResponse(req *http.Request, expectedStatusCode int, expe resp := tc.AssertResponseCode(req, expectedStatusCode) defer resp.Body.Close() - bytes, err := ioutil.ReadAll(resp.Body) + bytes, err := io.ReadAll(resp.Body) if err != nil { tc.t.Fatalf("unable to read the response body %s", err) } diff --git a/caddytest/integration/caddyfile_adapt_test.go b/caddytest/integration/caddyfile_adapt_test.go index e109899..5b052df 100644 --- a/caddytest/integration/caddyfile_adapt_test.go +++ b/caddytest/integration/caddyfile_adapt_test.go @@ -3,7 +3,7 @@ package integration import ( jsonMod "encoding/json" "fmt" - "io/ioutil" + "os" "path/filepath" "regexp" "strings" @@ -14,7 +14,7 @@ import ( func TestCaddyfileAdaptToJSON(t *testing.T) { // load the list of test files from the dir - files, err := ioutil.ReadDir("./caddyfile_adapt") + files, err := os.ReadDir("./caddyfile_adapt") if err != nil { t.Errorf("failed to read caddyfile_adapt dir: %s", err) } @@ -29,7 +29,7 @@ func TestCaddyfileAdaptToJSON(t *testing.T) { // read the test file filename := f.Name() - data, err := ioutil.ReadFile("./caddyfile_adapt/" + filename) + data, err := os.ReadFile("./caddyfile_adapt/" + filename) if err != nil { t.Errorf("failed to read %s dir: %s", filename, err) } diff --git a/caddytest/integration/reverseproxy_test.go b/caddytest/integration/reverseproxy_test.go index 422f671..ca11287 100644 --- a/caddytest/integration/reverseproxy_test.go +++ b/caddytest/integration/reverseproxy_test.go @@ -2,7 +2,6 @@ package integration import ( "fmt" - "io/ioutil" "net" "net/http" "os" @@ -85,7 +84,7 @@ func TestDialWithPlaceholderUnix(t *testing.T) { t.SkipNow() } - f, err := ioutil.TempFile("", "*.sock") + f, err := os.CreateTemp("", "*.sock") if err != nil { t.Errorf("failed to create TempFile: %s", err) return @@ -387,7 +386,7 @@ func TestReverseProxyHealthCheckUnixSocket(t *testing.T) { t.SkipNow() } tester := caddytest.NewTester(t) - f, err := ioutil.TempFile("", "*.sock") + f, err := os.CreateTemp("", "*.sock") if err != nil { t.Errorf("failed to create TempFile: %s", err) return @@ -442,7 +441,7 @@ func TestReverseProxyHealthCheckUnixSocketWithoutPort(t *testing.T) { t.SkipNow() } tester := caddytest.NewTester(t) - f, err := ioutil.TempFile("", "*.sock") + f, err := os.CreateTemp("", "*.sock") if err != nil { t.Errorf("failed to create TempFile: %s", err) return diff --git a/caddytest/integration/stream_test.go b/caddytest/integration/stream_test.go index b6447c6..d5edb79 100644 --- a/caddytest/integration/stream_test.go +++ b/caddytest/integration/stream_test.go @@ -6,7 +6,6 @@ import ( "crypto/rand" "fmt" "io" - "io/ioutil" "net/http" "net/http/httputil" "net/url" @@ -110,7 +109,7 @@ func TestH2ToH2CStream(t *testing.T) { r, w := io.Pipe() req := &http.Request{ Method: "PUT", - Body: ioutil.NopCloser(r), + Body: io.NopCloser(r), URL: &url.URL{ Scheme: "https", Host: "127.0.0.1:9443", @@ -134,7 +133,7 @@ func TestH2ToH2CStream(t *testing.T) { }() defer resp.Body.Close() - bytes, err := ioutil.ReadAll(resp.Body) + bytes, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("unable to read the response body %s", err) } @@ -319,7 +318,7 @@ func TestH2ToH1ChunkedResponse(t *testing.T) { r, w := io.Pipe() req := &http.Request{ Method: "PUT", - Body: ioutil.NopCloser(r), + Body: io.NopCloser(r), URL: &url.URL{ Scheme: "https", Host: "127.0.0.1:9443", @@ -342,7 +341,7 @@ func TestH2ToH1ChunkedResponse(t *testing.T) { } defer resp.Body.Close() - bytes, err := ioutil.ReadAll(resp.Body) + bytes, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("unable to read the response body %s", err) } @@ -370,7 +369,7 @@ func testH2ToH1ChunkedResponseServeH1(t *testing.T) *http.Server { } defer r.Body.Close() - bytes, err := ioutil.ReadAll(r.Body) + bytes, err := io.ReadAll(r.Body) if err != nil { t.Fatalf("unable to read the response body %s", err) } |