MCPcopy
hub / github.com/keploy/keploy / TestMarshalDocJSON

Function TestMarshalDocJSON

pkg/platform/yaml/codec_test.go:81–107  ·  view source on GitHub ↗

TestMarshalDocJSON verifies MarshalDoc produces valid JSON.

(t *testing.T)

Source from the content-addressed store, hash-verified

79
80// TestMarshalDocJSON verifies MarshalDoc produces valid JSON.
81func TestMarshalDocJSON(t *testing.T) {
82 doc := buildHTTPDoc()
83 data, err := MarshalDoc(FormatJSON, doc)
84 if err != nil {
85 t.Fatalf("MarshalDoc(JSON) error: %v", err)
86 }
87 if !json.Valid(data) {
88 t.Fatalf("MarshalDoc(JSON) produced invalid JSON: %s", data)
89 }
90
91 var parsed NetworkTrafficDocJSON
92 if err := json.Unmarshal(data, &parsed); err != nil {
93 t.Fatalf("Failed to re-parse JSON doc: %v", err)
94 }
95 if parsed.Version != models.V1Beta1 {
96 t.Errorf("version = %q, want %q", parsed.Version, models.V1Beta1)
97 }
98 if parsed.Kind != models.HTTP {
99 t.Errorf("kind = %q, want %q", parsed.Kind, models.HTTP)
100 }
101 if parsed.Name != "test-1" {
102 t.Errorf("name = %q, want %q", parsed.Name, "test-1")
103 }
104 if len(parsed.Spec) == 0 {
105 t.Error("spec is empty")
106 }
107}
108
109// TestMarshalDocYAML verifies MarshalDoc still works for YAML.
110func TestMarshalDocYAML(t *testing.T) {

Callers

nothing calls this directly

Calls 5

buildHTTPDocFunction · 0.85
MarshalDocFunction · 0.85
ValidMethod · 0.80
UnmarshalMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected