(t *testing.T)
| 58 | } |
| 59 | |
| 60 | func TestLoadPolicyPlugins(t *testing.T) { |
| 61 | tests := []struct { |
| 62 | name string |
| 63 | files map[string]string // File name to content mapping |
| 64 | expectedCount int |
| 65 | expectErrorCount int |
| 66 | expectError bool |
| 67 | }{ |
| 68 | { |
| 69 | name: "Valid plugin config", |
| 70 | files: map[string]string{ |
| 71 | "valid_policy.yml": ` |
| 72 | name: Example Policy Command |
| 73 | enforce_providers: true |
| 74 | command: /usr/bin/local/opk/policy-cmd`, |
| 75 | }, |
| 76 | expectedCount: 1, |
| 77 | expectErrorCount: 0, |
| 78 | }, |
| 79 | { |
| 80 | name: "Invalid plugin configs (missing required fields)", |
| 81 | files: map[string]string{ |
| 82 | "invalid_policy1.yml": ` |
| 83 | name: Invalid Policy Command |
| 84 | command: |
| 85 | enforce_providers: true |
| 86 | `, |
| 87 | "invalid_policy2.yml": ` |
| 88 | name: |
| 89 | command: |
| 90 | enforce_providers: true |
| 91 | `, |
| 92 | }, |
| 93 | expectedCount: 2, |
| 94 | expectErrorCount: 2, |
| 95 | }, |
| 96 | { |
| 97 | name: "Mixed valid and invalid plugin config", |
| 98 | files: map[string]string{ |
| 99 | "valid_policy.yml": ` |
| 100 | name: Example Policy Command |
| 101 | enforce_providers: true |
| 102 | command: /usr/bin/local/opk/policy-cmd |
| 103 | `, |
| 104 | "invalid_policy.yml": ` |
| 105 | name: Invalid Policy Command |
| 106 | enforce_providers: true |
| 107 | invalid_field: true |
| 108 | `, |
| 109 | }, |
| 110 | expectedCount: 2, |
| 111 | expectErrorCount: 1, |
| 112 | }, |
| 113 | { |
| 114 | name: "Corrupt YAML file", |
| 115 | files: map[string]string{ |
| 116 | "corrupt_policy.yml": `{`, |
| 117 | }, |
nothing calls this directly
no test coverage detected