TestFileExistsAnyDetection verifies FileExistsAny reports the correct detected format regardless of what the caller prefers.
(t *testing.T)
| 595 | // TestFileExistsAnyDetection verifies FileExistsAny reports the correct |
| 596 | // detected format regardless of what the caller prefers. |
| 597 | func TestFileExistsAnyDetection(t *testing.T) { |
| 598 | ctx := context.Background() |
| 599 | logger := testLogger() |
| 600 | |
| 601 | tempDir, err := os.MkdirTemp("", "fileexists_any_test") |
| 602 | if err != nil { |
| 603 | t.Fatal(err) |
| 604 | } |
| 605 | defer os.RemoveAll(tempDir) |
| 606 | |
| 607 | if err := os.WriteFile(filepath.Join(tempDir, "m.yaml"), []byte(""), 0644); err != nil { |
| 608 | t.Fatal(err) |
| 609 | } |
| 610 | |
| 611 | // Caller prefers JSON; only YAML exists. Must still report exists=true |
| 612 | // and detected=FormatYAML so writer can preserve the file's format. |
| 613 | exists, detected, err := FileExistsAny(ctx, logger, tempDir, "m", FormatJSON) |
| 614 | if err != nil { |
| 615 | t.Fatal(err) |
| 616 | } |
| 617 | if !exists { |
| 618 | t.Fatal("expected exists=true") |
| 619 | } |
| 620 | if detected != FormatYAML { |
| 621 | t.Errorf("detected = %v, want FormatYAML", detected) |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | // TestNewMockReaderAnyFallsBack verifies NewMockReaderAny opens a YAML |
| 626 | // mocks file even when the caller prefers JSON (and vice versa). |
nothing calls this directly
no test coverage detected