dialGitWatchWithPathStore starts an httptest server backed by the given PathStore and returns a stream connected with the given chat ID. The PathStore is used to feed paths into the handler instead of client-side subscribe messages.
( t *testing.T, ps *agentgit.PathStore, chatID uuid.UUID, opts ...agentgit.Option, )
| 684 | // chat ID. The PathStore is used to feed paths into the handler |
| 685 | // instead of client-side subscribe messages. |
| 686 | func dialGitWatchWithPathStore( |
| 687 | t *testing.T, |
| 688 | ps *agentgit.PathStore, |
| 689 | chatID uuid.UUID, |
| 690 | opts ...agentgit.Option, |
| 691 | ) *wsjson.Stream[ |
| 692 | codersdk.WorkspaceAgentGitServerMessage, |
| 693 | codersdk.WorkspaceAgentGitClientMessage, |
| 694 | ] { |
| 695 | t.Helper() |
| 696 | logger := slogtest.Make(t, nil) |
| 697 | api := agentgit.NewAPI(logger, ps, opts...) |
| 698 | srv := httptest.NewServer(api.Routes()) |
| 699 | t.Cleanup(srv.Close) |
| 700 | |
| 701 | wsURL := "ws" + srv.URL[len("http"):] + "/watch?chat_id=" + chatID.String() |
| 702 | conn, _, err := websocket.Dial(context.Background(), wsURL, nil) |
| 703 | require.NoError(t, err) |
| 704 | t.Cleanup(func() { _ = conn.Close(websocket.StatusNormalClosure, "") }) |
| 705 | |
| 706 | return wsjson.NewStream[ |
| 707 | codersdk.WorkspaceAgentGitServerMessage, |
| 708 | codersdk.WorkspaceAgentGitClientMessage, |
| 709 | ](conn, websocket.MessageText, websocket.MessageText, logger) |
| 710 | } |
| 711 | |
| 712 | // recvMsg reads the next server message, using the provided |
| 713 | // context for the timeout instead of a raw time.After. |
no test coverage detected