(t *testing.T)
| 180 | } |
| 181 | |
| 182 | func Test_ReportSummary(t *testing.T) { |
| 183 | tests := []struct { |
| 184 | name string |
| 185 | input []Input |
| 186 | want summary |
| 187 | }{ |
| 188 | { |
| 189 | name: "testing one violation and warning", |
| 190 | input: []Input{{ |
| 191 | FilePath: "/path/to/file1.yaml", |
| 192 | Violations: []evaluator.Result{ |
| 193 | { |
| 194 | Message: "short report", |
| 195 | Metadata: map[string]interface{}{ |
| 196 | "code": "short_name", |
| 197 | }, |
| 198 | }, |
| 199 | }, |
| 200 | Warnings: []evaluator.Result{ |
| 201 | { |
| 202 | Message: "short report", |
| 203 | Metadata: map[string]interface{}{ |
| 204 | "code": "short_name", |
| 205 | }, |
| 206 | }, |
| 207 | }, |
| 208 | Success: false, |
| 209 | }}, |
| 210 | want: summary{ |
| 211 | FilePaths: []inputSummary{ |
| 212 | { |
| 213 | FilePath: "/path/to/file1.yaml", |
| 214 | Violations: map[string][]string{ |
| 215 | "short_name": {"short report"}, |
| 216 | }, |
| 217 | Warnings: map[string][]string{ |
| 218 | "short_name": {"short report"}, |
| 219 | }, |
| 220 | Successes: map[string][]string{}, |
| 221 | TotalViolations: 1, |
| 222 | TotalSuccesses: 0, |
| 223 | TotalWarnings: 1, |
| 224 | Success: false, |
| 225 | }, |
| 226 | }, |
| 227 | Success: false, |
| 228 | }, |
| 229 | }, |
| 230 | } |
| 231 | |
| 232 | for _, tc := range tests { |
| 233 | t.Run(fmt.Sprintf("NewReport=%s", tc.name), func(t *testing.T) { |
| 234 | ctx := context.Background() |
| 235 | report, err := NewReport(tc.input, createTestPolicy(t, ctx), nil, false, true, true) |
| 236 | // report, err := NewReport(tc.snapshot, []Component{tc.input}, createTestPolicy(t, ctx), nil, nil) |
| 237 | assert.NoError(t, err) |
| 238 | fmt.Println("\n\nExpected:\n", tc.want, "\n\nActual:\n", report.toSummary()) |
| 239 | assert.Equal(t, tc.want, report.toSummary()) |
nothing calls this directly
no test coverage detected