mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-21 15:33:17 +01:00
test: Add several tests for numerical conditions
This commit is contained in:
parent
0ffa03f42d
commit
0db92f46da
@ -11,6 +11,7 @@ import (
|
||||
"github.com/TwiN/gatus/v5/pattern"
|
||||
)
|
||||
|
||||
// Placeholders
|
||||
const (
|
||||
// StatusPlaceholder is a placeholder for a HTTP status.
|
||||
//
|
||||
@ -49,7 +50,10 @@ const (
|
||||
|
||||
// DomainExpirationPlaceholder is a placeholder for the duration before the domain expires, in milliseconds.
|
||||
DomainExpirationPlaceholder = "[DOMAIN_EXPIRATION]"
|
||||
)
|
||||
|
||||
// Functions
|
||||
const (
|
||||
// LengthFunctionPrefix is the prefix for the length function
|
||||
//
|
||||
// Usage: len([BODY].articles) == 10, len([BODY].name) > 5
|
||||
@ -72,7 +76,10 @@ const (
|
||||
|
||||
// FunctionSuffix is the suffix for all functions
|
||||
FunctionSuffix = ")"
|
||||
)
|
||||
|
||||
// Other constants
|
||||
const (
|
||||
// InvalidConditionElementSuffix is the suffix that will be appended to an invalid condition
|
||||
InvalidConditionElementSuffix = "(INVALID)"
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user