add support for equality check.

This commit is contained in:
Jiahui Feng 2024-01-23 16:07:39 -08:00
parent 9bbdbc510e
commit df9620c9f6
2 changed files with 9 additions and 1 deletions

View File

@ -77,7 +77,10 @@ func (v *ObjectVal) ConvertToType(typeValue ref.Type) ref.Val {
// Equal returns true if the `other` value has the same type and content as the implementing struct. // Equal returns true if the `other` value has the same type and content as the implementing struct.
func (v *ObjectVal) Equal(other ref.Val) ref.Val { func (v *ObjectVal) Equal(other ref.Val) ref.Val {
return types.Bool(v == other) if rhs, ok := other.(*ObjectVal); ok {
return types.Bool(reflect.DeepEqual(v.fields, rhs.fields))
}
return types.Bool(false)
} }
// Type returns the TypeValue of the value. // Type returns the TypeValue of the value.

View File

@ -101,6 +101,11 @@ func TestTypeProvider(t *testing.T) {
}.intList.sum()`, }.intList.sum()`,
expectedValue: int64(6), expectedValue: int64(6),
}, },
{
name: "equality check",
expression: "Object{spec: Object.spec{replicas: 3}} == Object{spec: Object.spec{replicas: 1 + 2}}",
expectedValue: true,
},
} { } {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
_, option := mutation.NewTypeProviderAndEnvOption(&TypeResolver{}) _, option := mutation.NewTypeProviderAndEnvOption(&TypeResolver{})