TestValidateStrictModeEdgeCases tests edge cases for the validateStrictMode function
(t *testing.T)
| 506 | |
| 507 | // TestValidateStrictModeEdgeCases tests edge cases for the validateStrictMode function |
| 508 | func TestValidateStrictModeEdgeCases(t *testing.T) { |
| 509 | tests := []struct { |
| 510 | name string |
| 511 | frontmatter map[string]any |
| 512 | networkPermissions *NetworkPermissions |
| 513 | expectError bool |
| 514 | errorMsg string |
| 515 | }{ |
| 516 | { |
| 517 | name: "empty frontmatter with valid network", |
| 518 | frontmatter: map[string]any{}, |
| 519 | networkPermissions: &NetworkPermissions{ |
| 520 | Allowed: []string{"api.example.com"}, |
| 521 | }, |
| 522 | expectError: false, |
| 523 | }, |
| 524 | { |
| 525 | name: "nil frontmatter map is handled", |
| 526 | frontmatter: nil, |
| 527 | networkPermissions: &NetworkPermissions{ |
| 528 | Allowed: []string{"api.example.com"}, |
| 529 | }, |
| 530 | expectError: false, |
| 531 | }, |
| 532 | { |
| 533 | name: "invalid permissions type is handled gracefully", |
| 534 | frontmatter: map[string]any{ |
| 535 | "on": "push", |
| 536 | "permissions": "invalid-string-value", |
| 537 | }, |
| 538 | networkPermissions: &NetworkPermissions{ |
| 539 | Allowed: []string{"api.example.com"}, |
| 540 | }, |
| 541 | expectError: false, |
| 542 | }, |
| 543 | { |
| 544 | name: "permissions as array is handled gracefully", |
| 545 | frontmatter: map[string]any{ |
| 546 | "on": "push", |
| 547 | "permissions": []string{"contents:read"}, |
| 548 | }, |
| 549 | networkPermissions: &NetworkPermissions{ |
| 550 | Allowed: []string{"api.example.com"}, |
| 551 | }, |
| 552 | expectError: false, |
| 553 | }, |
| 554 | } |
| 555 | |
| 556 | for _, tt := range tests { |
| 557 | t.Run(tt.name, func(t *testing.T) { |
| 558 | compiler := NewCompiler() |
| 559 | compiler.SetStrictMode(true) |
| 560 | err := compiler.validateStrictMode(tt.frontmatter, tt.networkPermissions) |
| 561 | |
| 562 | if tt.expectError && err == nil { |
| 563 | t.Error("Expected validation to fail but it succeeded") |
| 564 | } else if !tt.expectError && err != nil { |
| 565 | t.Errorf("Expected validation to succeed but it failed: %v", err) |
nothing calls this directly
no test coverage detected