@@ -13,6 +13,7 @@ import (
1313 "github.com/coder/coder/v2/coderd/coderdtest"
1414 "github.com/coder/coder/v2/coderd/database"
1515 "github.com/coder/coder/v2/coderd/database/dbfake"
16+ "github.com/coder/coder/v2/coderd/rbac"
1617 "github.com/coder/coder/v2/codersdk"
1718 "github.com/coder/coder/v2/pty/ptytest"
1819 "github.com/coder/coder/v2/testutil"
@@ -100,4 +101,49 @@ func TestList(t *testing.T) {
100101
101102 require .Len (t , stderr .Bytes (), 0 )
102103 })
104+
105+ t .Run ("SharedWorkspaces" , func (t * testing.T ) {
106+ t .Parallel ()
107+
108+ var (
109+ client , db = coderdtest .NewWithDatabase (t , & coderdtest.Options {
110+ DeploymentValues : coderdtest .DeploymentValues (t , func (dv * codersdk.DeploymentValues ) {
111+ dv .Experiments = []string {string (codersdk .ExperimentWorkspaceSharing )}
112+ }),
113+ })
114+ orgOwner = coderdtest .CreateFirstUser (t , client )
115+ memberClient , member = coderdtest .CreateAnotherUser (t , client , orgOwner .OrganizationID , rbac .ScopedRoleOrgAuditor (orgOwner .OrganizationID ))
116+ sharedWorkspace = dbfake .WorkspaceBuild (t , db , database.WorkspaceTable {
117+ Name : "wibble" ,
118+ OwnerID : orgOwner .UserID ,
119+ OrganizationID : orgOwner .OrganizationID ,
120+ }).Do ().Workspace
121+ _ = dbfake .WorkspaceBuild (t , db , database.WorkspaceTable {
122+ Name : "wobble" ,
123+ OwnerID : orgOwner .UserID ,
124+ OrganizationID : orgOwner .OrganizationID ,
125+ }).Do ().Workspace
126+ )
127+
128+ ctx := testutil .Context (t , testutil .WaitMedium )
129+
130+ client .UpdateWorkspaceACL (ctx , sharedWorkspace .ID , codersdk.UpdateWorkspaceACL {
131+ UserRoles : map [string ]codersdk.WorkspaceRole {
132+ member .ID .String (): codersdk .WorkspaceRoleUse ,
133+ },
134+ })
135+
136+ inv , root := clitest .New (t , "list" , "--shared-with-me" , "--output=json" )
137+ clitest .SetupConfig (t , memberClient , root )
138+
139+ stdout := new (bytes.Buffer )
140+ inv .Stdout = stdout
141+ err := inv .WithContext (ctx ).Run ()
142+ require .NoError (t , err )
143+
144+ var workspaces []codersdk.Workspace
145+ require .NoError (t , json .Unmarshal (stdout .Bytes (), & workspaces ))
146+ require .Len (t , workspaces , 1 )
147+ require .Equal (t , sharedWorkspace .ID , workspaces [0 ].ID )
148+ })
103149}
0 commit comments