MCPcopy Create free account
hub / github.com/efficientgo/e2e / Ready

Method Ready

env.go:308–343  ·  view source on GitHub ↗
(runnable Runnable)

Source from the content-addressed store, hash-verified

306}
307
308func (p *HTTPReadinessProbe) Ready(runnable Runnable) (err error) {
309 endpoint := runnable.Endpoint(p.portName)
310 if endpoint == "" {
311 return errors.Newf("cannot get service endpoint for port %s", p.portName)
312 }
313 if endpoint == "stopped" {
314 return errors.New("service has stopped")
315 }
316
317 httpClient := &http.Client{Timeout: 1 * time.Second}
318 if p.scheme == "HTTPS" {
319 httpClient.Transport = &http.Transport{
320 TLSClientConfig: &tls.Config{
321 InsecureSkipVerify: true,
322 },
323 }
324 }
325
326 res, err := httpClient.Get(p.scheme + "://" + endpoint + p.path)
327 if err != nil {
328 return err
329 }
330 defer errcapture.ExhaustClose(&err, res.Body, "response readiness")
331
332 body, _ := io.ReadAll(res.Body)
333 if res.StatusCode < p.expectedStatusRangeStart || res.StatusCode > p.expectedStatusRangeEnd {
334 return errors.Newf("expected code in range: [%v, %v], got status code: %v and body: %v", p.expectedStatusRangeStart, p.expectedStatusRangeEnd, res.StatusCode, string(body))
335 }
336
337 for _, expected := range p.expectedContent {
338 if !strings.Contains(string(body), expected) {
339 return errors.Newf("expected body containing %s, got: %v", expected, string(body))
340 }
341 }
342 return nil
343}
344
345// TCPReadinessProbe checks readiness by ensure a TCP connection can be established.
346type TCPReadinessProbe struct {

Callers

nothing calls this directly

Calls 1

EndpointMethod · 0.65

Tested by

no test coverage detected