MCPcopy Index your code
hub / github.com/coder/coder / TestAccessURL

Function TestAccessURL

coderd/healthcheck/accessurl_test.go:18–154  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestAccessURL(t *testing.T) {
19 t.Parallel()
20
21 t.Run("OK", func(t *testing.T) {
22 t.Parallel()
23
24 var (
25 ctx, cancel = context.WithCancel(context.Background())
26 report healthcheck.AccessURLReport
27 resp = []byte("OK")
28 srv = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
29 w.WriteHeader(http.StatusOK)
30 _, _ = w.Write(resp)
31 }))
32 )
33 defer cancel()
34
35 report.Run(ctx, &healthcheck.AccessURLReportOptions{
36 Client: srv.Client(),
37 AccessURL: mustURL(t, srv.URL),
38 })
39
40 assert.True(t, report.Healthy)
41 assert.True(t, report.Reachable)
42 assert.Equal(t, health.SeverityOK, report.Severity)
43 assert.Equal(t, http.StatusOK, report.StatusCode)
44 assert.Equal(t, "OK", report.HealthzResponse)
45 assert.Nil(t, report.Error)
46 })
47
48 t.Run("NotSet", func(t *testing.T) {
49 t.Parallel()
50
51 var (
52 ctx, cancel = context.WithCancel(context.Background())
53 report healthcheck.AccessURLReport
54 )
55 defer cancel()
56
57 report.Run(ctx, &healthcheck.AccessURLReportOptions{
58 Client: &http.Client{},
59 AccessURL: nil,
60 })
61
62 assert.False(t, report.Healthy)
63 assert.False(t, report.Reachable)
64 assert.Equal(t, health.SeverityError, report.Severity)
65 assert.Equal(t, 0, report.StatusCode)
66 assert.Equal(t, "", report.HealthzResponse)
67 require.NotNil(t, report.Error)
68 assert.Contains(t, *report.Error, health.CodeAccessURLNotSet)
69 })
70
71 t.Run("ClientErr", func(t *testing.T) {
72 t.Parallel()
73
74 var (
75 ctx, cancel = context.WithCancel(context.Background())

Callers

nothing calls this directly

Calls 12

mustURLFunction · 0.85
ClientMethod · 0.80
NotEmptyMethod · 0.80
roundTripFuncFuncType · 0.70
RunMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65
NewMethod · 0.65
WriteHeaderMethod · 0.45
EqualMethod · 0.45
ContainsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected