@@ -103,15 +103,15 @@ func TestSharingShare(t *testing.T) {
103
103
Username : toShareWithUser1 .Username ,
104
104
AvatarURL : toShareWithUser1 .AvatarURL ,
105
105
},
106
- Role : codersdk .WorkspaceRole ( "use" ) ,
106
+ Role : codersdk .WorkspaceRoleUse ,
107
107
})
108
108
assert .Contains (t , acl .Users , codersdk.WorkspaceUser {
109
109
MinimalUser : codersdk.MinimalUser {
110
110
ID : toShareWithUser2 .ID ,
111
111
Username : toShareWithUser2 .Username ,
112
112
AvatarURL : toShareWithUser2 .AvatarURL ,
113
113
},
114
- Role : codersdk .WorkspaceRole ( "use" ) ,
114
+ Role : codersdk .WorkspaceRoleUse ,
115
115
})
116
116
117
117
// Test that the users appeart in the output
@@ -126,43 +126,56 @@ func TestSharingShare(t *testing.T) {
126
126
}
127
127
}
128
128
129
- assert .True (t , found , fmt .Sprintf ("Expected to find username %s in output" , username ))
129
+ assert .True (t , found , fmt .Sprintf ("Expected to find the username %s in the command output: %s " , username , out . String () ))
130
130
}
131
131
})
132
132
133
- // t.Run("ShareWithUsers_Roles", func(t *testing.T) {
134
- // t.Parallel()
135
-
136
- // assert.True(t, false)
137
- // })
138
-
139
- // t.Run("ShareWithUsers+AdminRole", func(t *testing.T) {
140
- // t.Parallel()
141
-
142
- // assert.True(t, false)
143
- // })
144
-
145
- // t.Run("ShareWithGroups+Simple", func(t *testing.T) {
146
- // t.Parallel()
147
-
148
- // assert.True(t, false)
149
- // })
150
-
151
- // t.Run("ShareWithGroups+Mutliple", func(t *testing.T) {
152
- // t.Parallel()
133
+ t .Run ("ShareWithUsers_Roles" , func (t * testing.T ) {
134
+ t .Parallel ()
153
135
154
- // assert.True(t, false)
155
- // })
136
+ var (
137
+ client , db = coderdtest .NewWithDatabase (t , & coderdtest.Options {
138
+ DeploymentValues : dv ,
139
+ })
140
+ orgOwner = coderdtest .CreateFirstUser (t , client )
141
+ workspaceOwnerClient , workspaceOwner = coderdtest .CreateAnotherUser (t , client , orgOwner .OrganizationID , rbac .ScopedRoleOrgAuditor (orgOwner .OrganizationID ))
142
+ workspace = dbfake .WorkspaceBuild (t , db , database.WorkspaceTable {
143
+ OwnerID : workspaceOwner .ID ,
144
+ OrganizationID : orgOwner .OrganizationID ,
145
+ }).Do ().Workspace
146
+ _ , toShareWithUser = coderdtest .CreateAnotherUser (t , client , orgOwner .OrganizationID )
147
+ )
156
148
157
- // t.Run("ShareWithGroups+UseRole", func(t *testing.T) {
158
- // t.Parallel()
149
+ ctx := testutil .Context (t , testutil .WaitMedium )
150
+ var inv , root = clitest .New (t , "sharing" , "share" , workspace .Name ,
151
+ "--org" , orgOwner .OrganizationID .String (),
152
+ "--user" , fmt .Sprintf ("%s:admin" , toShareWithUser .Username ),
153
+ )
154
+ clitest .SetupConfig (t , workspaceOwnerClient , root )
159
155
160
- // assert.True(t, false)
161
- // })
156
+ out := bytes .NewBuffer (nil )
157
+ inv .Stdout = out
158
+ err := inv .WithContext (ctx ).Run ()
159
+ require .NoError (t , err )
162
160
163
- // t.Run("ShareWithGroups+AdminRole", func(t *testing.T) {
164
- // t.Parallel()
161
+ acl , err := workspaceOwnerClient .WorkspaceACL (inv .Context (), workspace .ID )
162
+ assert .NoError (t , err )
163
+ assert .Contains (t , acl .Users , codersdk.WorkspaceUser {
164
+ MinimalUser : codersdk.MinimalUser {
165
+ ID : toShareWithUser .ID ,
166
+ Username : toShareWithUser .Username ,
167
+ AvatarURL : toShareWithUser .AvatarURL ,
168
+ },
169
+ Role : codersdk .WorkspaceRoleAdmin ,
170
+ })
165
171
166
- // assert.True(t, false)
167
- // })
172
+ found := false
173
+ for _ , line := range strings .Split (out .String (), "\n " ) {
174
+ if strings .Contains (line , toShareWithUser .Username ) && strings .Contains (line , string (codersdk .WorkspaceRoleAdmin )) {
175
+ found = true
176
+ break
177
+ }
178
+ }
179
+ assert .True (t , found , fmt .Sprintf ("expected to find the username %s and role %s in the command: %s" , toShareWithUser .Username , codersdk .WorkspaceRoleAdmin , out .String ()))
180
+ })
168
181
}
0 commit comments