TestReadFileAnyFallsBack verifies ReadFileAny falls back to the other format when the preferred one is missing — this is the backward-compat path for replay after a StorageFormat switch.
(t *testing.T)
| 545 | // format when the preferred one is missing — this is the backward-compat |
| 546 | // path for replay after a StorageFormat switch. |
| 547 | func TestReadFileAnyFallsBack(t *testing.T) { |
| 548 | ctx := context.Background() |
| 549 | logger := testLogger() |
| 550 | |
| 551 | tempDir, err := os.MkdirTemp("", "readfile_any_fallback_test") |
| 552 | if err != nil { |
| 553 | t.Fatal(err) |
| 554 | } |
| 555 | defer os.RemoveAll(tempDir) |
| 556 | |
| 557 | // Only a .yaml file exists — caller prefers JSON but must get YAML back. |
| 558 | if err := os.WriteFile(filepath.Join(tempDir, "legacy.yaml"), []byte("hello: world"), 0644); err != nil { |
| 559 | t.Fatal(err) |
| 560 | } |
| 561 | |
| 562 | data, detected, err := ReadFileAny(ctx, logger, tempDir, "legacy", FormatJSON) |
| 563 | if err != nil { |
| 564 | t.Fatalf("expected fallback, got err: %v", err) |
| 565 | } |
| 566 | if detected != FormatYAML { |
| 567 | t.Errorf("detected = %v, want FormatYAML (fallback)", detected) |
| 568 | } |
| 569 | if string(data) != "hello: world" { |
| 570 | t.Errorf("data = %q", data) |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | // TestReadFileAnyMissingBoth verifies ReadFileAny returns fs.ErrNotExist |
| 575 | // when neither format's file is present. |
nothing calls this directly
no test coverage detected