Shit ton of tests

This commit is contained in:
Melody Becker 2025-04-24 15:59:15 +02:00
parent 99b00887a8
commit ccf98c2f6e
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
13 changed files with 1157 additions and 1 deletions

23
http/context_test.go Normal file
View 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
}