TestReadNextDocJSONReturnsRawMessageSpec verifies that on a JSON mocks file, ReadNextDocJSON returns a NetworkTrafficDocJSON whose Spec is still json.RawMessage — i.e. we've bypassed the yaml.Node bridge entirely on the JSON read hot path.
(t *testing.T)
| 705 | // json.RawMessage — i.e. we've bypassed the yaml.Node bridge entirely on |
| 706 | // the JSON read hot path. |
| 707 | func TestReadNextDocJSONReturnsRawMessageSpec(t *testing.T) { |
| 708 | ctx := context.Background() |
| 709 | logger := testLogger() |
| 710 | |
| 711 | tempDir, err := os.MkdirTemp("", "mockreader_json_native_test") |
| 712 | if err != nil { |
| 713 | t.Fatal(err) |
| 714 | } |
| 715 | defer os.RemoveAll(tempDir) |
| 716 | |
| 717 | // Build two docs and write as NDJSON via the JSON write-side helper. |
| 718 | doc := buildHTTPDoc() |
| 719 | doc.Name = "mock-json-native" |
| 720 | line, err := MarshalDoc(FormatJSON, doc) |
| 721 | if err != nil { |
| 722 | t.Fatal(err) |
| 723 | } |
| 724 | content := append(line, '\n') |
| 725 | if err := os.WriteFile(filepath.Join(tempDir, "mocks.json"), content, 0644); err != nil { |
| 726 | t.Fatal(err) |
| 727 | } |
| 728 | |
| 729 | reader, err := NewMockReaderF(ctx, logger, tempDir, "mocks", FormatJSON) |
| 730 | if err != nil { |
| 731 | t.Fatal(err) |
| 732 | } |
| 733 | defer reader.Close() |
| 734 | |
| 735 | jd, err := reader.ReadNextDocJSON() |
| 736 | if err != nil { |
| 737 | t.Fatalf("ReadNextDocJSON: %v", err) |
| 738 | } |
| 739 | if jd.Name != "mock-json-native" { |
| 740 | t.Errorf("name = %q", jd.Name) |
| 741 | } |
| 742 | if len(jd.Spec) == 0 { |
| 743 | t.Fatalf("expected Spec to carry a json.RawMessage body, got empty") |
| 744 | } |
| 745 | if !json.Valid(jd.Spec) { |
| 746 | t.Errorf("Spec is not valid JSON: %s", jd.Spec) |
| 747 | } |
| 748 | if _, err := reader.ReadNextDocJSON(); err != io.EOF { |
| 749 | t.Errorf("expected EOF, got %v", err) |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | // TestReadNextDocJSONRejectsYAMLFormat verifies that ReadNextDocJSON is a |
| 754 | // programming-error guard — it must error when called on a YAML reader so |
nothing calls this directly
no test coverage detected