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

Function TestPermissionsEqual

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

Source from the content-addressed store, hash-verified

273}
274
275func TestPermissionsEqual(t *testing.T) {
276 t.Parallel()
277
278 a := []Permission{
279 {ResourceType: ResourceWorkspace.Type, Action: policy.ActionRead},
280 {ResourceType: ResourceTemplate.Type, Action: policy.ActionUpdate},
281 {ResourceType: ResourceWorkspace.Type, Action: policy.ActionShare, Negate: true},
282 }
283
284 t.Run("Order", func(t *testing.T) {
285 t.Parallel()
286
287 b := []Permission{
288 a[2],
289 a[0],
290 a[1],
291 }
292 require.True(t, PermissionsEqual(a, b))
293 })
294
295 t.Run("SubsetAndSuperset", func(t *testing.T) {
296 t.Parallel()
297
298 require.False(t, PermissionsEqual(a, a[:2]))
299
300 b := append(slices.Clone(a), Permission{ResourceType: ResourceWorkspace.Type, Action: policy.ActionUpdate})
301 require.False(t, PermissionsEqual(a, b))
302 })
303
304 t.Run("Negate", func(t *testing.T) {
305 t.Parallel()
306
307 b := slices.Clone(a)
308 b[0] = Permission{
309 ResourceType: ResourceWorkspace.Type, Action: policy.ActionRead, Negate: true,
310 }
311 require.False(t, PermissionsEqual(a, b))
312 })
313
314 t.Run("Duplicates", func(t *testing.T) {
315 t.Parallel()
316
317 b := append(slices.Clone(a), a[0])
318 require.True(t, PermissionsEqual(a, b), "equal sets with duplicates should compare equal even without pre-deduplication")
319 })
320
321 t.Run("NilEmpty", func(t *testing.T) {
322 t.Parallel()
323
324 var nilSlice []Permission
325 emptySlice := []Permission{}
326 require.True(t, PermissionsEqual(nilSlice, emptySlice))
327 require.True(t, PermissionsEqual(emptySlice, nilSlice))
328 })
329}
330
331// equalRoles compares 2 roles for equality.
332func equalRoles(t *testing.T, a, b Role) {

Callers

nothing calls this directly

Calls 3

PermissionsEqualFunction · 0.85
RunMethod · 0.65
CloneMethod · 0.45

Tested by

no test coverage detected