TestFileExistsF tests format-aware file existence check.
(t *testing.T)
| 467 | |
| 468 | // TestFileExistsF tests format-aware file existence check. |
| 469 | func TestFileExistsF(t *testing.T) { |
| 470 | tempDir, err := os.MkdirTemp("", "fileexists_test") |
| 471 | if err != nil { |
| 472 | t.Fatal(err) |
| 473 | } |
| 474 | defer os.RemoveAll(tempDir) |
| 475 | logger := testLogger() |
| 476 | |
| 477 | // Create a .json file |
| 478 | if err := os.WriteFile(filepath.Join(tempDir, "test.json"), []byte("{}"), 0644); err != nil { |
| 479 | t.Fatal(err) |
| 480 | } |
| 481 | |
| 482 | ctx := context.Background() |
| 483 | exists, err := FileExistsF(ctx, logger, tempDir, "test", FormatJSON) |
| 484 | if err != nil { |
| 485 | t.Fatal(err) |
| 486 | } |
| 487 | if !exists { |
| 488 | t.Error("expected test.json to exist") |
| 489 | } |
| 490 | |
| 491 | exists, err = FileExistsF(ctx, logger, tempDir, "test", FormatYAML) |
| 492 | if err != nil { |
| 493 | t.Fatal(err) |
| 494 | } |
| 495 | if exists { |
| 496 | t.Error("expected test.yaml to NOT exist") |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | // TestReadFileAnyPrefersPreferred verifies ReadFileAny picks the preferred |
| 501 | // format when both files exist. |
nothing calls this directly
no test coverage detected