StartServerWithConfig starts a server from given config, and returns a function to close the server. Prefer use of RestTester for more ergonomic APIs.
(t *testing.T, config *StartupConfig)
| 189 | |
| 190 | // StartServerWithConfig starts a server from given config, and returns a function to close the server. Prefer use of RestTester for more ergonomic APIs. |
| 191 | func StartServerWithConfig(t *testing.T, config *StartupConfig) (*ServerContext, func()) { |
| 192 | ctx := base.TestCtx(t) |
| 193 | sc, err := SetupServerContext(ctx, config, true) |
| 194 | require.NoError(t, err) |
| 195 | |
| 196 | serverErr := make(chan error) |
| 197 | |
| 198 | closeFn := func() { |
| 199 | sc.Close(ctx) |
| 200 | assert.NoError(t, <-serverErr) |
| 201 | } |
| 202 | |
| 203 | started := false |
| 204 | defer func() { |
| 205 | if !started { |
| 206 | closeFn() |
| 207 | } |
| 208 | |
| 209 | }() |
| 210 | go func() { |
| 211 | serverErr <- StartServer(ctx, config, sc) |
| 212 | }() |
| 213 | |
| 214 | require.NoError(t, sc.WaitForRESTAPIs(ctx)) |
| 215 | started = true |
| 216 | return sc, closeFn |
| 217 | } |