mirror of
https://github.com/cert-manager/webhook-example.git
synced 2025-07-03 07:05:50 +02:00
37 lines
791 B
Go
37 lines
791 B
Go
package test
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"net"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
)
|
|
|
|
// Testclient ...
|
|
type Testclient struct{}
|
|
|
|
// TestingHTTPClient ...
|
|
func (c Testclient) TestingHTTPClient(handler http.Handler) (*http.Client, func()) {
|
|
s := httptest.NewTLSServer(handler)
|
|
|
|
cli := &http.Client{
|
|
Transport: &http.Transport{
|
|
DialContext: func(_ context.Context, network, _ string) (net.Conn, error) {
|
|
return net.Dial(network, s.Listener.Addr().String())
|
|
},
|
|
TLSClientConfig: &tls.Config{
|
|
InsecureSkipVerify: true,
|
|
},
|
|
},
|
|
}
|
|
|
|
return cli, s.Close
|
|
}
|
|
|
|
// NewTestingHTTPClient - Create a new TestingHTTPClient
|
|
func (c *Testclient) NewTestingHTTPClient(handler http.Handler) (*http.Client, func()) {
|
|
client, fn := c.TestingHTTPClient(handler)
|
|
|
|
return client, fn
|
|
}
|