(t *testing.T)
| 414 | } |
| 415 | |
| 416 | func TestConfigToJSON(t *testing.T) { |
| 417 | tcs := []struct { |
| 418 | name string |
| 419 | confIn *Config |
| 420 | jsonOut string |
| 421 | }{ |
| 422 | { |
| 423 | name: "string variable type", |
| 424 | confIn: NewConfig("foo").AddVariables( |
| 425 | NewVariable("foo", NewTypeDesc("int")), |
| 426 | ), |
| 427 | jsonOut: `{ |
| 428 | "name": "foo", |
| 429 | "variables": [ |
| 430 | { |
| 431 | "name": "foo", |
| 432 | "type": "int" |
| 433 | } |
| 434 | ] |
| 435 | }`, |
| 436 | }, |
| 437 | { |
| 438 | name: "extension version latest", |
| 439 | confIn: NewConfig("foo").AddExtensions( |
| 440 | NewExtension("optional", math.MaxUint32), |
| 441 | NewExtension("strings", 1), |
| 442 | ), |
| 443 | jsonOut: `{ |
| 444 | "name": "foo", |
| 445 | "extensions": [ |
| 446 | { |
| 447 | "name": "optional", |
| 448 | "version": "latest" |
| 449 | }, |
| 450 | { |
| 451 | "name": "strings", |
| 452 | "version": "1" |
| 453 | } |
| 454 | ] |
| 455 | }`, |
| 456 | }, |
| 457 | } |
| 458 | |
| 459 | for _, tc := range tcs { |
| 460 | t.Run(tc.name, func(t *testing.T) { |
| 461 | b, err := ConfigToJSON(tc.confIn) |
| 462 | if err != nil { |
| 463 | t.Fatalf("ConfigToJSON() = (err) %v", err) |
| 464 | } |
| 465 | if diff := cmp.Diff(tc.jsonOut, string(b)); diff != "" { |
| 466 | t.Errorf("ConfigToJSON() has diff (-want +got):\n%s", diff) |
| 467 | } |
| 468 | got, err := ConfigFromJSON(b) |
| 469 | if err != nil { |
| 470 | t.Fatalf("ConfigFromJSON() = (err) %v", err) |
| 471 | } |
| 472 | assertConfigEquals(t, got, tc.confIn) |
| 473 | }) |
nothing calls this directly
no test coverage detected