(t *testing.T)
| 379 | } |
| 380 | |
| 381 | func TestFormatErrorChain(t *testing.T) { |
| 382 | tests := []struct { |
| 383 | name string |
| 384 | err error |
| 385 | expectedContains []string |
| 386 | expectMultiLine bool |
| 387 | }{ |
| 388 | { |
| 389 | name: "nil error", |
| 390 | err: nil, |
| 391 | expectedContains: []string{}, |
| 392 | expectMultiLine: false, |
| 393 | }, |
| 394 | { |
| 395 | name: "simple single error", |
| 396 | err: errors.New("file not found"), |
| 397 | expectedContains: []string{"✗", "file not found"}, |
| 398 | expectMultiLine: false, |
| 399 | }, |
| 400 | { |
| 401 | name: "two-level wrapped error", |
| 402 | err: fmt.Errorf("outer: %w", errors.New("inner cause")), |
| 403 | expectedContains: []string{"✗", "outer", "inner cause"}, |
| 404 | expectMultiLine: true, |
| 405 | }, |
| 406 | { |
| 407 | name: "three-level wrapped error chain", |
| 408 | err: fmt.Errorf("workflow not found: %w", |
| 409 | fmt.Errorf("failed to download: %w", |
| 410 | errors.New("HTTP 404: Not Found"))), |
| 411 | expectedContains: []string{"✗", "workflow not found", "failed to download", "HTTP 404: Not Found"}, |
| 412 | expectMultiLine: true, |
| 413 | }, |
| 414 | { |
| 415 | name: "multiline error from errors.Join", |
| 416 | err: errors.Join(errors.New("error one"), errors.New("error two")), |
| 417 | expectedContains: []string{"✗", "error one", "error two"}, |
| 418 | expectMultiLine: true, |
| 419 | }, |
| 420 | } |
| 421 | |
| 422 | for _, tt := range tests { |
| 423 | t.Run(tt.name, func(t *testing.T) { |
| 424 | result := FormatErrorChain(tt.err) |
| 425 | |
| 426 | for _, expected := range tt.expectedContains { |
| 427 | if !strings.Contains(result, expected) { |
| 428 | t.Errorf("FormatErrorChain() = %q, should contain %q", result, expected) |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | if tt.expectMultiLine && !strings.Contains(result, "\n") { |
| 433 | t.Errorf("FormatErrorChain() should produce multi-line output for wrapped/joined errors, got: %q", result) |
| 434 | } |
| 435 | |
| 436 | // Verify indentation: continuation lines should start with spaces, first line should not |
| 437 | if tt.expectMultiLine && tt.err != nil { |
| 438 | lines := strings.Split(result, "\n") |
nothing calls this directly
no test coverage detected