MCPcopy Index your code
hub / github.com/keploy/keploy / TestWriteFileAppendNDJSON

Function TestWriteFileAppendNDJSON

pkg/platform/yaml/codec_test.go:429–466  ·  view source on GitHub ↗

TestWriteFileAppendNDJSON tests appending multiple documents in JSON format.

(t *testing.T)

Source from the content-addressed store, hash-verified

427
428// TestWriteFileAppendNDJSON tests appending multiple documents in JSON format.
429func TestWriteFileAppendNDJSON(t *testing.T) {
430 ctx := context.Background()
431 logger := testLogger()
432
433 tempDir, err := os.MkdirTemp("", "appendfile_json_test")
434 if err != nil {
435 t.Fatal(err)
436 }
437 defer os.RemoveAll(tempDir)
438
439 doc1 := []byte(`{"name":"mock-0"}`)
440 doc2 := []byte(`{"name":"mock-1"}`)
441
442 if err := WriteFileF(ctx, logger, tempDir, "mocks", doc1, true, FormatJSON); err != nil {
443 t.Fatal(err)
444 }
445 if err := WriteFileF(ctx, logger, tempDir, "mocks", doc2, true, FormatJSON); err != nil {
446 t.Fatal(err)
447 }
448
449 data, err := ReadFileF(ctx, logger, tempDir, "mocks", FormatJSON)
450 if err != nil {
451 t.Fatal(err)
452 }
453
454 // Should be NDJSON: first doc, newline, second doc
455 lines := 0
456 for _, b := range data {
457 if b == '\n' {
458 lines++
459 }
460 }
461 // First write: just the data (empty file, no separator). Second write: \n + data.
462 // So we expect at least 1 newline separator between docs.
463 if lines < 1 {
464 t.Errorf("expected at least 1 newline in NDJSON, got content: %q", string(data))
465 }
466}
467
468// TestFileExistsF tests format-aware file existence check.
469func TestFileExistsF(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