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

Function TestMarshalGenericJSON

pkg/platform/yaml/codec_test.go:186–213  ·  view source on GitHub ↗

TestMarshalGenericJSON tests MarshalGeneric with a struct that has json tags.

(t *testing.T)

Source from the content-addressed store, hash-verified

184
185// TestMarshalGenericJSON tests MarshalGeneric with a struct that has json tags.
186func TestMarshalGenericJSON(t *testing.T) {
187 report := models.TestReport{
188 Version: models.V1Beta1,
189 Name: "test-set-0-report",
190 Status: "PASSED",
191 Success: 5,
192 Total: 5,
193 TestSet: "test-set-0",
194 }
195 data, err := MarshalGeneric(FormatJSON, &report)
196 if err != nil {
197 t.Fatalf("MarshalGeneric error: %v", err)
198 }
199 if !json.Valid(data) {
200 t.Fatalf("invalid JSON: %s", data)
201 }
202
203 var decoded models.TestReport
204 if err := UnmarshalGeneric(FormatJSON, data, &decoded); err != nil {
205 t.Fatalf("UnmarshalGeneric error: %v", err)
206 }
207 if decoded.Name != report.Name {
208 t.Errorf("name = %q, want %q", decoded.Name, report.Name)
209 }
210 if decoded.Success != 5 {
211 t.Errorf("success = %d, want 5", decoded.Success)
212 }
213}
214
215// TestMarshalGenericYAML tests MarshalGeneric roundtrip with YAML.
216func TestMarshalGenericYAML(t *testing.T) {

Callers

nothing calls this directly

Calls 3

MarshalGenericFunction · 0.85
UnmarshalGenericFunction · 0.85
ValidMethod · 0.80

Tested by

no test coverage detected