Better handling of unresolved (type any) values

This commit is contained in:
Denis Arh
2022-02-25 16:13:39 +01:00
parent 0f6e712487
commit c32687e061
2 changed files with 16 additions and 2 deletions
+1 -1
View File
@@ -203,7 +203,7 @@ func (t *Unresolved) Assign(interface{}) (err error) {
}
func CastToAny(val interface{}) (interface{}, error) {
return val, nil
return UntypedValue(val), nil
}
func CastToArray(val interface{}) (out []TypedValue, err error) {
+15 -1
View File
@@ -2,8 +2,9 @@ package expr
import (
"encoding/json"
"github.com/stretchr/testify/require"
"testing"
"github.com/stretchr/testify/require"
)
// extract typed-value
@@ -282,6 +283,19 @@ func TestVars_Omit(t *testing.T) {
req.Equal(expected, out)
}
func TestVarsTypeResolving(t *testing.T) {
var (
req = require.New(t)
v = &Vars{}
)
req.NoError(v.Set("unr", &Unresolved{value: "wrapped any", typ: "Any"}))
req.NoError(v.Set("any", &Any{value: "raw any"}))
req.NoError(v.ResolveTypes(func(typ string) Type { return Any{} }))
req.Equal("wrapped any", v.value["unr"].Get())
req.Equal("raw any", v.value["any"].Get())
}
func TestVars_UnmarshalJSON(t *testing.T) {
cases := []struct {
name string