Files
isp-admin-service/vendor/github.com/txix-open/isp-kit/test/httpt/server.go
T
2026-11-23 12:58:04 +03:00

21 lines
672 B
Go

package httpt
import (
"net/http"
"net/http/httptest"
"github.com/txix-open/isp-kit/http/httpcli"
"github.com/txix-open/isp-kit/http/httpclix"
"github.com/txix-open/isp-kit/test"
)
// TestServer creates and starts an HTTP test server with the provided handler,
// returning both the server and a configured client. The server listens on
// a random local port and the client is pre-configured with the server's URL.
func TestServer(t *test.Test, handler http.Handler, opts ...httpcli.Option) (*httptest.Server, *httpcli.Client) {
srv := httptest.NewServer(handler)
cli := httpclix.Default(opts...)
cli.GlobalRequestConfig().BaseUrl = srv.URL
return srv, cli
}