--- WebSocket end-to-end tests --- dialGitWatch starts an httptest server with the agentgit API and returns a wsjson.Stream connected to it. The server and connection are cleaned up when the test ends.
(t *testing.T, opts ...agentgit.Option)
| 659 | // returns a wsjson.Stream connected to it. The server and connection |
| 660 | // are cleaned up when the test ends. |
| 661 | func dialGitWatch(t *testing.T, opts ...agentgit.Option) *wsjson.Stream[ |
| 662 | codersdk.WorkspaceAgentGitServerMessage, |
| 663 | codersdk.WorkspaceAgentGitClientMessage, |
| 664 | ] { |
| 665 | t.Helper() |
| 666 | logger := slogtest.Make(t, nil) |
| 667 | api := agentgit.NewAPI(logger, nil, opts...) |
| 668 | srv := httptest.NewServer(api.Routes()) |
| 669 | t.Cleanup(srv.Close) |
| 670 | |
| 671 | wsURL := "ws" + srv.URL[len("http"):] + "/watch" |
| 672 | conn, _, err := websocket.Dial(context.Background(), wsURL, nil) |
| 673 | require.NoError(t, err) |
| 674 | t.Cleanup(func() { _ = conn.Close(websocket.StatusNormalClosure, "") }) |
| 675 | |
| 676 | return wsjson.NewStream[ |
| 677 | codersdk.WorkspaceAgentGitServerMessage, |
| 678 | codersdk.WorkspaceAgentGitClientMessage, |
| 679 | ](conn, websocket.MessageText, websocket.MessageText, logger) |
| 680 | } |
| 681 | |
| 682 | // dialGitWatchWithPathStore starts an httptest server backed by the |
| 683 | // given PathStore and returns a stream connected with the given |