MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestConfigToJSON

Function TestConfigToJSON

common/env/io_test.go:416–479  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

414}
415
416func 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 })

Callers

nothing calls this directly

Calls 10

MarshalJSONMethod · 0.95
NewConfigFunction · 0.85
NewTypeDescFunction · 0.85
ConfigToJSONFunction · 0.85
ConfigFromJSONFunction · 0.85
assertConfigEqualsFunction · 0.85
AddExtensionsMethod · 0.80
NewVariableFunction · 0.70
NewExtensionFunction · 0.70
AddVariablesMethod · 0.45

Tested by

no test coverage detected