Shit ton of tests
This commit is contained in:
parent
99b00887a8
commit
ccf98c2f6e
13 changed files with 1157 additions and 1 deletions
33
http/chain_test.go
Normal file
33
http/chain_test.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package webutils_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
webutils "git.mstar.dev/mstar/goutils/http"
|
||||
)
|
||||
|
||||
func TestChainMiddlewares(t *testing.T) {
|
||||
wrapper1 := webutils.HandlerBuilder(func(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Header.Add("X-Foo", "bar")
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
})
|
||||
wrapper2 := webutils.HandlerBuilder(func(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Header.Add("X-Foos", r.Header.Get("X-Foo")+"baz")
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
})
|
||||
baseHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if x := r.Header.Get("X-Foos"); x != "barbaz" {
|
||||
t.Fatalf(`Expected header "X-Foos" to be "barbaz", got %v`, x)
|
||||
}
|
||||
})
|
||||
handler := webutils.ChainMiddlewares(baseHandler, wrapper1, wrapper2)
|
||||
recorder := httptest.NewRecorder()
|
||||
req := httptest.NewRequest("GET", "/", nil)
|
||||
handler.ServeHTTP(recorder, req)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue