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

Function TestServer_Single

enterprise/cli/server_test.go:28–65  ·  view source on GitHub ↗

TestServer runs the enterprise server command and waits for /healthz to return "OK".

(t *testing.T)

Source from the content-addressed store, hash-verified

26// TestServer runs the enterprise server command
27// and waits for /healthz to return "OK".
28func TestServer_Single(t *testing.T) {
29 t.Parallel()
30
31 ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitLong)
32 defer cancelFunc()
33
34 var root cli.RootCmd
35 cmd, err := root.Command(root.EnterpriseSubcommands())
36 require.NoError(t, err)
37
38 inv, cfg := clitest.NewWithCommand(t, cmd,
39 "server",
40 dbArg(t),
41 "--http-address", ":0",
42 "--access-url", "http://example.com",
43 )
44 clitest.Start(t, inv.WithContext(ctx))
45 accessURL := waitAccessURL(t, cfg)
46 client := &http.Client{}
47 require.Eventually(t, func() bool {
48 reqCtx := testutil.Context(t, testutil.IntervalMedium)
49 req, err := http.NewRequestWithContext(reqCtx, http.MethodGet, accessURL.String()+"/healthz", nil)
50 if err != nil {
51 panic(err)
52 }
53 resp, err := client.Do(req)
54 if err != nil {
55 t.Log("/healthz not ready yet")
56 return false
57 }
58 defer resp.Body.Close()
59 bs, err := io.ReadAll(resp.Body)
60 if err != nil {
61 panic(err)
62 }
63 return assert.Equal(t, "OK", string(bs))
64 }, testutil.WaitShort, testutil.IntervalMedium)
65}
66
67func waitAccessURL(t *testing.T, cfg config.Root) *url.URL {
68 t.Helper()

Callers

nothing calls this directly

Calls 14

CommandMethod · 0.95
EnterpriseSubcommandsMethod · 0.95
NewWithCommandFunction · 0.92
StartFunction · 0.92
ContextFunction · 0.92
WithContextMethod · 0.80
LogMethod · 0.80
dbArgFunction · 0.70
waitAccessURLFunction · 0.70
DoMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected