1
0
Fork 0
mirror of https://github.com/TwiN/gatus.git synced 2024-12-14 11:58:04 +00:00

Add TestCondition_evaluateWithBodyHTMLPattern

This commit is contained in:
TwinProduction 2021-01-15 19:45:17 -05:00
parent 271c3dc91d
commit 77737dbab6

View file

@ -394,6 +394,20 @@ func TestCondition_evaluateWithBodyStringPattern(t *testing.T) {
} }
} }
func TestCondition_evaluateWithBodyHTMLPattern(t *testing.T) {
var html = `<!DOCTYPE html><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><div id="user">john.doe</div></body></html>`
condition := Condition("[BODY] == pat(*<div id=\"user\">john.doe</div>*)")
result := &Result{Body: []byte(html)}
condition.evaluate(result)
if !result.ConditionResults[0].Success {
t.Errorf("Condition '%s' should have been a success", condition)
}
expectedConditionDisplayed := "[BODY] == pat(*<div id=\"user\">john.doe</div>*)"
if result.ConditionResults[0].Condition != expectedConditionDisplayed {
t.Errorf("Condition '%s' should have resolved to '%s', got '%s'", condition, expectedConditionDisplayed, result.ConditionResults[0].Condition)
}
}
func TestCondition_evaluateWithBodyStringPatternFailure(t *testing.T) { func TestCondition_evaluateWithBodyStringPatternFailure(t *testing.T) {
condition := Condition("[BODY].name == pat(bob*)") condition := Condition("[BODY].name == pat(bob*)")
result := &Result{Body: []byte("{\"name\": \"john.doe\"}")} result := &Result{Body: []byte("{\"name\": \"john.doe\"}")}