Implement any function and prettify displayed condition on failure

This commit is contained in:
TwinProduction
2021-01-14 20:08:27 -05:00
parent 855c106e9b
commit 819093cb7e
4 changed files with 977 additions and 802 deletions

View File

@ -322,6 +322,53 @@ func TestCondition_evaluateWithStatusPatternFailure(t *testing.T) {
}
}
func TestCondition_evaluateWithBodyStringAny(t *testing.T) {
condition := Condition("[BODY].name == any(john.doe, jane.doe)")
result := &Result{Body: []byte("{\"name\": \"john.doe\"}")}
condition.evaluate(result)
if !result.ConditionResults[0].Success {
t.Errorf("Condition '%s' should have been a success", condition)
}
result = &Result{Body: []byte("{\"name\": \"jane.doe\"}")}
condition.evaluate(result)
if !result.ConditionResults[0].Success {
t.Errorf("Condition '%s' should have been a success", condition)
}
}
func TestCondition_evaluateWithBodyStringAnyFailure(t *testing.T) {
condition := Condition("[BODY].name == any(john.doe, jane.doe)")
result := &Result{Body: []byte("{\"name\": \"bob.doe\"}")}
condition.evaluate(result)
if result.ConditionResults[0].Success {
t.Errorf("Condition '%s' should have been a failure", condition)
}
}
func TestCondition_evaluateWithStatusAny(t *testing.T) {
condition := Condition("[STATUS] == any(200, 429)")
statuses := []int{200, 429}
for _, status := range statuses {
result := &Result{HTTPStatus: status}
condition.evaluate(result)
if !result.ConditionResults[0].Success {
t.Errorf("Condition '%s' should have been a success", condition)
}
}
}
func TestCondition_evaluateWithStatusAnyFailure(t *testing.T) {
condition := Condition("[STATUS] == any(200, 429)")
statuses := []int{201, 400, 404, 500}
for _, status := range statuses {
result := &Result{HTTPStatus: status}
condition.evaluate(result)
if result.ConditionResults[0].Success {
t.Errorf("Condition '%s' should have been a failure", condition)
}
}
}
func TestCondition_evaluateWithConnected(t *testing.T) {
condition := Condition("[CONNECTED] == true")
result := &Result{Connected: true}