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

Function TestStrictDecodingJSON

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

Source from the content-addressed store, hash-verified

905}
906
907func TestStrictDecodingJSON(t *testing.T) {
908 validJSON := `{
909 "name": "subset_env",
910 "stdlib": {
911 "excludeFunctions": [
912 {
913 "name": "_+_",
914 "overloads": [
915 "add_bytes",
916 {
917 "id": "add_list",
918 "args": [
919 "list<~T>",
920 {
921 "typeName": "list",
922 "params": [
923 {
924 "typeName": "T",
925 "isTypeParam": true
926 }
927 ]
928 }
929 ],
930 "return": "list<~T>"
931 }
932 ]
933 }
934 ]
935 },
936 "contextVariable": {
937 "type": "google.expr.proto3.test.TestAllTypes"
938 },
939 "validators": [
940 {
941 "name": "cel.validator.comprehension_nesting_limit",
942 "config": {
943 "limit": 2
944 }
945 }
946 ]
947}`
948 if _, err := ConfigFromJSON([]byte(validJSON), StrictDecoding(true)); err != nil {
949 t.Fatalf("ConfigFromJSON(StrictDecoding(true)) = %v, want nil", err)
950 }
951
952 unknownFieldInputs := []struct {
953 name string
954 jsonIn string
955 wantErr string
956 }{
957 {
958 name: "unknown config field",
959 jsonIn: `{"name": "foo", "unknownField": "bar"}`,
960 wantErr: `unknown field "unknownField"`,
961 },
962 {
963 name: "unknown variable field",
964 jsonIn: `{"variables": [{"name": "x", "type": "int", "unknownVarField": 1}]}`,

Callers

nothing calls this directly

Calls 9

ConfigFromJSONFunction · 0.85
StrictDecodingFunction · 0.85
NewConfigFunction · 0.85
NewValidatorFunction · 0.85
ConfigToJSONFunction · 0.85
AddValidatorsMethod · 0.80
SetConfigMethod · 0.80
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected