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

Function newTestServer

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

Source from the content-addressed store, hash-verified

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

Callers 7

TestNewClientFromConfigFunction · 0.85
TestTLSRoundTripperFunction · 0.85
TestTLSRoundTripperRacesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…