TestErrorCollectorFormattedError tests the FormattedError method
(t *testing.T)
| 208 | |
| 209 | // TestErrorCollectorFormattedError tests the FormattedError method |
| 210 | func TestErrorCollectorFormattedError(t *testing.T) { |
| 211 | tests := []struct { |
| 212 | name string |
| 213 | errors []error |
| 214 | category string |
| 215 | expectError bool |
| 216 | shouldContain []string |
| 217 | }{ |
| 218 | { |
| 219 | name: "no errors", |
| 220 | errors: []error{}, |
| 221 | category: "validation", |
| 222 | expectError: false, |
| 223 | }, |
| 224 | { |
| 225 | name: "single error (no formatting)", |
| 226 | errors: []error{errors.New("single error")}, |
| 227 | category: "validation", |
| 228 | expectError: true, |
| 229 | shouldContain: []string{"single error"}, |
| 230 | }, |
| 231 | { |
| 232 | name: "multiple errors with formatted header", |
| 233 | errors: []error{errors.New("error 1"), errors.New("error 2"), errors.New("error 3")}, |
| 234 | category: "validation", |
| 235 | expectError: true, |
| 236 | shouldContain: []string{ |
| 237 | "Found 3 validation errors:", |
| 238 | "error 1", |
| 239 | "error 2", |
| 240 | "error 3", |
| 241 | }, |
| 242 | }, |
| 243 | { |
| 244 | name: "errors with newlines preserved", |
| 245 | errors: []error{errors.New("error with\nmultiple\nlines"), errors.New("simple error")}, |
| 246 | category: "test", |
| 247 | expectError: true, |
| 248 | shouldContain: []string{ |
| 249 | "Found 2 test errors:", |
| 250 | "error with", |
| 251 | "multiple", |
| 252 | "lines", |
| 253 | "simple error", |
| 254 | }, |
| 255 | }, |
| 256 | } |
| 257 | |
| 258 | for _, tt := range tests { |
| 259 | t.Run(tt.name, func(t *testing.T) { |
| 260 | collector := NewErrorCollector(false) |
| 261 | |
| 262 | // Add all errors |
| 263 | for _, err := range tt.errors { |
| 264 | _ = collector.Add(err) |
| 265 | } |
| 266 | |
| 267 | // Get the formatted error |
nothing calls this directly
no test coverage detected