test: Add several tests for numerical conditions

This commit is contained in:
TwiN
2023-01-19 01:37:21 -05:00
parent 0ffa03f42d
commit 0db92f46da
2 changed files with 36 additions and 0 deletions

View File

@ -182,6 +182,34 @@ func TestCondition_evaluate(t *testing.T) {
ExpectedSuccess: true,
ExpectedOutput: "[BODY] == test",
},
{
Name: "body-numerical-equal",
Condition: Condition("[BODY] == 123"),
Result: &Result{body: []byte("123")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY] == 123",
},
{
Name: "body-numerical-less-than",
Condition: Condition("[BODY] < 124"),
Result: &Result{body: []byte("123")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY] < 124",
},
{
Name: "body-numerical-greater-than",
Condition: Condition("[BODY] > 122"),
Result: &Result{body: []byte("123")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY] > 122",
},
{
Name: "body-numerical-greater-than-failure",
Condition: Condition("[BODY] > 123"),
Result: &Result{body: []byte("100")},
ExpectedSuccess: false,
ExpectedOutput: "[BODY] (100) > 123",
},
{
Name: "body-jsonpath",
Condition: Condition("[BODY].status == UP"),
@ -594,6 +622,7 @@ func TestCondition_evaluate(t *testing.T) {
}
for _, scenario := range scenarios {
t.Run(scenario.Name, func(t *testing.T) {
t.Parallel()
scenario.Condition.evaluate(scenario.Result, scenario.DontResolveFailedConditions)
if scenario.Result.ConditionResults[0].Success != scenario.ExpectedSuccess {
t.Errorf("Condition '%s' should have been success=%v", scenario.Condition, scenario.ExpectedSuccess)