Skip to content

Commit

Permalink
👷 v3 (ci): fix some linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Feb 9, 2023
1 parent c2749c3 commit 3168a60
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 60 deletions.
1 change: 0 additions & 1 deletion app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,6 @@ func Test_App_Route(t *testing.T) {
resp, err = app.Test(httptest.NewRequest(MethodGet, "/test/v1/v2/v3", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")

}

func Test_App_Deep_Group(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func Test_Client_Unsupported_Protocol(t *testing.T) {
require.Equal(t, 1, len(errs))
require.Equal(t, `unsupported protocol "ftp". http and https are supported`,
errs[0].Error())

}

func Test_Client_Get(t *testing.T) {
Expand Down
29 changes: 19 additions & 10 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,15 @@ func Test_Ctx_Format(t *testing.T) {
require.Error(t, err)

c.Request().Header.Set(HeaderAccept, MIMETextPlain)
c.Format(Map{})
err = c.Format(Map{})
require.NoError(t, err)
require.Equal(t, "map[]", string(c.Response().Body()))

type broken string
c.Request().Header.Set(HeaderAccept, "broken/accept")
c.Format(broken("Hello, World!"))
require.NoError(t, err)
err = c.Format(broken("Hello, World!"))
require.NoError(t, err)
require.Equal(t, `Hello, World!`, string(c.Response().Body()))
}

Expand Down Expand Up @@ -2565,7 +2568,6 @@ func Test_Ctx_RenderWithLocals(t *testing.T) {
defer bytebufferpool.Put(buf)

require.Equal(t, "<h1>Hello, World!</h1>", string(c.Response().Body()))

}

func Test_Ctx_RenderWithBindVars(t *testing.T) {
Expand Down Expand Up @@ -3073,13 +3075,16 @@ func Test_Ctx_SendStream(t *testing.T) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{})

c.SendStream(bytes.NewReader([]byte("Don't crash please")))
err := c.SendStream(bytes.NewReader([]byte("Don't crash please")))
require.NoError(t, err)
require.Equal(t, "Don't crash please", string(c.Response().Body()))

c.SendStream(bytes.NewReader([]byte("Don't crash please")), len([]byte("Don't crash please")))
err = c.SendStream(bytes.NewReader([]byte("Don't crash please")), len([]byte("Don't crash please")))
require.NoError(t, err)
require.Equal(t, "Don't crash please", string(c.Response().Body()))

c.SendStream(bufio.NewReader(bytes.NewReader([]byte("Hello bufio"))))
err = c.SendStream(bufio.NewReader(bytes.NewReader([]byte("Hello bufio"))))
require.NoError(t, err)
require.Equal(t, "Hello bufio", string(c.Response().Body()))
}

Expand Down Expand Up @@ -3215,8 +3220,10 @@ func Test_Ctx_Write(t *testing.T) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{})

c.Write([]byte("Hello, "))
c.Write([]byte("World!"))
_, err := c.Write([]byte("Hello, "))
require.NoError(t, err)
_, err = c.Write([]byte("World!"))
require.NoError(t, err)
require.Equal(t, "Hello, World!", string(c.Response().Body()))
}

Expand Down Expand Up @@ -3270,8 +3277,10 @@ func Test_Ctx_WriteString(t *testing.T) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{})

c.WriteString("Hello, ")
c.WriteString("World!")
_, err := c.WriteString("Hello, ")
require.NoError(t, err)
_, err = c.WriteString("World!")
require.NoError(t, err)
require.Equal(t, "Hello, World!", string(c.Response().Body()))
}

Expand Down
2 changes: 1 addition & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ const (
ConstraintBool = "bool"
ConstraintFloat = "float"
ConstraintAlpha = "alpha"
ConstraintGuid = "guid" //nolint:revive,stylecheck // TODO: Rename to "ConstraintGUID" in v3
ConstraintGUID = "guid"
ConstraintMinLen = "minLen"
ConstraintMaxLen = "maxLen"
ConstraintLen = "len"
Expand Down
2 changes: 0 additions & 2 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func Test_Utils_UniqueRouteStack(t *testing.T) {
route2,
route3,
}))

}

func Test_Utils_getGroupPath(t *testing.T) {
Expand Down Expand Up @@ -143,7 +142,6 @@ func Test_Utils_IsNoCache(t *testing.T) {
ok := isNoCache(c.string)
require.Equal(t, c.bool, ok,
fmt.Sprintf("want %t, got isNoCache(%s)=%t", c.bool, c.string, ok))

}
}

Expand Down
4 changes: 2 additions & 2 deletions listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (app *App) Listen(addr string, config ...ListenConfig) error {
if cfg.CertFile != "" && cfg.CertKeyFile != "" {
cert, err := tls.LoadX509KeyPair(cfg.CertFile, cfg.CertKeyFile)
if err != nil {
return fmt.Errorf("tls: cannot load TLS key pair from certFile=%q and keyFile=%q: %s", cfg.CertFile, cfg.CertKeyFile, err)
return fmt.Errorf("tls: cannot load TLS key pair from certFile=%q and keyFile=%q: %w", cfg.CertFile, cfg.CertKeyFile, err)
}

tlsHandler := &TLSHandler{}
Expand Down Expand Up @@ -241,7 +241,7 @@ func (app *App) Listener(ln net.Listener, config ...ListenConfig) error {

// Prefork is not supported for custom listeners
if cfg.EnablePrefork {
fmt.Println("[Warning] Prefork isn't supported for custom listeners.")
log.Print("[Warning] Prefork isn't supported for custom listeners.")
}

return app.server.Serve(ln)
Expand Down
7 changes: 0 additions & 7 deletions listen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func Test_Listen_MutualTLS(t *testing.T) {
CertKeyFile: "./.github/testdata/ssl.key",
CertClientFile: "./.github/testdata/ca-chain.cert.pem",
}))

}

// go test -run Test_Listen_MutualTLS_Prefork
Expand Down Expand Up @@ -198,7 +197,6 @@ func Test_Listen_MutualTLS_Prefork(t *testing.T) {
CertKeyFile: "./.github/testdata/ssl.key",
CertClientFile: "./.github/testdata/ca-chain.cert.pem",
}))

}

// go test -run Test_Listener
Expand Down Expand Up @@ -351,7 +349,6 @@ func Test_Listen_Master_Process_Show_Startup_Message(t *testing.T) {
startupMessage(":3000", true, strings.Repeat(",11111,22222,33333,44444,55555,60000", 10), cfg)
})
colors := Colors{}
fmt.Println(startupMessage)
require.True(t, strings.Contains(startupMessage, "https://127.0.0.1:3000"))
require.True(t, strings.Contains(startupMessage, "(bound on host 0.0.0.0 and port 3000)"))
require.True(t, strings.Contains(startupMessage, "Child PIDs"))
Expand All @@ -369,7 +366,6 @@ func Test_Listen_Master_Process_Show_Startup_MessageWithAppName(t *testing.T) {
startupMessage := captureOutput(func() {
app.startupMessage(":3000", true, strings.Repeat(",11111,22222,33333,44444,55555,60000", 10), cfg)
})
fmt.Println(startupMessage)
require.Equal(t, "Test App v3.0.0", app.Config().AppName)
require.True(t, strings.Contains(startupMessage, app.Config().AppName))
}
Expand All @@ -386,7 +382,6 @@ func Test_Listen_Master_Process_Show_Startup_MessageWithAppNameNonAscii(t *testi
startupMessage := captureOutput(func() {
app.startupMessage(":3000", false, "", cfg)
})
fmt.Println(startupMessage)
require.True(t, strings.Contains(startupMessage, "Serveur de vérification des données"))
}

Expand All @@ -402,7 +397,6 @@ func Test_Listen_Master_Process_Show_Startup_MessageWithDisabledPreforkAndCustom
app.startupMessage("server.com:8081", true, strings.Repeat(",11111,22222,33333,44444,55555,60000", 5), cfg)
})
colors := Colors{}
fmt.Println(startupMessage)
require.True(t, strings.Contains(startupMessage, fmt.Sprintf("%sINFO%s", colors.Green, colors.Reset)))
require.True(t, strings.Contains(startupMessage, fmt.Sprintf("%s%s%s", colors.Blue, appName, colors.Reset)))
require.True(t, strings.Contains(startupMessage, fmt.Sprintf("%s%s%s", colors.Blue, "https://server.com:8081", colors.Reset)))
Expand All @@ -416,7 +410,6 @@ func Test_Listen_Print_Route(t *testing.T) {
printRoutesMessage := captureOutput(func() {
app.printRoutesMessage()
})
fmt.Println(printRoutesMessage)
require.True(t, strings.Contains(printRoutesMessage, MethodGet))
require.True(t, strings.Contains(printRoutesMessage, "/"))
require.True(t, strings.Contains(printRoutesMessage, "emptyHandler"))
Expand Down
6 changes: 4 additions & 2 deletions middleware/adaptor/adopter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"testing"

"github.com/gofiber/fiber/v3"
"github.com/stretchr/testify/require"
"github.com/valyala/fasthttp"
)

Expand Down Expand Up @@ -94,7 +95,8 @@ func Test_HTTPHandler(t *testing.T) {
w.Header().Set("Header1", "value1")
w.Header().Set("Header2", "value2")
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "request body is %q", body)
_, err = fmt.Fprintf(w, "request body is %q", body)
require.NoError(t, err)
}
fiberH := HTTPHandlerFunc(http.HandlerFunc(nethttpH))
fiberH = setFiberContextValueMiddleware(fiberH, expectedContextKey, expectedContextValue)
Expand Down Expand Up @@ -211,7 +213,7 @@ func Test_FiberAppDefaultPort(t *testing.T) {
testFiberToHandlerFunc(t, true, fiber.New())
}

func testFiberToHandlerFunc(t *testing.T, checkDefaultPort bool, app ...*fiber.App) {
func testFiberToHandlerFunc(t *testing.T, checkDefaultPort bool, app ...*fiber.App) { //revive:disable-line:flag-parameter
expectedMethod := fiber.MethodPost
expectedRequestURI := "/foo/bar?baz=123"
expectedBody := "body 123 foo bar baz"
Expand Down
2 changes: 1 addition & 1 deletion middleware/etag/etag.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func New(config ...Config) fiber.Handler {
crc32q := crc32.MakeTable(crcPol)

// Return new handler
return func(c fiber.Ctx) (err error) {
return func(c fiber.Ctx) error {
// Don't execute middleware if Next returns true
if cfg.Next != nil && cfg.Next(c) {
return c.Next()
Expand Down
4 changes: 2 additions & 2 deletions middleware/filesystem/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func dirList(c fiber.Ctx, f fs.File) error {
return nil
}

func openFile(fs fs.FS, name string) (fs.File, error) {
func openFile(filesystem fs.FS, name string) (fs.File, error) {
name = filepath.ToSlash(name)

return fs.Open(name)
return filesystem.Open(name)
}
1 change: 0 additions & 1 deletion middleware/helmet/helmet.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func New(config ...Config) fiber.Handler {
}
if cfg.PermissionPolicy != "" {
c.Set(fiber.HeaderPermissionsPolicy, cfg.PermissionPolicy)

}
return c.Next()
}
Expand Down
2 changes: 1 addition & 1 deletion middleware/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func New(config ...Config) fiber.Handler {
}

// Return new handler
return func(c fiber.Ctx) (err error) {
return func(c fiber.Ctx) error {
// Don't execute middleware if Next returns true
if cfg.Next != nil && cfg.Next(c) {
return c.Next()
Expand Down
2 changes: 1 addition & 1 deletion middleware/redirect/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func New(config ...Config) fiber.Handler {
cfg.rulesRegex = map[*regexp.Regexp]string{}
// Initialize
for k, v := range cfg.Rules {
k = strings.Replace(k, "*", "(.*)", -1)
k = strings.ReplaceAll(k, "*", "(.*)")
k += "$"
cfg.rulesRegex[regexp.MustCompile(k)] = v
}
Expand Down
3 changes: 2 additions & 1 deletion middleware/redirect/redirect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package redirect

import (
"context"
"net/http"
"testing"

Expand Down Expand Up @@ -110,7 +111,7 @@ func Test_Redirect(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req, err := http.NewRequest(fiber.MethodGet, tt.url, nil)
req, err := http.NewRequestWithContext(context.Background(), fiber.MethodGet, tt.url, nil)
require.NoError(t, err)
req.Header.Set("Location", "github.com/gofiber/redirect")
resp, err := app.Test(req)
Expand Down
7 changes: 4 additions & 3 deletions mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ func Test_Ctx_Render_Mount(t *testing.T) {
t.Parallel()

engine := &testTemplateEngine{}
engine.Load()
err := engine.Load()
require.NoError(t, err)

sub := New(Config{
Views: engine,
Expand Down Expand Up @@ -376,14 +377,14 @@ func Test_Ctx_Render_Mount_ParentOrSubHasViews(t *testing.T) {
body, err = io.ReadAll(resp.Body)
require.Equal(t, nil, err)
require.Equal(t, "<h1>I'm Bruh</h1>", string(body))

}

func Test_Ctx_Render_MountGroup(t *testing.T) {
t.Parallel()

engine := &testTemplateEngine{}
engine.Load()
err := engine.Load()
require.NoError(t, err)

micro := New(Config{
Views: engine,
Expand Down
2 changes: 1 addition & 1 deletion path.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ func getParamConstraintType(constraintPart string) TypeConstraint {
return floatConstraint
case ConstraintAlpha:
return alphaConstraint
case ConstraintGuid:
case ConstraintGUID:
return guidConstraint
case ConstraintMinLen, ConstraintMinLenLower:
return minLenConstraint
Expand Down
1 change: 0 additions & 1 deletion path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func Test_Path_parseRoute(t *testing.T) {
params: []string{"*1", "*2"},
wildCardCount: 2,
}, rp)

}

// go test -race -run Test_Path_matchParams
Expand Down
13 changes: 6 additions & 7 deletions redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ func (r *Redirect) OldInput(key string) string {
}
}
return ""

}

// Redirect to the URL derived from the specified path, with specified status.
Expand Down Expand Up @@ -204,20 +203,20 @@ func (r *Redirect) Route(name string, config ...RedirectConfig) error {

// flash messages
for i, message := range r.messages {
_, _ = messageText.WriteString(message)
_, _ = messageText.WriteString(message) //nolint:errcheck // Always return nil
// when there are more messages or oldInput -> add a comma
if len(r.messages)-1 != i || (len(r.messages)-1 == i && len(r.oldInput) > 0) {
_, _ = messageText.WriteString(CookieDataSeparator)
_, _ = messageText.WriteString(CookieDataSeparator) //nolint:errcheck // Always return nil
}
}
r.messages = r.messages[:0]

// old input data
i := 1
for k, v := range r.oldInput {
_, _ = messageText.WriteString(OldInputDataPrefix + k + CookieDataAssigner + v)
_, _ = messageText.WriteString(OldInputDataPrefix + k + CookieDataAssigner + v) //nolint:errcheck // Always return nil
if len(r.oldInput) != i {
_, _ = messageText.WriteString(CookieDataSeparator)
_, _ = messageText.WriteString(CookieDataSeparator) //nolint:errcheck // Always return nil
}
i++
}
Expand All @@ -236,10 +235,10 @@ func (r *Redirect) Route(name string, config ...RedirectConfig) error {

i := 1
for k, v := range cfg.Queries {
_, _ = queryText.WriteString(k + "=" + v)
_, _ = queryText.WriteString(k + "=" + v) //nolint:errcheck // Always return nil

if i != len(cfg.Queries) {
_, _ = queryText.WriteString("&")
_, _ = queryText.WriteString("&") //nolint:errcheck // Always return nil
}
i++
}
Expand Down
Loading

0 comments on commit 3168a60

Please sign in to comment.