From 95c181469d874772bf84bd89a030458466c9ffe3 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Sun, 24 Mar 2024 15:54:56 -0400 Subject: [PATCH] chore: Enabling shuffling, cleanup and consistency across tests (#2931) * Make Test/Benchmark names consistent. Add Makefile for GoFiber developers * Cleanup README and Makefile * Update statement --- .github/README.md | 48 +++++++++-- .github/workflows/test.yml | 2 +- .gitignore | 4 +- Makefile | 43 ++++++++++ addon/retry/exponential_backoff_test.go | 4 +- app_test.go | 2 +- client/cookiejar_test.go | 12 +-- ctx_test.go | 88 ++++++++++---------- error_test.go | 20 ++--- middleware/cache/manager_msgp_test.go | 8 +- middleware/cors/utils_test.go | 12 +-- middleware/csrf/manager_msgp_test.go | 8 +- middleware/envvar/envvar_test.go | 12 +-- middleware/idempotency/response_msgp_test.go | 6 +- middleware/keyauth/keyauth_test.go | 12 +-- middleware/limiter/manager_msgp_test.go | 8 +- middleware/session/store_test.go | 12 +-- 17 files changed, 187 insertions(+), 114 deletions(-) create mode 100644 Makefile diff --git a/.github/README.md b/.github/README.md index bed17346d4..ee33a86a08 100644 --- a/.github/README.md +++ b/.github/README.md @@ -26,18 +26,20 @@

- Fiber is an Express inspired web framework built on top of Fasthttp, the fastest HTTP engine for Go. Designed to ease things up for fast development with zero memory allocation and performance in mind. + Fiber is an Express inspired web framework built on top of Fasthttp, the fastest HTTP engine for Go. Designed to ease things up for fast development with zero memory allocation and performance in mind.

+--- + ## ⚠️ **Attention** Fiber v3 is currently in beta and under active development. While it offers exciting new features, please note that it may not be stable for production use. We recommend sticking to the latest stable release (v2.x) for mission-critical applications. If you choose to use v3, be prepared for potential bugs and breaking changes. Always check the official documentation and release notes for updates and proceed with caution. Happy coding! πŸš€ -## βš™οΈ Installation +--- -Before you begin, ensure you have Go installed on your system. Fiber requires **Go version `1.21` or higher** to run. You can check your current Go version by running `go version` in your terminal. If you need to install or upgrade Go, visit the [official Go download page](https://go.dev/dl/). +## βš™οΈ Installation -Once you have verified your Go installation, you can start setting up your project. Create a new directory for your project and navigate into it. Then, initialize your project with Go modules by executing the following command in your terminal: +Fiber requires **Go version `1.21` or higher** to run. If you need to install or upgrade Go, visit the [official Go download page](https://go.dev/dl/). To start setting up your project. Create a new directory for your project and navigate into it. Then, initialize your project with Go modules by executing the following command in your terminal: ```bash go mod init github.com/your/repo @@ -60,7 +62,11 @@ Getting started with Fiber is easy. Here's a basic example to create a simple we ```go package main -import "github.com/gofiber/fiber/v3" +import ( + "log" + + "github.com/gofiber/fiber/v3" +) func main() { // Initialize a new Fiber app @@ -73,7 +79,7 @@ func main() { }) // Start the server on port 3000 - app.Listen(":3000") + log.Fatal(app.Listen(":3000")) } ``` @@ -186,7 +192,6 @@ func main() { // ] // } - log.Fatal(app.Listen(":3000")) } @@ -262,6 +267,8 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( + "log" + "github.com/gofiber/fiber/v3" "github.com/gofiber/template/pug" ) @@ -437,6 +444,8 @@ func main() { ```go import ( + "log" + "github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3/middleware/websocket" ) @@ -471,6 +480,8 @@ func main() { ```go import ( + "log" + "github.com/gofiber/fiber/v3" "github.com/valyala/fasthttp" ) @@ -512,6 +523,8 @@ func main() { ```go import ( + "log" + "github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3/middleware/recover" ) @@ -537,6 +550,8 @@ func main() { ```go import ( + "log" + "github.com/gofiber/fiber/v3" ) @@ -611,6 +626,21 @@ If you want to say **Thank You** and/or support the active development of `Fiber 3. Write a review or tutorial on [Medium](https://medium.com/), [Dev.to](https://dev.to/) or personal blog. 4. Support the project by donating a [cup of coffee](https://buymeacoff.ee/fenny). +## πŸ–₯️ Development + +To ensure your contributions are ready for a Pull Request, please use the following `Makefile` commands. These tools help maintain code quality, consistency. + +* **make help**: Display available commands. +* **make audit**: Conduct quality checks. +* **make benchmark**: Benchmark code performance. +* **make coverage**: Generate test coverage report. +* **make format**: Automatically format code. +* **make lint**: Run lint checks. +* **make test**: Execute all tests. +* **make tidy**: Tidy dependencies. + +Run these commands to ensure your code adheres to project standards and best practices. + ## β˜• Supporters Fiber is an open source project that runs on donations to pay the bills e.g. our domain name, gitbook, netlify and serverless hosting. If you want to support Fiber, you can β˜• [**buy a coffee here**](https://buymeacoff.ee/fenny). @@ -636,7 +666,7 @@ Fiber is an open source project that runs on donations to pay the bills e.g. our | ![](https://avatars.githubusercontent.com/u/31022056?s=25) | [@marvinjwendt](https://github.com/marvinjwendt) | β˜• x 1 | | ![](https://avatars.githubusercontent.com/u/31921460?s=25) | [@toishy](https://github.com/toishy) | β˜• x 1 | -## β€Žβ€πŸ’» Code Contributors +## πŸ’» Code Contributors Code Contributors @@ -644,6 +674,6 @@ Fiber is an open source project that runs on donations to pay the bills e.g. our Stargazers over time -## ⚠️ License +## 🧾 License Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](https://github.com/gofiber/fiber/graphs/contributors). `Fiber` is free and open-source software licensed under the [MIT License](https://github.com/gofiber/fiber/blob/master/LICENSE). Official logo was created by [Vic ShΓ³stak](https://github.com/koddr) and distributed under [Creative Commons](https://creativecommons.org/licenses/by-sa/4.0/) license (CC BY-SA 4.0 International). diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0cc3b2c60b..8fff9b80b9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,7 +34,7 @@ jobs: run: go install gotest.tools/gotestsum@v1.11.0 - name: Test - run: gotestsum -f testname -- ./... -race -count=1 -coverprofile=coverage.txt -covermode=atomic + run: gotestsum -f testname -- ./... -race -count=1 -coverprofile=coverage.txt -covermode=atomic -shuffle=on - name: Upload coverage reports to Codecov if: ${{ matrix.platform == 'ubuntu-latest' && matrix.go-version == '1.22.x' }} diff --git a/.gitignore b/.gitignore index 119b1111db..ac272edc41 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,8 @@ *.test *.tmp -# Output of the go coverage tool, specifically when used with LiteIDE -*.out +# Output of the go coverage tool +**/*.out # IDE files .vscode diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..a548b2105f --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +## help: πŸ’‘ Display available commands +.PHONY: help +help: + @echo '⚑️ GoFiber/Fiber Development:' + @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' + +## audit: πŸš€ Conduct quality checks +.PHONY: audit +audit: + go mod verify + go vet ./... + go run golang.org/x/vuln/cmd/govulncheck@latest ./... + +## benchmark: πŸ“ˆ Benchmark code performance +.PHONY: benchmark +benchmark: + go test ./... -benchmem -bench=. -run=^Benchmark_$ + +## coverage: β˜‚οΈ Generate coverage report +.PHONY: coverage +coverage: + go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=1 -coverprofile=/tmp/coverage.out -covermode=atomic + go tool cover -html=/tmp/coverage.out + +## format: 🎨 Fix code format issues +.PHONY: format +format: + go run mvdan.cc/gofumpt@latest -w -l . + +## lint: 🚨 Run lint checks +.PHONY: lint +lint: + go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.1 run ./... + +## test: 🚦 Execute all tests +.PHONY: test +test: + go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=1 -shuffle=on + +## tidy: πŸ“Œ Clean and tidy dependencies +.PHONY: tidy +tidy: + go mod tidy -v diff --git a/addon/retry/exponential_backoff_test.go b/addon/retry/exponential_backoff_test.go index 370f90a06d..0961d4fa43 100644 --- a/addon/retry/exponential_backoff_test.go +++ b/addon/retry/exponential_backoff_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestExponentialBackoff_Retry(t *testing.T) { +func Test_ExponentialBackoff_Retry(t *testing.T) { t.Parallel() tests := []struct { name string @@ -60,7 +60,7 @@ func TestExponentialBackoff_Retry(t *testing.T) { } } -func TestExponentialBackoff_Next(t *testing.T) { +func Test_ExponentialBackoff_Next(t *testing.T) { t.Parallel() tests := []struct { name string diff --git a/app_test.go b/app_test.go index 63aaa94658..f0e42a0848 100644 --- a/app_test.go +++ b/app_test.go @@ -1809,7 +1809,7 @@ func Test_App_AddCustomRequestMethod(t *testing.T) { require.Equal(t, "TEST", appMethods[len(appMethods)-1]) } -func TestApp_GetRoutes(t *testing.T) { +func Test_App_GetRoutes(t *testing.T) { t.Parallel() app := New() app.Use(func(c Ctx) error { diff --git a/client/cookiejar_test.go b/client/cookiejar_test.go index 2b72bdf34a..12c3691f74 100644 --- a/client/cookiejar_test.go +++ b/client/cookiejar_test.go @@ -22,7 +22,7 @@ func checkKeyValue(t *testing.T, cj *CookieJar, cookie *fasthttp.Cookie, uri *fa require.Equal(t, string(c.Value()), string(cookie.Value())) } -func TestCookieJarGet(t *testing.T) { +func Test_CookieJarGet(t *testing.T) { t.Parallel() url := []byte("http://fasthttp.com/") @@ -97,7 +97,7 @@ func TestCookieJarGet(t *testing.T) { } } -func TestCookieJarGetExpired(t *testing.T) { +func Test_CookieJarGetExpired(t *testing.T) { t.Parallel() url1 := []byte("http://fasthttp.com/make/") @@ -116,7 +116,7 @@ func TestCookieJarGetExpired(t *testing.T) { require.Empty(t, cookies) } -func TestCookieJarSet(t *testing.T) { +func Test_CookieJarSet(t *testing.T) { t.Parallel() url := []byte("http://fasthttp.com/hello/world") @@ -133,7 +133,7 @@ func TestCookieJarSet(t *testing.T) { checkKeyValue(t, cj, cookie, uri, 1) } -func TestCookieJarSetRepeatedCookieKeys(t *testing.T) { +func Test_CookieJarSetRepeatedCookieKeys(t *testing.T) { t.Parallel() host := "fast.http" cj := &CookieJar{} @@ -161,7 +161,7 @@ func TestCookieJarSetRepeatedCookieKeys(t *testing.T) { require.True(t, bytes.Equal(cookies[0].Value(), cookie2.Value())) } -func TestCookieJarSetKeyValue(t *testing.T) { +func Test_CookieJarSetKeyValue(t *testing.T) { t.Parallel() host := "fast.http" @@ -179,7 +179,7 @@ func TestCookieJarSetKeyValue(t *testing.T) { require.Len(t, cookies, 2) } -func TestCookieJarGetFromResponse(t *testing.T) { +func Test_CookieJarGetFromResponse(t *testing.T) { t.Parallel() res := fasthttp.AcquireResponse() diff --git a/ctx_test.go b/ctx_test.go index 6ecb3f0200..fdd21a1672 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -4561,8 +4561,8 @@ func Benchmark_Ctx_GetReqHeaders(b *testing.B) { }, headers) } -// go test -run Test_genericParseTypeInts -func Test_genericParseTypeInts(t *testing.T) { +// go test -run Test_GenericParseTypeInts +func Test_GenericParseTypeInts(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { value v @@ -4615,8 +4615,8 @@ func Test_genericParseTypeInts(t *testing.T) { } } -// go test -run Test_genericParseTypeInt8s -func Test_genericParseTypeInt8s(t *testing.T) { +// go test -run Test_GenericParseTypeInt8s +func Test_GenericParseTypeInt8s(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { @@ -4666,8 +4666,8 @@ func Test_genericParseTypeInt8s(t *testing.T) { } } -// go test -run Test_genericParseTypeInt16s -func Test_genericParseTypeInt16s(t *testing.T) { +// go test -run Test_GenericParseTypeInt16s +func Test_GenericParseTypeInt16s(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { value v @@ -4716,8 +4716,8 @@ func Test_genericParseTypeInt16s(t *testing.T) { } } -// go test -run Test_genericParseTypeInt32s -func Test_genericParseTypeInt32s(t *testing.T) { +// go test -run Test_GenericParseTypeInt32s +func Test_GenericParseTypeInt32s(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { value v @@ -4766,8 +4766,8 @@ func Test_genericParseTypeInt32s(t *testing.T) { } } -// go test -run Test_genericParseTypeInt64s -func Test_genericParseTypeInt64s(t *testing.T) { +// go test -run Test_GenericParseTypeInt64s +func Test_GenericParseTypeInt64s(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { value v @@ -4816,8 +4816,8 @@ func Test_genericParseTypeInt64s(t *testing.T) { } } -// go test -run Test_genericParseTypeUints -func Test_genericParseTypeUints(t *testing.T) { +// go test -run Test_GenericParseTypeUints +func Test_GenericParseTypeUints(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { value v @@ -4858,8 +4858,8 @@ func Test_genericParseTypeUints(t *testing.T) { } } -// go test -run Test_genericParseTypeUints -func Test_genericParseTypeUint8s(t *testing.T) { +// go test -run Test_GenericParseTypeUints +func Test_GenericParseTypeUint8s(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { value v @@ -4904,8 +4904,8 @@ func Test_genericParseTypeUint8s(t *testing.T) { } } -// go test -run Test_genericParseTypeUint16s -func Test_genericParseTypeUint16s(t *testing.T) { +// go test -run Test_GenericParseTypeUint16s +func Test_GenericParseTypeUint16s(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { @@ -4951,8 +4951,8 @@ func Test_genericParseTypeUint16s(t *testing.T) { } } -// go test -run Test_genericParseTypeUint32s -func Test_genericParseTypeUint32s(t *testing.T) { +// go test -run Test_GenericParseTypeUint32s +func Test_GenericParseTypeUint32s(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { @@ -4998,8 +4998,8 @@ func Test_genericParseTypeUint32s(t *testing.T) { } } -// go test -run Test_genericParseTypeUint64s -func Test_genericParseTypeUint64s(t *testing.T) { +// go test -run Test_GenericParseTypeUint64s +func Test_GenericParseTypeUint64s(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { value v @@ -5040,8 +5040,8 @@ func Test_genericParseTypeUint64s(t *testing.T) { } } -// go test -run Test_genericParseTypeFloat32s -func Test_genericParseTypeFloat32s(t *testing.T) { +// go test -run Test_GenericParseTypeFloat32s +func Test_GenericParseTypeFloat32s(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { @@ -5079,8 +5079,8 @@ func Test_genericParseTypeFloat32s(t *testing.T) { } } -// go test -run Test_genericParseTypeFloat64s -func Test_genericParseTypeFloat64s(t *testing.T) { +// go test -run Test_GenericParseTypeFloat64s +func Test_GenericParseTypeFloat64s(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { @@ -5118,8 +5118,8 @@ func Test_genericParseTypeFloat64s(t *testing.T) { } } -// go test -run Test_genericParseTypeArrayBytes -func Test_genericParseTypeArrayBytes(t *testing.T) { +// go test -run Test_GenericParseTypeArrayBytes +func Test_GenericParseTypeArrayBytes(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { @@ -5157,8 +5157,8 @@ func Test_genericParseTypeArrayBytes(t *testing.T) { } } -// go test -run Test_genericParseTypeBoolean -func Test_genericParseTypeBoolean(t *testing.T) { +// go test -run Test_GenericParseTypeBoolean +func Test_GenericParseTypeBoolean(t *testing.T) { t.Parallel() type genericTypes[v GenericType] struct { @@ -5201,8 +5201,8 @@ func Test_genericParseTypeBoolean(t *testing.T) { } } -// go test -run Test_genericParseTypeString -func Test_genericParseTypeString(t *testing.T) { +// go test -run Test_GenericParseTypeString +func Test_GenericParseTypeString(t *testing.T) { t.Parallel() tests := []string{"john", "doe", "hello", "fiber"} @@ -5218,8 +5218,8 @@ func Test_genericParseTypeString(t *testing.T) { } } -// go test -v -run=^$ -bench=Benchmark_genericParseTypeInts -benchmem -count=4 -func Benchmark_genericParseTypeInts(b *testing.B) { +// go test -v -run=^$ -bench=Benchmark_GenericParseTypeInts -benchmem -count=4 +func Benchmark_GenericParseTypeInts(b *testing.B) { type genericTypes[v GenericType] struct { value v str string @@ -5401,8 +5401,8 @@ func Benchmark_genericParseTypeInts(b *testing.B) { } } -// go test -v -run=^$ -bench=Benchmark_genericParseTypeUints -benchmem -count=4 -func Benchmark_genericParseTypeUints(b *testing.B) { +// go test -v -run=^$ -bench=Benchmark_GenericParseTypeUints -benchmem -count=4 +func Benchmark_GenericParseTypeUints(b *testing.B) { type genericTypes[v GenericType] struct { value v str string @@ -5584,8 +5584,8 @@ func Benchmark_genericParseTypeUints(b *testing.B) { } } -// go test -v -run=^$ -bench=Benchmark_genericParseTypeFloats -benchmem -count=4 -func Benchmark_genericParseTypeFloats(b *testing.B) { +// go test -v -run=^$ -bench=Benchmark_GenericParseTypeFloats -benchmem -count=4 +func Benchmark_GenericParseTypeFloats(b *testing.B) { type genericTypes[v GenericType] struct { value v str string @@ -5654,8 +5654,8 @@ func Benchmark_genericParseTypeFloats(b *testing.B) { } } -// go test -v -run=^$ -bench=Benchmark_genericParseTypeArrayBytes -benchmem -count=4 -func Benchmark_genericParseTypeArrayBytes(b *testing.B) { +// go test -v -run=^$ -bench=Benchmark_GenericParseTypeArrayBytes -benchmem -count=4 +func Benchmark_GenericParseTypeArrayBytes(b *testing.B) { type genericTypes[v GenericType] struct { value v str string @@ -5681,7 +5681,7 @@ func Benchmark_genericParseTypeArrayBytes(b *testing.B) { } for _, test := range arrBytes { - b.Run("Benchmark_genericParseTypeArrayBytes", func(b *testing.B) { + b.Run("Benchmark_GenericParseTypeArrayBytes", func(b *testing.B) { var res []byte b.ReportAllocs() b.ResetTimer() @@ -5693,8 +5693,8 @@ func Benchmark_genericParseTypeArrayBytes(b *testing.B) { } } -// go test -v -run=^$ -bench=Benchmark_genericParseTypeBoolean -benchmem -count=4 -func Benchmark_genericParseTypeBoolean(b *testing.B) { +// go test -v -run=^$ -bench=Benchmark_GenericParseTypeBoolean -benchmem -count=4 +func Benchmark_GenericParseTypeBoolean(b *testing.B) { type genericTypes[v GenericType] struct { value v str string @@ -5720,7 +5720,7 @@ func Benchmark_genericParseTypeBoolean(b *testing.B) { } for _, test := range bools { - b.Run("Benchmark_genericParseTypeBoolean", func(b *testing.B) { + b.Run("Benchmark_GenericParseTypeBoolean", func(b *testing.B) { var res bool b.ReportAllocs() b.ResetTimer() @@ -5736,8 +5736,8 @@ func Benchmark_genericParseTypeBoolean(b *testing.B) { } } -// go test -v -run=^$ -bench=Benchmark_genericParseTypeString -benchmem -count=4 -func Benchmark_genericParseTypeString(b *testing.B) { +// go test -v -run=^$ -bench=Benchmark_GenericParseTypeString -benchmem -count=4 +func Benchmark_GenericParseTypeString(b *testing.B) { tests := []string{"john", "doe", "hello", "fiber"} b.ReportAllocs() diff --git a/error_test.go b/error_test.go index 02096cd3db..e2eace101c 100644 --- a/error_test.go +++ b/error_test.go @@ -9,66 +9,66 @@ import ( "github.com/stretchr/testify/require" ) -func TestConversionError(t *testing.T) { +func Test_ConversionError(t *testing.T) { t.Parallel() ok := errors.As(ConversionError{}, &schema.ConversionError{}) require.True(t, ok) } -func TestUnknownKeyError(t *testing.T) { +func Test_UnknownKeyError(t *testing.T) { t.Parallel() ok := errors.As(UnknownKeyError{}, &schema.UnknownKeyError{}) require.True(t, ok) } -func TestEmptyFieldError(t *testing.T) { +func Test_EmptyFieldError(t *testing.T) { t.Parallel() ok := errors.As(EmptyFieldError{}, &schema.EmptyFieldError{}) require.True(t, ok) } -func TestMultiError(t *testing.T) { +func Test_MultiError(t *testing.T) { t.Parallel() ok := errors.As(MultiError{}, &schema.MultiError{}) require.True(t, ok) } -func TestInvalidUnmarshalError(t *testing.T) { +func Test_InvalidUnmarshalError(t *testing.T) { t.Parallel() var e *json.InvalidUnmarshalError ok := errors.As(&InvalidUnmarshalError{}, &e) require.True(t, ok) } -func TestMarshalerError(t *testing.T) { +func Test_MarshalerError(t *testing.T) { t.Parallel() var e *json.MarshalerError ok := errors.As(&MarshalerError{}, &e) require.True(t, ok) } -func TestSyntaxError(t *testing.T) { +func Test_SyntaxError(t *testing.T) { t.Parallel() var e *json.SyntaxError ok := errors.As(&SyntaxError{}, &e) require.True(t, ok) } -func TestUnmarshalTypeError(t *testing.T) { +func Test_UnmarshalTypeError(t *testing.T) { t.Parallel() var e *json.UnmarshalTypeError ok := errors.As(&UnmarshalTypeError{}, &e) require.True(t, ok) } -func TestUnsupportedTypeError(t *testing.T) { +func Test_UnsupportedTypeError(t *testing.T) { t.Parallel() var e *json.UnsupportedTypeError ok := errors.As(&UnsupportedTypeError{}, &e) require.True(t, ok) } -func TestUnsupportedValeError(t *testing.T) { +func Test_UnsupportedValeError(t *testing.T) { t.Parallel() var e *json.UnsupportedValueError ok := errors.As(&UnsupportedValueError{}, &e) diff --git a/middleware/cache/manager_msgp_test.go b/middleware/cache/manager_msgp_test.go index 0008ba9b51..ab4d912be8 100644 --- a/middleware/cache/manager_msgp_test.go +++ b/middleware/cache/manager_msgp_test.go @@ -8,7 +8,7 @@ import ( "github.com/tinylib/msgp/msgp" ) -func TestMarshalUnmarshalitem(t *testing.T) { +func Test_MarshalUnmarshalitem(t *testing.T) { v := item{} bts, err := v.MarshalMsg(nil) if err != nil { @@ -31,7 +31,7 @@ func TestMarshalUnmarshalitem(t *testing.T) { } } -func BenchmarkMarshalMsgitem(b *testing.B) { +func Benchmark_MarshalMsgitem(b *testing.B) { v := item{} b.ReportAllocs() b.ResetTimer() @@ -40,7 +40,7 @@ func BenchmarkMarshalMsgitem(b *testing.B) { } } -func BenchmarkAppendMsgitem(b *testing.B) { +func Benchmark_AppendMsgitem(b *testing.B) { v := item{} bts := make([]byte, 0, v.Msgsize()) bts, _ = v.MarshalMsg(bts[0:0]) @@ -52,7 +52,7 @@ func BenchmarkAppendMsgitem(b *testing.B) { } } -func BenchmarkUnmarshalitem(b *testing.B) { +func Benchmark_Unmarshalitem(b *testing.B) { v := item{} bts, _ := v.MarshalMsg(nil) b.ReportAllocs() diff --git a/middleware/cors/utils_test.go b/middleware/cors/utils_test.go index 6fec3dc463..4e8495772c 100644 --- a/middleware/cors/utils_test.go +++ b/middleware/cors/utils_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/assert" ) -// go test -run -v Test_normalizeOrigin -func Test_normalizeOrigin(t *testing.T) { +// go test -run -v Test_NormalizeOrigin +func Test_NormalizeOrigin(t *testing.T) { testCases := []struct { origin string expectedValid bool @@ -52,8 +52,8 @@ func Test_normalizeOrigin(t *testing.T) { } } -// go test -run -v Test_matchScheme -func Test_matchScheme(t *testing.T) { +// go test -run -v Test_MatchScheme +func Test_MatchScheme(t *testing.T) { testCases := []struct { domain string pattern string @@ -80,8 +80,8 @@ func Test_matchScheme(t *testing.T) { } } -// go test -run -v Test_normalizeDomain -func Test_normalizeDomain(t *testing.T) { +// go test -run -v Test_NormalizeDomain +func Test_NormalizeDomain(t *testing.T) { testCases := []struct { input string expectedOutput string diff --git a/middleware/csrf/manager_msgp_test.go b/middleware/csrf/manager_msgp_test.go index 49167c0fe4..4d2bd2371b 100644 --- a/middleware/csrf/manager_msgp_test.go +++ b/middleware/csrf/manager_msgp_test.go @@ -8,7 +8,7 @@ import ( "github.com/tinylib/msgp/msgp" ) -func TestMarshalUnmarshalitem(t *testing.T) { +func Test_MarshalUnmarshalitem(t *testing.T) { v := item{} bts, err := v.MarshalMsg(nil) if err != nil { @@ -31,7 +31,7 @@ func TestMarshalUnmarshalitem(t *testing.T) { } } -func BenchmarkMarshalMsgitem(b *testing.B) { +func Benchmark_MarshalMsgitem(b *testing.B) { v := item{} b.ReportAllocs() b.ResetTimer() @@ -40,7 +40,7 @@ func BenchmarkMarshalMsgitem(b *testing.B) { } } -func BenchmarkAppendMsgitem(b *testing.B) { +func Benchmark_AppendMsgitem(b *testing.B) { v := item{} bts := make([]byte, 0, v.Msgsize()) bts, _ = v.MarshalMsg(bts[0:0]) @@ -52,7 +52,7 @@ func BenchmarkAppendMsgitem(b *testing.B) { } } -func BenchmarkUnmarshalitem(b *testing.B) { +func Benchmark_Unmarshalitem(b *testing.B) { v := item{} bts, _ := v.MarshalMsg(nil) b.ReportAllocs() diff --git a/middleware/envvar/envvar_test.go b/middleware/envvar/envvar_test.go index 8c2fbeb05b..197ca81eca 100644 --- a/middleware/envvar/envvar_test.go +++ b/middleware/envvar/envvar_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestEnvVarStructWithExportVarsExcludeVars(t *testing.T) { +func Test_EnvVarStructWithExportVarsExcludeVars(t *testing.T) { t.Setenv("testKey", "testEnvValue") t.Setenv("anotherEnvKey", "anotherEnvVal") t.Setenv("excludeKey", "excludeEnvValue") @@ -27,7 +27,7 @@ func TestEnvVarStructWithExportVarsExcludeVars(t *testing.T) { require.Equal(t, "", vars.Vars["anotherEnvKey"]) } -func TestEnvVarHandler(t *testing.T) { +func Test_EnvVarHandler(t *testing.T) { t.Setenv("testKey", "testVal") expectedEnvVarResponse, err := json.Marshal( @@ -54,7 +54,7 @@ func TestEnvVarHandler(t *testing.T) { require.Equal(t, expectedEnvVarResponse, respBody) } -func TestEnvVarHandlerNotMatched(t *testing.T) { +func Test_EnvVarHandlerNotMatched(t *testing.T) { app := fiber.New() app.Use("/envvars", New(Config{ ExportVars: map[string]string{"testKey": ""}, @@ -76,7 +76,7 @@ func TestEnvVarHandlerNotMatched(t *testing.T) { require.Equal(t, []byte("OK"), respBody) } -func TestEnvVarHandlerDefaultConfig(t *testing.T) { +func Test_EnvVarHandlerDefaultConfig(t *testing.T) { t.Setenv("testEnvKey", "testEnvVal") app := fiber.New() @@ -96,7 +96,7 @@ func TestEnvVarHandlerDefaultConfig(t *testing.T) { require.Equal(t, "testEnvVal", val) } -func TestEnvVarHandlerMethod(t *testing.T) { +func Test_EnvVarHandlerMethod(t *testing.T) { app := fiber.New() app.Use("/envvars", New()) @@ -107,7 +107,7 @@ func TestEnvVarHandlerMethod(t *testing.T) { require.Equal(t, fiber.StatusMethodNotAllowed, resp.StatusCode) } -func TestEnvVarHandlerSpecialValue(t *testing.T) { +func Test_EnvVarHandlerSpecialValue(t *testing.T) { testEnvKey := "testEnvKey" fakeBase64 := "testBase64:TQ==" t.Setenv(testEnvKey, fakeBase64) diff --git a/middleware/idempotency/response_msgp_test.go b/middleware/idempotency/response_msgp_test.go index cf41da4939..a1241f9014 100644 --- a/middleware/idempotency/response_msgp_test.go +++ b/middleware/idempotency/response_msgp_test.go @@ -31,7 +31,7 @@ func TestMarshalUnmarshalresponse(t *testing.T) { } } -func BenchmarkMarshalMsgresponse(b *testing.B) { +func Benchmark_MarshalMsgresponse(b *testing.B) { v := response{} b.ReportAllocs() b.ResetTimer() @@ -40,7 +40,7 @@ func BenchmarkMarshalMsgresponse(b *testing.B) { } } -func BenchmarkAppendMsgresponse(b *testing.B) { +func Benchmark_AppendMsgresponse(b *testing.B) { v := response{} bts := make([]byte, 0, v.Msgsize()) bts, _ = v.MarshalMsg(bts[0:0]) @@ -52,7 +52,7 @@ func BenchmarkAppendMsgresponse(b *testing.B) { } } -func BenchmarkUnmarshalresponse(b *testing.B) { +func Benchmark_Unmarshalresponse(b *testing.B) { v := response{} bts, _ := v.MarshalMsg(nil) b.ReportAllocs() diff --git a/middleware/keyauth/keyauth_test.go b/middleware/keyauth/keyauth_test.go index 36607d9e6c..3cb756dc32 100644 --- a/middleware/keyauth/keyauth_test.go +++ b/middleware/keyauth/keyauth_test.go @@ -14,7 +14,7 @@ import ( const CorrectKey = "specials: !$%,.#\"!?~`<>@$^*(){}[]|/\\123" -func TestAuthSources(t *testing.T) { +func Test_AuthSources(t *testing.T) { // define test cases testSources := []string{"header", "cookie", "query", "param", "form"} @@ -130,7 +130,7 @@ func TestAuthSources(t *testing.T) { } } -func TestMultipleKeyAuth(t *testing.T) { +func Test_MultipleKeyAuth(t *testing.T) { // setup the fiber endpoint app := fiber.New() @@ -261,7 +261,7 @@ func TestMultipleKeyAuth(t *testing.T) { } } -func TestCustomSuccessAndFailureHandlers(t *testing.T) { +func Test_CustomSuccessAndFailureHandlers(t *testing.T) { app := fiber.New() app.Use(New(Config{ @@ -314,7 +314,7 @@ func TestCustomSuccessAndFailureHandlers(t *testing.T) { require.Equal(t, "API key is valid and request was handled by custom success handler", string(body)) } -func TestCustomNextFunc(t *testing.T) { +func Test_CustomNextFunc(t *testing.T) { app := fiber.New() app.Use(New(Config{ @@ -376,7 +376,7 @@ func TestCustomNextFunc(t *testing.T) { require.Equal(t, string(body), ErrMissingOrMalformedAPIKey.Error()) } -func TestAuthSchemeToken(t *testing.T) { +func Test_AuthSchemeToken(t *testing.T) { app := fiber.New() app.Use(New(Config{ @@ -411,7 +411,7 @@ func TestAuthSchemeToken(t *testing.T) { require.Equal(t, "API key is valid", string(body)) } -func TestAuthSchemeBasic(t *testing.T) { +func Test_AuthSchemeBasic(t *testing.T) { app := fiber.New() app.Use(New(Config{ diff --git a/middleware/limiter/manager_msgp_test.go b/middleware/limiter/manager_msgp_test.go index b1507dd863..39562df395 100644 --- a/middleware/limiter/manager_msgp_test.go +++ b/middleware/limiter/manager_msgp_test.go @@ -8,7 +8,7 @@ import ( "github.com/tinylib/msgp/msgp" ) -func TestMarshalUnmarshalitem(t *testing.T) { +func Test_MarshalUnmarshalitem(t *testing.T) { v := item{} bts, err := v.MarshalMsg(nil) if err != nil { @@ -31,7 +31,7 @@ func TestMarshalUnmarshalitem(t *testing.T) { } } -func BenchmarkMarshalMsgitem(b *testing.B) { +func Benchmark_MarshalMsgitem(b *testing.B) { v := item{} b.ReportAllocs() b.ResetTimer() @@ -40,7 +40,7 @@ func BenchmarkMarshalMsgitem(b *testing.B) { } } -func BenchmarkAppendMsgitem(b *testing.B) { +func Benchmark_AppendMsgitem(b *testing.B) { v := item{} bts := make([]byte, 0, v.Msgsize()) bts, _ = v.MarshalMsg(bts[0:0]) @@ -52,7 +52,7 @@ func BenchmarkAppendMsgitem(b *testing.B) { } } -func BenchmarkUnmarshalitem(b *testing.B) { +func Benchmark_Unmarshalitem(b *testing.B) { v := item{} bts, _ := v.MarshalMsg(nil) b.ReportAllocs() diff --git a/middleware/session/store_test.go b/middleware/session/store_test.go index 130f13feba..1373827899 100644 --- a/middleware/session/store_test.go +++ b/middleware/session/store_test.go @@ -9,8 +9,8 @@ import ( "github.com/valyala/fasthttp" ) -// go test -run TestStore_getSessionID -func TestStore_getSessionID(t *testing.T) { +// go test -run Test_Store_getSessionID +func Test_Store_getSessionID(t *testing.T) { t.Parallel() expectedID := "test-session-id" @@ -61,9 +61,9 @@ func TestStore_getSessionID(t *testing.T) { }) } -// go test -run TestStore_Get +// go test -run Test_Store_Get // Regression: https://github.com/gofiber/fiber/issues/1408 -func TestStore_Get(t *testing.T) { +func Test_Store_Get(t *testing.T) { t.Parallel() unexpectedID := "test-session-id" // fiber instance @@ -85,8 +85,8 @@ func TestStore_Get(t *testing.T) { }) } -// go test -run TestStore_DeleteSession -func TestStore_DeleteSession(t *testing.T) { +// go test -run Test_Store_DeleteSession +func Test_Store_DeleteSession(t *testing.T) { t.Parallel() // fiber instance app := fiber.New()