(t *testing.T)
| 1416 | } |
| 1417 | |
| 1418 | func 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 | } |
nothing calls this directly
no test coverage detected