MCPcopy
hub / github.com/keploy/keploy / TestFileExistsAnyDetection

Function TestFileExistsAnyDetection

pkg/platform/yaml/codec_test.go:597–623  ·  view source on GitHub ↗

TestFileExistsAnyDetection verifies FileExistsAny reports the correct detected format regardless of what the caller prefers.

(t *testing.T)

Source from the content-addressed store, hash-verified

595// TestFileExistsAnyDetection verifies FileExistsAny reports the correct
596// detected format regardless of what the caller prefers.
597func 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).

Callers

nothing calls this directly

Calls 2

FileExistsAnyFunction · 0.85
testLoggerFunction · 0.70

Tested by

no test coverage detected