TestMarshalGenericJSON tests MarshalGeneric with a struct that has json tags.
(t *testing.T)
| 184 | |
| 185 | // TestMarshalGenericJSON tests MarshalGeneric with a struct that has json tags. |
| 186 | func 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. |
| 216 | func TestMarshalGenericYAML(t *testing.T) { |
nothing calls this directly
no test coverage detected