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

Function TestRoleByName

coderd/rbac/roles_internal_test.go:210–252  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

208}
209
210func TestRoleByName(t *testing.T) {
211 t.Parallel()
212
213 t.Run("BuiltIns", func(t *testing.T) {
214 t.Parallel()
215 testCases := []struct {
216 Role Role
217 }{
218 {Role: builtInRoles[owner](uuid.Nil)},
219 {Role: builtInRoles[member](uuid.Nil)},
220 {Role: builtInRoles[templateAdmin](uuid.Nil)},
221 {Role: builtInRoles[userAdmin](uuid.Nil)},
222 {Role: builtInRoles[auditor](uuid.Nil)},
223
224 {Role: builtInRoles[orgAdmin](uuid.New())},
225 {Role: builtInRoles[orgAdmin](uuid.New())},
226 {Role: builtInRoles[orgAdmin](uuid.New())},
227
228 {Role: builtInRoles[orgAuditor](uuid.New())},
229 {Role: builtInRoles[orgAuditor](uuid.New())},
230 {Role: builtInRoles[orgAuditor](uuid.New())},
231 }
232
233 for _, c := range testCases {
234 t.Run(c.Role.Identifier.String(), func(t *testing.T) {
235 role, err := RoleByName(c.Role.Identifier)
236 require.NoError(t, err, "role exists")
237 equalRoles(t, c.Role, role)
238 })
239 }
240 })
241
242 // nolint:paralleltest
243 t.Run("Errors", func(t *testing.T) {
244 var err error
245
246 _, err = RoleByName(RoleIdentifier{})
247 require.Error(t, err, "empty role")
248
249 _, err = RoleByName(RoleIdentifier{Name: orgMember})
250 require.Error(t, err, "expect orgID")
251 })
252}
253
254func TestDeduplicatePermissions(t *testing.T) {
255 t.Parallel()

Callers

nothing calls this directly

Calls 6

RoleByNameFunction · 0.85
equalRolesFunction · 0.85
RunMethod · 0.65
NewMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected