MCPcopy Index your code
hub / github.com/coder/coder / runWatchChatGitWorkspaceLookupTest

Function runWatchChatGitWorkspaceLookupTest

coderd/workspaceagents_internal_test.go:110–163  ·  view source on GitHub ↗

runWatchChatGitWorkspaceLookupTest exercises the GetWorkspaceByID error branches in authorizeChatWorkspaceExec. The chat middleware always succeeds; the workspace lookup returns workspaceErr, and the handler is expected to respond with wantStatus.

(t *testing.T, workspaceErr error, wantStatus int)

Source from the content-addressed store, hash-verified

108// always succeeds; the workspace lookup returns workspaceErr, and the
109// handler is expected to respond with wantStatus.
110func runWatchChatGitWorkspaceLookupTest(t *testing.T, workspaceErr error, wantStatus int) {
111 t.Helper()
112
113 var (
114 ctx = testutil.Context(t, testutil.WaitShort)
115 logger = slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug).Named("coderd")
116
117 mCtrl = gomock.NewController(t)
118 mDB = dbmock.NewMockStore(mCtrl)
119
120 chatID = uuid.New()
121 workspaceID = uuid.New()
122
123 r = chi.NewMux()
124
125 api = API{
126 ctx: ctx,
127 Options: &Options{
128 AgentInactiveDisconnectTimeout: testutil.WaitShort,
129 Database: mDB,
130 Logger: logger,
131 DeploymentValues: &codersdk.DeploymentValues{},
132 },
133 HTTPAuth: &HTTPAuthorizer{
134 Authorizer: &mockAuthorizer{},
135 Logger: logger,
136 },
137 }
138 )
139
140 mDB.EXPECT().GetChatByID(gomock.Any(), chatID).Return(database.Chat{
141 ID: chatID,
142 OwnerID: uuid.New(),
143 WorkspaceID: uuid.NullUUID{UUID: workspaceID, Valid: true},
144 }, nil)
145
146 mDB.EXPECT().GetWorkspaceByID(gomock.Any(), workspaceID).Return(database.Workspace{}, workspaceErr)
147
148 r.With(injectSystemActor, httpmw.ExtractChatParam(mDB)).
149 Get("/chats/{chat}/stream/git", api.watchChatGit)
150
151 srv := httptest.NewServer(r)
152 defer srv.Close()
153
154 req, err := http.NewRequestWithContext(ctx, http.MethodGet,
155 fmt.Sprintf("%s/chats/%s/stream/git", srv.URL, chatID), nil)
156 require.NoError(t, err)
157
158 resp, err := http.DefaultClient.Do(req)
159 require.NoError(t, err)
160 defer resp.Body.Close()
161
162 require.Equal(t, wantStatus, resp.StatusCode)
163}
164
165func TestWatchChatGit(t *testing.T) {
166 t.Parallel()

Callers 1

TestWatchChatGitFunction · 0.85

Calls 14

CloseMethod · 0.95
ContextFunction · 0.92
NewMockStoreFunction · 0.92
ExtractChatParamFunction · 0.92
NamedMethod · 0.80
HelperMethod · 0.65
NewMethod · 0.65
GetChatByIDMethod · 0.65
GetWorkspaceByIDMethod · 0.65
GetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected