TestWriteFileReadFileJSON tests the format-aware file I/O round-trip.
(t *testing.T)
| 397 | |
| 398 | // TestWriteFileReadFileJSON tests the format-aware file I/O round-trip. |
| 399 | func 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. |
| 429 | func TestWriteFileAppendNDJSON(t *testing.T) { |
nothing calls this directly
no test coverage detected