Skip to content

Commit

Permalink
Merge pull request #1085 from michelle192837/eval
Browse files Browse the repository at this point in the history
Fix string comparison for custom statuses.
  • Loading branch information
google-oss-prow[bot] authored Nov 23, 2022
2 parents 0052319 + 9a975e8 commit 40491bc
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/updater/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func strStartsWith(a, b string) bool {
}

func strContains(a, b string) bool {
return strings.Contains(b, a)
return strings.Contains(a, b)
}

func numEQ(a, b float64) bool {
Expand Down
79 changes: 76 additions & 3 deletions pkg/updater/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,30 @@ func TestCustomStatus(t *testing.T) {

want: &timedOut,
},
{
name: "wrong string value",
rules: []*evalpb.Rule{
{
ComputedStatus: tspb.TestStatus_TIMED_OUT,
TestResultComparisons: []*evalpb.TestResultComparison{
{
TestResultInfo: &evalpb.TestResultComparison_PropertyKey{
PropertyKey: "foo",
},
Comparison: &evalpb.Comparison{
Op: evalpb.Comparison_OP_EQ,
ComparisonValue: &evalpb.Comparison_StringValue{
StringValue: "goal",
},
},
},
},
},
},
tr: makeResult(map[string][]string{
"foo": {"wrong-value"},
}),
},
{
name: "not equal, string",
rules: []*evalpb.Rule{
Expand All @@ -164,7 +188,7 @@ func TestCustomStatus(t *testing.T) {
want: &timedOut,
},
{
name: "wrong string value",
name: "not equal, string, is equal",
rules: []*evalpb.Rule{
{
ComputedStatus: tspb.TestStatus_TIMED_OUT,
Expand All @@ -174,7 +198,7 @@ func TestCustomStatus(t *testing.T) {
PropertyKey: "foo",
},
Comparison: &evalpb.Comparison{
Op: evalpb.Comparison_OP_EQ,
Op: evalpb.Comparison_OP_NE,
ComparisonValue: &evalpb.Comparison_StringValue{
StringValue: "goal",
},
Expand All @@ -184,7 +208,56 @@ func TestCustomStatus(t *testing.T) {
},
},
tr: makeResult(map[string][]string{
"foo": {"wrong-value"},
"foo": {"goal"},
}),
},
{
name: "string contains",
rules: []*evalpb.Rule{
{
ComputedStatus: tspb.TestStatus_TIMED_OUT,
TestResultComparisons: []*evalpb.TestResultComparison{
{
TestResultInfo: &evalpb.TestResultComparison_PropertyKey{
PropertyKey: "foo",
},
Comparison: &evalpb.Comparison{
Op: evalpb.Comparison_OP_CONTAINS,
ComparisonValue: &evalpb.Comparison_StringValue{
StringValue: "goal",
},
},
},
},
},
},
tr: makeResult(map[string][]string{
"foo": {"this is the goal"},
}),
want: &timedOut,
},
{
name: "string does not contains",
rules: []*evalpb.Rule{
{
ComputedStatus: tspb.TestStatus_TIMED_OUT,
TestResultComparisons: []*evalpb.TestResultComparison{
{
TestResultInfo: &evalpb.TestResultComparison_PropertyKey{
PropertyKey: "foo",
},
Comparison: &evalpb.Comparison{
Op: evalpb.Comparison_OP_CONTAINS,
ComparisonValue: &evalpb.Comparison_StringValue{
StringValue: "goal",
},
},
},
},
},
},
tr: makeResult(map[string][]string{
"foo": {"i am not a matching message"},
}),
},
{
Expand Down

0 comments on commit 40491bc

Please sign in to comment.