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

Function TestWorkspaceFilterManual

coderd/workspaces_test.go:2346–3133  ·  view source on GitHub ↗

TestWorkspaceFilterManual runs some specific setups with basic checks.

(t *testing.T)

Source from the content-addressed store, hash-verified

2344
2345// TestWorkspaceFilterManual runs some specific setups with basic checks.
2346func TestWorkspaceFilterManual(t *testing.T) {
2347 t.Parallel()
2348
2349 expectIDs := func(t *testing.T, exp []codersdk.Workspace, got []codersdk.Workspace) {
2350 t.Helper()
2351 expIDs := make([]uuid.UUID, 0, len(exp))
2352 for _, e := range exp {
2353 expIDs = append(expIDs, e.ID)
2354 }
2355
2356 gotIDs := make([]uuid.UUID, 0, len(got))
2357 for _, g := range got {
2358 gotIDs = append(gotIDs, g.ID)
2359 }
2360 require.ElementsMatchf(t, expIDs, gotIDs, "expected IDs")
2361 }
2362
2363 t.Run("Name", func(t *testing.T) {
2364 t.Parallel()
2365 client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
2366 user := coderdtest.CreateFirstUser(t, client)
2367 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
2368 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
2369 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
2370 workspace := coderdtest.CreateWorkspace(t, client, template.ID)
2371
2372 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
2373 defer cancel()
2374
2375 // full match
2376 res, err := client.Workspaces(ctx, codersdk.WorkspaceFilter{
2377 Name: workspace.Name,
2378 })
2379 require.NoError(t, err)
2380 require.Len(t, res.Workspaces, 1, workspace.Name)
2381 require.Equal(t, workspace.ID, res.Workspaces[0].ID)
2382
2383 // partial match
2384 res, err = client.Workspaces(ctx, codersdk.WorkspaceFilter{
2385 Name: workspace.Name[1 : len(workspace.Name)-2],
2386 })
2387 require.NoError(t, err)
2388 require.Len(t, res.Workspaces, 1)
2389 require.Equal(t, workspace.ID, res.Workspaces[0].ID)
2390
2391 // no match
2392 res, err = client.Workspaces(ctx, codersdk.WorkspaceFilter{
2393 Name: "$$$$",
2394 })
2395 require.NoError(t, err)
2396 require.Len(t, res.Workspaces, 0)
2397 })
2398 t.Run("Owner", func(t *testing.T) {
2399 t.Parallel()
2400 client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
2401 user := coderdtest.CreateFirstUser(t, client)
2402 otherUser, _ := coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleOwner())
2403 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateWorkspaceFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleOwnerFunction · 0.92
CreateWorkspaceBuildFunction · 0.92
ProvisionGraphWithAgentFunction · 0.92
NewFunction · 0.92

Tested by

no test coverage detected