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

Function TestWorkspaceFilter

coderd/workspaces_test.go:1998–2343  ·  view source on GitHub ↗

TestWorkspaceFilter creates a set of workspaces, users, and organizations to run various filters against for testing.

(t *testing.T)

Source from the content-addressed store, hash-verified

1996// TestWorkspaceFilter creates a set of workspaces, users, and organizations
1997// to run various filters against for testing.
1998func TestWorkspaceFilter(t *testing.T) {
1999 t.Parallel()
2000 // Manual tests still occur below, so this is safe to disable.
2001 t.Skip("This test is slow and flaky. See: https://github.com/coder/coder/issues/2854")
2002 // nolint:unused
2003 type coderUser struct {
2004 *codersdk.Client
2005 User codersdk.User
2006 Org codersdk.Organization
2007 }
2008
2009 client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
2010 first := coderdtest.CreateFirstUser(t, client)
2011
2012 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
2013 t.Cleanup(cancel)
2014
2015 users := make([]coderUser, 0)
2016 for i := 0; i < 10; i++ {
2017 userClient, user := coderdtest.CreateAnotherUser(t, client, first.OrganizationID, rbac.RoleOwner())
2018
2019 if i%3 == 0 {
2020 var err error
2021 user, err = client.UpdateUserProfile(ctx, user.ID.String(), codersdk.UpdateUserProfileRequest{
2022 Username: strings.ToUpper(user.Username),
2023 })
2024 require.NoError(t, err, "uppercase username")
2025 }
2026
2027 org, err := userClient.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
2028 Name: user.Username + "-org",
2029 })
2030 require.NoError(t, err, "create org")
2031
2032 users = append(users, coderUser{
2033 Client: userClient,
2034 User: user,
2035 Org: org,
2036 })
2037 }
2038
2039 type madeWorkspace struct {
2040 Owner codersdk.User
2041 Workspace codersdk.Workspace
2042 Template codersdk.Template
2043 }
2044
2045 availTemplates := make([]codersdk.Template, 0)
2046 allWorkspaces := make([]madeWorkspace, 0)
2047 upperTemplates := make([]string, 0)
2048
2049 // Create some random workspaces
2050 var count int
2051 for i, user := range users {
2052 version := coderdtest.CreateTemplateVersion(t, client, user.Org.ID, nil)
2053
2054 // Create a template & workspace in the user's org
2055 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleOwnerFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateWorkspaceFunction · 0.92
IntnFunction · 0.92
ContextFunction · 0.92
DeploymentValuesFunction · 0.92

Tested by

no test coverage detected