all repos

x @ main

go extra()

x/reqid/reqid_test.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
reqid: add reqid :), 3 months ago
1
package reqid
2
3
import (
4
	"net/http"
5
	"net/http/httptest"
6
	"testing"
7
8
	"olexsmir.xyz/x/is"
9
)
10
11
func TestMiddleware(t *testing.T) {
12
	mux := http.NewServeMux()
13
	mux.HandleFunc("GET /", testHandler)
14
	hand := Middleware(mux)
15
16
	w := httptest.NewRecorder()
17
	req, _ := http.NewRequest(http.MethodGet, "/", nil)
18
	hand.ServeHTTP(w, req)
19
20
	is.Equal(t, http.StatusOK, w.Code)
21
	is.NotEqual(t, w.Header().Get(Header), "")
22
}
23
24
func BenchmarkMiddleware(b *testing.B) {
25
	mux := http.NewServeMux()
26
	mux.HandleFunc("GET /", testHandler)
27
	hand := Middleware(mux)
28
29
	w := httptest.NewRecorder()
30
	req, _ := http.NewRequest(http.MethodGet, "/", nil)
31
32
	for b.Loop() {
33
		hand.ServeHTTP(w, req)
34
	}
35
}
36
37
func testHandler(w http.ResponseWriter, _ *http.Request) {
38
	w.WriteHeader(http.StatusOK)
39
}