TestServer runs the enterprise server command and waits for /healthz to return "OK".
(t *testing.T)
| 26 | // TestServer runs the enterprise server command |
| 27 | // and waits for /healthz to return "OK". |
| 28 | func 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 | |
| 67 | func waitAccessURL(t *testing.T, cfg config.Root) *url.URL { |
| 68 | t.Helper() |
nothing calls this directly
no test coverage detected