Skip to content

Commit

Permalink
v3: replace io/ioutil by io and os, update version constant
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Jun 1, 2022
1 parent 9efcefa commit f119794
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 140 deletions.
5 changes: 2 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/httputil"
Expand All @@ -38,7 +37,7 @@ import (
)

// Version of current fiber package
const Version = "2.34.0"
const Version = "3.0.0-beta.1"

// Handler defines a function to serve HTTP requests.
type Handler = func(*Ctx) error
Expand Down Expand Up @@ -847,7 +846,7 @@ func (app *App) ListenMutualTLS(addr, certFile, keyFile, clientCertFile string)
return fmt.Errorf("tls: cannot load TLS key pair from certFile=%q and keyFile=%q: %s", certFile, keyFile, err)
}

clientCACert, err := ioutil.ReadFile(filepath.Clean(clientCertFile))
clientCACert, err := os.ReadFile(filepath.Clean(clientCertFile))
if err != nil {
return err
}
Expand Down
49 changes: 24 additions & 25 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net"
Expand Down Expand Up @@ -47,7 +46,7 @@ func testErrorResponse(t *testing.T, err error, resp *http.Response, expectedBod
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 500, resp.StatusCode, "Status code")

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, expectedBodyError, string(body), "Response body")
}
Expand Down Expand Up @@ -165,7 +164,7 @@ func Test_App_Errors(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 500, resp.StatusCode, "Status code")

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, "hi, i'm an error", string(body))

Expand All @@ -190,7 +189,7 @@ func Test_App_ErrorHandler_Custom(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, "hi, i'm an custom error", string(body))
}
Expand Down Expand Up @@ -219,7 +218,7 @@ func Test_App_ErrorHandler_HandlerStack(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 500, resp.StatusCode, "Status code")

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, "1: USE error", string(body))
}
Expand All @@ -244,7 +243,7 @@ func Test_App_ErrorHandler_RouteStack(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 500, resp.StatusCode, "Status code")

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, "1: USE error", string(body))
}
Expand Down Expand Up @@ -385,7 +384,7 @@ func Test_App_Use_UnescapedPath(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code")

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "app.Test(req)")
// check the param result
utils.AssertEqual(t, "اختبار", app.getString(body))
Expand Down Expand Up @@ -420,7 +419,7 @@ func Test_App_Use_CaseSensitive(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code")

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "app.Test(req)")
// check the detected path result
utils.AssertEqual(t, "/AbC", app.getString(body))
Expand Down Expand Up @@ -522,7 +521,7 @@ func Test_App_Order(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, "123", string(body))
}
Expand Down Expand Up @@ -644,7 +643,7 @@ func Test_App_Static_Index_Default(t *testing.T) {
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, MIMETextHTMLCharsetUTF8, resp.Header.Get(HeaderContentType))

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, strings.Contains(string(body), "Hello, World!"))

Expand All @@ -654,7 +653,7 @@ func Test_App_Static_Index_Default(t *testing.T) {
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType))

body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, "Cannot GET /not-found", string(body))
}
Expand All @@ -671,7 +670,7 @@ func Test_App_Static_Direct(t *testing.T) {
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, MIMETextHTMLCharsetUTF8, resp.Header.Get(HeaderContentType))

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, strings.Contains(string(body), "Hello, World!"))

Expand All @@ -682,7 +681,7 @@ func Test_App_Static_Direct(t *testing.T) {
utils.AssertEqual(t, MIMEApplicationJSON, resp.Header.Get("Content-Type"))
utils.AssertEqual(t, "", resp.Header.Get(HeaderCacheControl), "CacheControl Control")

body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, strings.Contains(string(body), "testRoutes"))
}
Expand Down Expand Up @@ -759,7 +758,7 @@ func Test_App_Static_Wildcard(t *testing.T) {
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, MIMETextHTMLCharsetUTF8, resp.Header.Get(HeaderContentType))

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, strings.Contains(string(body), "Test file"))
}
Expand All @@ -784,7 +783,7 @@ func Test_App_Static_Prefix_Wildcard(t *testing.T) {
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, MIMETextHTMLCharsetUTF8, resp.Header.Get(HeaderContentType))

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, strings.Contains(string(body), "Test file"))
}
Expand Down Expand Up @@ -887,7 +886,7 @@ func Test_App_Static_Next(t *testing.T) {
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType))

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, strings.Contains(string(body), "You've skipped app.Static"))
})
Expand All @@ -901,7 +900,7 @@ func Test_App_Static_Next(t *testing.T) {
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, MIMETextHTMLCharsetUTF8, resp.Header.Get(HeaderContentType))

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, strings.Contains(string(body), "Hello, World!"))
})
Expand Down Expand Up @@ -932,7 +931,7 @@ func Test_App_Mixed_Routes_WithSameLen(t *testing.T) {
utils.AssertEqual(t, "TestValue", resp.Header.Get("TestHeader"))
utils.AssertEqual(t, "text/html", resp.Header.Get(HeaderContentType))

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, "FOO_BAR", string(body))

Expand All @@ -945,7 +944,7 @@ func Test_App_Mixed_Routes_WithSameLen(t *testing.T) {
utils.AssertEqual(t, "TestValue", resp.Header.Get("TestHeader"))
utils.AssertEqual(t, "text/html; charset=utf-8", resp.Header.Get(HeaderContentType))

body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, strings.Contains(string(body), "Hello, World!"), "Response: "+string(body))
utils.AssertEqual(t, true, strings.HasPrefix(string(body), "<!DOCTYPE html>"), "Response: "+string(body))
Expand Down Expand Up @@ -1545,8 +1544,8 @@ func Test_App_ReadBodyStream(t *testing.T) {
testString := "this is a test"
resp, err := app.Test(httptest.NewRequest("POST", "/", bytes.NewBufferString(testString)))
utils.AssertEqual(t, nil, err, "app.Test(req)")
body, err := ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "ioutil.ReadAll(resp.Body)")
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "io.ReadAll(resp.Body)")
utils.AssertEqual(t, fmt.Sprintf("true %s", testString), string(body))
}

Expand Down Expand Up @@ -1591,8 +1590,8 @@ func Test_App_DisablePreParseMultipartForm(t *testing.T) {
req.Header.Set("Content-Type", w.FormDataContentType())
resp, err := app.Test(req)
utils.AssertEqual(t, nil, err, "app.Test(req)")
body, err := ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "ioutil.ReadAll(resp.Body)")
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "io.ReadAll(resp.Body)")

utils.AssertEqual(t, testString, string(body))
}
Expand Down Expand Up @@ -1674,15 +1673,15 @@ func Test_App_UseMountedErrorHandlerForBestPrefixMatch(t *testing.T) {
utils.AssertEqual(t, nil, err, "/api/sub req")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "iotuil.ReadAll()")
utils.AssertEqual(t, "hi, i'm a custom sub fiber error", string(b), "Response body")

resp2, err := app.Test(httptest.NewRequest(MethodGet, "/api/sub/third", nil))
utils.AssertEqual(t, nil, err, "/api/sub/third req")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")

b, err = ioutil.ReadAll(resp2.Body)
b, err = io.ReadAll(resp2.Body)
utils.AssertEqual(t, nil, err, "iotuil.ReadAll()")
utils.AssertEqual(t, "hi, i'm a custom sub sub fiber error", string(b), "Third fiber Response body")
}
Expand Down
3 changes: 1 addition & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net"
"os"
Expand Down Expand Up @@ -542,7 +541,7 @@ func (a *Agent) FileData(formFiles ...*FormFile) *Agent {

// SendFile reads file and appends it to multipart form request.
func (a *Agent) SendFile(filename string, fieldname ...string) *Agent {
content, err := ioutil.ReadFile(filepath.Clean(filename))
content, err := os.ReadFile(filepath.Clean(filename))
if err != nil {
a.errs = append(a.errs, err)
return a
Expand Down
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net"
"os"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -812,7 +812,7 @@ func checkFormFile(t *testing.T, fh *multipart.FileHeader, filename string) {
basename := filepath.Base(filename)
utils.AssertEqual(t, fh.Filename, basename)

b1, err := ioutil.ReadFile(filename)
b1, err := os.ReadFile(filename)
utils.AssertEqual(t, nil, err)

b2 := make([]byte, fh.Size)
Expand Down
3 changes: 1 addition & 2 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net"
"net/http"
Expand Down Expand Up @@ -1316,7 +1315,7 @@ func (c *Ctx) SaveFileToStorage(fileheader *multipart.FileHeader, path string, s
return err
}

content, err := ioutil.ReadAll(file)
content, err := io.ReadAll(file)
if err != nil {
return err
}
Expand Down
19 changes: 9 additions & 10 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -644,7 +643,7 @@ func Test_Ctx_UserContext_Multiple_Requests(t *testing.T) {
utils.AssertEqual(t, nil, err, "Unexpected error from response")
utils.AssertEqual(t, StatusOK, resp.StatusCode, "context.Context returned from c.UserContext() is reused")

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "Unexpected error from reading response body")
utils.AssertEqual(t, fmt.Sprintf("resp_%d_returned", i), string(b), "response text incorrect")
})
Expand Down Expand Up @@ -1067,7 +1066,7 @@ func Test_Ctx_PortInHandler(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code")

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, "0", string(body))
}
Expand Down Expand Up @@ -1700,14 +1699,14 @@ func Test_Ctx_SaveFile(t *testing.T) {
fh, err := c.FormFile("file")
utils.AssertEqual(t, nil, err)

tempFile, err := ioutil.TempFile(os.TempDir(), "test-")
tempFile, err := os.CreateTemp(os.TempDir(), "test-")
utils.AssertEqual(t, nil, err)

defer os.Remove(tempFile.Name())
err = c.SaveFile(fh, tempFile.Name())
utils.AssertEqual(t, nil, err)

bs, err := ioutil.ReadFile(tempFile.Name())
bs, err := os.ReadFile(tempFile.Name())
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, "hello world", string(bs))
return nil
Expand Down Expand Up @@ -1851,7 +1850,7 @@ func Test_Ctx_Download(t *testing.T) {
utils.AssertEqual(t, nil, err)
defer f.Close()

expect, err := ioutil.ReadAll(f)
expect, err := io.ReadAll(f)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, expect, c.Response().Body())
utils.AssertEqual(t, `attachment; filename="Awesome+File%21"`, string(c.Response().Header.Peek(HeaderContentDisposition)))
Expand All @@ -1869,7 +1868,7 @@ func Test_Ctx_SendFile(t *testing.T) {
f, err := os.Open("./ctx.go")
utils.AssertEqual(t, nil, err)
defer f.Close()
expectFileContent, err := ioutil.ReadAll(f)
expectFileContent, err := io.ReadAll(f)
utils.AssertEqual(t, nil, err)
// fetch file info for the not modified test case
fI, err := os.Stat("./ctx.go")
Expand Down Expand Up @@ -2335,7 +2334,7 @@ func Test_Ctx_Render_Mount(t *testing.T) {
utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code")
utils.AssertEqual(t, nil, err, "app.Test(req)")

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, "<h1>Hello a!</h1>", string(body))
}
Expand All @@ -2361,7 +2360,7 @@ func Test_Ctx_Render_MountGroup(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, "<h1>Hello doe!</h1>", string(body))
}
Expand Down Expand Up @@ -2810,7 +2809,7 @@ func Test_Ctx_Render_Engine_Error(t *testing.T) {
func Test_Ctx_Render_Go_Template(t *testing.T) {
t.Parallel()

file, err := ioutil.TempFile(os.TempDir(), "fiber")
file, err := os.CreateTemp(os.TempDir(), "fiber")
utils.AssertEqual(t, nil, err)
defer os.Remove(file.Name())

Expand Down
4 changes: 2 additions & 2 deletions middleware/basicauth/basicauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package basicauth

import (
"fmt"
"io/ioutil"
"io"
"net/http/httptest"
"testing"

Expand Down Expand Up @@ -82,7 +82,7 @@ func Test_Middleware_BasicAuth(t *testing.T) {
resp, err := app.Test(req)
utils.AssertEqual(t, nil, err)

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)

utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, tt.statusCode, resp.StatusCode)
Expand Down
Loading

0 comments on commit f119794

Please sign in to comment.