From 973dd7f7ef3a26e46ed6c3353eb381e544d27b7b Mon Sep 17 00:00:00 2001 From: Alex Savchuk Date: Fri, 3 Mar 2023 11:16:33 +0300 Subject: [PATCH] fix: compare properties of Invalid types (#1645) * fix: compare properties of Invalid types fix: compare properties of Invalid types #1643 * fix linter problem * Fix review comment --- pkg/exprparser/interpreter.go | 10 +++++++++- pkg/exprparser/interpreter_test.go | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/exprparser/interpreter.go b/pkg/exprparser/interpreter.go index ea91271..ef3e8e1 100644 --- a/pkg/exprparser/interpreter.go +++ b/pkg/exprparser/interpreter.go @@ -372,8 +372,16 @@ func (impl *interperterImpl) compareValues(leftValue reflect.Value, rightValue r return impl.compareNumber(leftValue.Float(), rightValue.Float(), kind) + case reflect.Invalid: + if rightValue.Kind() == reflect.Invalid { + return true, nil + } + + // not possible situation - params are converted to the same type in code above + return nil, fmt.Errorf("Compare params of Invalid type: left: %+v, right: %+v", leftValue.Kind(), rightValue.Kind()) + default: - return nil, fmt.Errorf("TODO: evaluateCompare not implemented! left: %+v, right: %+v", leftValue.Kind(), rightValue.Kind()) + return nil, fmt.Errorf("Compare not implemented for types: left: %+v, right: %+v", leftValue.Kind(), rightValue.Kind()) } } diff --git a/pkg/exprparser/interpreter_test.go b/pkg/exprparser/interpreter_test.go index d6f58a7..01eb25f 100644 --- a/pkg/exprparser/interpreter_test.go +++ b/pkg/exprparser/interpreter_test.go @@ -69,6 +69,11 @@ func TestOperators(t *testing.T) { {`true || false`, true, "or", ""}, {`fromJSON('{}') && true`, true, "and-boolean-object", ""}, {`fromJSON('{}') || false`, make(map[string]interface{}), "or-boolean-object", ""}, + {"github.event.commits[0].author.username != github.event.commits[1].author.username", true, "property-comparison1", ""}, + {"github.event.commits[0].author.username1 != github.event.commits[1].author.username", true, "property-comparison2", ""}, + {"github.event.commits[0].author.username != github.event.commits[1].author.username1", true, "property-comparison3", ""}, + {"github.event.commits[0].author.username1 != github.event.commits[1].author.username2", true, "property-comparison4", ""}, + {"secrets != env", nil, "property-comparison5", "Compare not implemented for types: left: map, right: map"}, } env := &EvaluationEnvironment{