MCPcopy
hub / github.com/keploy/keploy / TestWriteFileReadFileJSON

Function TestWriteFileReadFileJSON

pkg/platform/yaml/codec_test.go:399–426  ·  view source on GitHub ↗

TestWriteFileReadFileJSON tests the format-aware file I/O round-trip.

(t *testing.T)

Source from the content-addressed store, hash-verified

397
398// TestWriteFileReadFileJSON tests the format-aware file I/O round-trip.
399func TestWriteFileReadFileJSON(t *testing.T) {
400 ctx := context.Background()
401 logger := testLogger()
402
403 tempDir, err := os.MkdirTemp("", "writefile_json_test")
404 if err != nil {
405 t.Fatal(err)
406 }
407 defer os.RemoveAll(tempDir)
408
409 content := []byte(`{"hello":"world"}`)
410 if err := WriteFileF(ctx, logger, tempDir, "testfile", content, false, FormatJSON); err != nil {
411 t.Fatalf("WriteFileF: %v", err)
412 }
413
414 // Verify file has .json extension
415 if _, err := os.Stat(filepath.Join(tempDir, "testfile.json")); err != nil {
416 t.Fatalf("Expected testfile.json to exist: %v", err)
417 }
418
419 data, err := ReadFileF(ctx, logger, tempDir, "testfile", FormatJSON)
420 if err != nil {
421 t.Fatalf("ReadFileF: %v", err)
422 }
423 if string(data) != `{"hello":"world"}` {
424 t.Errorf("got %q", string(data))
425 }
426}
427
428// TestWriteFileAppendNDJSON tests appending multiple documents in JSON format.
429func TestWriteFileAppendNDJSON(t *testing.T) {

Callers

nothing calls this directly

Calls 3

WriteFileFFunction · 0.85
ReadFileFFunction · 0.85
testLoggerFunction · 0.70

Tested by

no test coverage detected