MCPcopy Create free account
hub / github.com/prometheus/common / newTestServer

Function newTestServer

config/http_config_test.go:140–166  ·  view source on GitHub ↗
(handler func(w http.ResponseWriter, r *http.Request))

Source from the content-addressed store, hash-verified

138}
139
140func newTestServer(handler func(w http.ResponseWriter, r *http.Request)) (*httptest.Server, error) {
141 testServer := httptest.NewUnstartedServer(http.HandlerFunc(handler))
142
143 tlsCAChain, err := os.ReadFile(TLSCAChainPath)
144 if err != nil {
145 return nil, fmt.Errorf("Can't read %s", TLSCAChainPath)
146 }
147 serverCertificate, err := tls.LoadX509KeyPair(ServerCertificatePath, ServerKeyPath)
148 if err != nil {
149 return nil, fmt.Errorf("Can't load X509 key pair %s - %s", ServerCertificatePath, ServerKeyPath)
150 }
151
152 rootCAs := x509.NewCertPool()
153 rootCAs.AppendCertsFromPEM(tlsCAChain)
154
155 testServer.TLS = &tls.Config{
156 Certificates: make([]tls.Certificate, 1),
157 RootCAs: rootCAs,
158 ClientAuth: tls.RequireAndVerifyClientCert,
159 ClientCAs: rootCAs,
160 }
161 testServer.TLS.Certificates[0] = serverCertificate
162
163 testServer.StartTLS()
164
165 return testServer, nil
166}
167
168func TestNewClientFromConfig(t *testing.T) {
169 newClientValidConfig := []struct {

Callers 6

TestNewClientFromConfigFunction · 0.85
TestTLSRoundTripperFunction · 0.85
TestTLSRoundTripperRacesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected