all: sync with master; upd chlog
This commit is contained in:
@@ -4,10 +4,14 @@ package aghtest
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -51,3 +55,19 @@ func HostToIPs(host string) (ipv4, ipv6 netip.Addr) {
|
||||
|
||||
return netip.AddrFrom4([4]byte(hash[:4])), netip.AddrFrom16([16]byte(hash[4:20]))
|
||||
}
|
||||
|
||||
// StartHTTPServer is a helper that starts the HTTP server, which is configured
|
||||
// to return data on every request, and returns the client and server URL.
|
||||
func StartHTTPServer(t testing.TB, data []byte) (c *http.Client, u *url.URL) {
|
||||
t.Helper()
|
||||
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
_, _ = w.Write(data)
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
u, err := url.Parse(srv.URL)
|
||||
require.NoError(t, err)
|
||||
|
||||
return srv.Client(), u
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user