TestPermissionCombinations tests various permission combinations
(t *testing.T)
| 417 | |
| 418 | // TestPermissionCombinations tests various permission combinations |
| 419 | func TestPermissionCombinations(t *testing.T) { |
| 420 | tests := []struct { |
| 421 | name string |
| 422 | permissions string |
| 423 | expectValid bool |
| 424 | description string |
| 425 | }{ |
| 426 | { |
| 427 | name: "multiple read permissions", |
| 428 | permissions: `permissions: |
| 429 | contents: read |
| 430 | issues: read |
| 431 | pull-requests: read`, |
| 432 | expectValid: true, |
| 433 | description: "multiple read permissions are valid", |
| 434 | }, |
| 435 | { |
| 436 | name: "mixed read and write permissions", |
| 437 | permissions: `permissions: |
| 438 | contents: read |
| 439 | issues: write |
| 440 | pull-requests: write`, |
| 441 | expectValid: true, |
| 442 | description: "mixing read and write is valid", |
| 443 | }, |
| 444 | { |
| 445 | name: "all scopes with none", |
| 446 | permissions: `permissions: |
| 447 | contents: none |
| 448 | issues: none |
| 449 | pull-requests: none`, |
| 450 | expectValid: true, |
| 451 | description: "all none is valid (explicit deny)", |
| 452 | }, |
| 453 | } |
| 454 | |
| 455 | for _, tt := range tests { |
| 456 | t.Run(tt.name, func(t *testing.T) { |
| 457 | parser := NewPermissionsParser(tt.permissions) |
| 458 | |
| 459 | if tt.expectValid { |
| 460 | if len(parser.parsedPerms) == 0 && !parser.isShorthand { |
| 461 | t.Errorf("%s: expected permissions to be parsed", tt.description) |
| 462 | } |
| 463 | } |
| 464 | }) |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | // TestPermissionsWhitespaceHandling tests whitespace handling in permissions |
| 469 | func TestPermissionsWhitespaceHandling(t *testing.T) { |
nothing calls this directly
no test coverage detected