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

Function TestChangeSet

coderd/rbac/roles_test.go:1418–1473  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1416}
1417
1418func TestChangeSet(t *testing.T) {
1419 t.Parallel()
1420 testCases := []struct {
1421 Name string
1422 From []string
1423 To []string
1424 ExpAdd []string
1425 ExpRemove []string
1426 }{
1427 {
1428 Name: "Empty",
1429 },
1430 {
1431 Name: "Same",
1432 From: []string{"a", "b", "c"},
1433 To: []string{"a", "b", "c"},
1434 ExpAdd: []string{},
1435 ExpRemove: []string{},
1436 },
1437 {
1438 Name: "AllRemoved",
1439 From: []string{"a", "b", "c"},
1440 ExpRemove: []string{"a", "b", "c"},
1441 },
1442 {
1443 Name: "AllAdded",
1444 To: []string{"a", "b", "c"},
1445 ExpAdd: []string{"a", "b", "c"},
1446 },
1447 {
1448 Name: "AddAndRemove",
1449 From: []string{"a", "b", "c"},
1450 To: []string{"a", "b", "d", "e"},
1451 ExpAdd: []string{"d", "e"},
1452 ExpRemove: []string{"c"},
1453 },
1454 }
1455
1456 convert := func(s []string) rbac.RoleIdentifiers {
1457 tmp := make([]rbac.RoleIdentifier, 0, len(s))
1458 for _, e := range s {
1459 tmp = append(tmp, rbac.RoleIdentifier{Name: e})
1460 }
1461 return tmp
1462 }
1463
1464 for _, c := range testCases {
1465 t.Run(c.Name, func(t *testing.T) {
1466 t.Parallel()
1467
1468 add, remove := rbac.ChangeRoleSet(convert(c.From), convert(c.To))
1469 require.ElementsMatch(t, convert(c.ExpAdd), add, "expect added")
1470 require.ElementsMatch(t, convert(c.ExpRemove), remove, "expect removed")
1471 })
1472 }
1473}

Callers

nothing calls this directly

Calls 3

ChangeRoleSetFunction · 0.92
convertFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected