( ctx context.Context, t *testing.T, apps []codersdk.WorkspaceApp, handlers []http.Handler, clk quartz.Clock, )
| 230 | } |
| 231 | |
| 232 | func setupAppReporter( |
| 233 | ctx context.Context, t *testing.T, |
| 234 | apps []codersdk.WorkspaceApp, |
| 235 | handlers []http.Handler, |
| 236 | clk quartz.Clock, |
| 237 | ) (*agenttest.FakeAgentAPI, func()) { |
| 238 | closers := []func(){} |
| 239 | for _, app := range apps { |
| 240 | require.NotEqual(t, uuid.Nil, app.ID, "all apps must have ID set") |
| 241 | } |
| 242 | for i, handler := range handlers { |
| 243 | if handler == nil { |
| 244 | continue |
| 245 | } |
| 246 | ts := httptest.NewServer(handler) |
| 247 | app := apps[i] |
| 248 | app.Healthcheck.URL = ts.URL |
| 249 | apps[i] = app |
| 250 | closers = append(closers, ts.Close) |
| 251 | } |
| 252 | |
| 253 | // We don't care about manifest or stats in this test since it's not using |
| 254 | // a full agent and these RPCs won't get called. |
| 255 | // |
| 256 | // We use a proper fake agent API so we can test the conversion code and the |
| 257 | // request code as well. Before we were bypassing these by using a custom |
| 258 | // post function. |
| 259 | fakeAAPI := agenttest.NewFakeAgentAPI(t, testutil.Logger(t), nil, nil) |
| 260 | |
| 261 | go agent.NewAppHealthReporterWithClock( |
| 262 | testutil.Logger(t), |
| 263 | apps, agentsdk.AppHealthPoster(fakeAAPI), clk, |
| 264 | )(ctx) |
| 265 | |
| 266 | return fakeAAPI, func() { |
| 267 | for _, closeFn := range closers { |
| 268 | closeFn() |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | func applyUpdate(t *testing.T, apps []codersdk.WorkspaceApp, req *proto.BatchUpdateAppHealthRequest) { |
| 274 | t.Helper() |
no test coverage detected