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:
parent
271c3dc91d
commit
77737dbab6
1 changed files with 14 additions and 0 deletions
|
@ -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\"}")}
|
||||||
|
|
Loading…
Reference in a new issue