Skip to content

Commit

Permalink
fix: compare properties of Invalid types (#1645)
Browse files Browse the repository at this point in the history
* fix: compare properties of Invalid types

 fix: compare properties of Invalid types #1643

* fix linter problem

* Fix review comment
  • Loading branch information
alex-savchuk authored Mar 3, 2023
1 parent 44b510f commit 973dd7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/exprparser/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/exprparser/interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 973dd7f

Please sign in to comment.