Shit ton of tests
This commit is contained in:
parent
99b00887a8
commit
ccf98c2f6e
13 changed files with 1157 additions and 1 deletions
23
http/context_test.go
Normal file
23
http/context_test.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package webutils_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
webutils "git.mstar.dev/mstar/goutils/http"
|
||||
)
|
||||
|
||||
func TestContextValsMiddleware(t *testing.T) {
|
||||
builder := webutils.ContextValsMiddleware(map[any]any{"foo": "bar"})
|
||||
baseHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if val, _ := r.Context().Value("foo").(string); val != "bar" {
|
||||
t.Fatalf(`Expected context value "foo" to be "bar", got %v`, val)
|
||||
}
|
||||
})
|
||||
wrapped := builder(baseHandler)
|
||||
recorder := httptest.NewRecorder()
|
||||
req := httptest.NewRequest("GET", "/", nil)
|
||||
wrapped.ServeHTTP(recorder, req)
|
||||
// At this point baseHandler should have been called and checked for the context value
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue