Files
zip/adapt_test.go
zeekayandHanzo Dev 2869190b45 refactor!: drop AdaptNetHTTPFunc — http.HandlerFunc IS an http.Handler
Two adapters did one job. http.HandlerFunc already satisfies http.Handler, and
the underlying fiber adaptor.HTTPHandlerFunc is literally `return
HTTPHandler(h)` — so AdaptNetHTTPFunc was a second name for the same
conversion, differing only in that it let a bare func literal skip the explicit
http.HandlerFunc() cast.

One adapter, one path: adapt a bare func as
AdaptNetHTTP(http.HandlerFunc(fn)). AdaptNetHTTP and AdaptNetHTTPMiddleware
stay — they front third-party handlers and stdlib middleware that cannot be
rewritten natively, and they are genuinely different shapes.

adapt_test.go pins the func path so the removed adapter cannot creep back.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-27 12:14:44 -07:00

26 lines
842 B
Go

package zip_test
import (
"io"
"net/http"
"strings"
"testing"
"github.com/zap-proto/zip"
)
// TestAdaptNetHTTP_HandlerFunc pins the ONE way to adapt a bare
// func(http.ResponseWriter, *http.Request): convert it with http.HandlerFunc,
// which IS an http.Handler, and hand that to AdaptNetHTTP. There is no
// separate func-shaped adapter — one adapter, one path.
func TestAdaptNetHTTP_HandlerFunc(t *testing.T) {
app := zip.New(zip.Config{DisableStartupMessage: true})
app.Get("/fn", zip.AdaptNetHTTP(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = io.WriteString(w, "from-func "+r.URL.Path)
})))
if status, body := call(t, app, "GET", "/fn", ""); status != 200 || !strings.Contains(body, "from-func /fn") {
t.Fatalf("GET /fn: status=%d body=%q, want 200 with the func's output", status, body)
}
}