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

Function TestStrictDecodingYAML

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

Source from the content-addressed store, hash-verified

779}
780
781func TestStrictDecodingYAML(t *testing.T) {
782 validInputs := []struct {
783 name string
784 yamlIn string
785 }{
786 {
787 name: "empty",
788 yamlIn: "",
789 },
790 {
791 name: "shorthand and structured fields",
792 yamlIn: `name: subset_env
793context_variable:
794 type: google.expr.proto3.test.TestAllTypes
795stdlib:
796 exclude_functions:
797 - name: "_+_"
798 overloads:
799 - add_bytes
800 - id: add_list
801variables:
802 - name: x
803 type: list<int>
804 - name: y
805 type:
806 type_name: list
807 params:
808 - type_name: string
809validators:
810 - name: cel.validator.comprehension_nesting_limit
811 config:
812 limit: 2
813`,
814 },
815 }
816
817 for _, tc := range validInputs {
818 t.Run("valid/"+tc.name, func(t *testing.T) {
819 if _, err := ConfigFromYAML([]byte(tc.yamlIn), StrictDecoding(true)); err != nil {
820 t.Fatalf("ConfigFromYAML(StrictDecoding(true)) = %v, want nil", err)
821 }
822 })
823 }
824
825 unknownFieldInputs := []struct {
826 name string
827 yamlIn string
828 wantErr string
829 }{
830 {
831 name: "unknown config field",
832 yamlIn: "name: foo\nunknown_field: bar\n",
833 wantErr: "field unknown_field not found",
834 },
835 {
836 name: "unknown variable field",
837 yamlIn: `variables:
838 - name: x

Callers

nothing calls this directly

Calls 4

ConfigFromYAMLFunction · 0.85
StrictDecodingFunction · 0.85
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected