Browse Source

🐛 Fix pointer typo [ Fiber ] (#5871)

* Update Fiber v1.10.0

* Fiber: Bump v1.12.0

* Update constant

* Fiber optimization

* v1.12.1

* Update dependencies

* Update cached worlds test

* Update cached test

* Update cached test

* Update cache test

* Fix cache test

* Update cache test

* Update cache test

* Fix panic

* 🧹 Fix test-requirements

* 👩‍🚀 Optimize response

* 🐛 Fix typo

* 📦 Update test

* 📦 Bump v1.12.6

* 🐛 Fix test

* 🐛 Fix test

* 🧹

* 📘 Add two simple benchmark test cases

* 🍬 remove extra '&'

* 🐛 Fix JSON pointer

Co-authored-by: Fenny <Fenny>
Co-authored-by: kiyon <[email protected]>
fenny 5 years ago
parent
commit
baab422dcd
1 changed files with 62 additions and 0 deletions
  1. 62 0
      frameworks/Go/fiber/src/server_test.go

+ 62 - 0
frameworks/Go/fiber/src/server_test.go

@@ -0,0 +1,62 @@
+package main
+
+import (
+	"github.com/gofiber/fiber"
+	"github.com/gofiber/utils"
+	"io/ioutil"
+	"net/http"
+	"net/http/httptest"
+	"testing"
+)
+
+// go test -v  -run=^$ -bench=Benchmark_Plaintext -benchmem -count=4
+func Benchmark_Plaintext(b *testing.B) {
+	app := fiber.New()
+	app.Settings.DisableStartupMessage = true
+
+	app.Get("/plaintext", plaintextHandler)
+
+	var (
+		resp *http.Response
+		err  error
+	)
+
+	b.ReportAllocs()
+	b.ResetTimer()
+
+	for i := 0; i < b.N; i++ {
+		resp, err = app.Test(httptest.NewRequest("GET", "/plaintext", nil))
+	}
+
+	utils.AssertEqual(b, nil, err, "app.Test(req)")
+	utils.AssertEqual(b, 200, resp.StatusCode, "Status code")
+	utils.AssertEqual(b, fiber.MIMETextPlainCharsetUTF8, resp.Header.Get("Content-Type"))
+	body, _ := ioutil.ReadAll(resp.Body)
+	utils.AssertEqual(b, helloworldRaw, body)
+}
+
+// go test -v  -run=^$ -bench=Benchmark_JSON -benchmem -count=4
+func Benchmark_JSON(b *testing.B) {
+	app := fiber.New()
+	app.Settings.DisableStartupMessage = true
+
+	app.Get("/json", jsonHandler)
+
+	var (
+		resp *http.Response
+		err  error
+	)
+
+	b.ReportAllocs()
+	b.ResetTimer()
+
+	for i := 0; i < b.N; i++ {
+		resp, err = app.Test(httptest.NewRequest("GET", "/json", nil))
+	}
+
+	utils.AssertEqual(b, nil, err, "app.Test(req)")
+	utils.AssertEqual(b, 200, resp.StatusCode, "Status code")
+	utils.AssertEqual(b, fiber.MIMEApplicationJSON, resp.Header.Get("Content-Type"))
+	body, _ := ioutil.ReadAll(resp.Body)
+	utils.AssertEqual(b, `{"message":"Hello, World!"}`, string(body))
+}