2020-04-15 01:20:00 +02:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2020-09-25 01:49:32 +02:00
|
|
|
func TestIntegrationEvaluateHealth(t *testing.T) {
|
2020-04-15 01:20:00 +02:00
|
|
|
condition := Condition("[STATUS] == 200")
|
|
|
|
service := Service{
|
|
|
|
Name: "TwiNNatioN",
|
|
|
|
Url: "https://twinnation.org/health",
|
|
|
|
Conditions: []*Condition{&condition},
|
|
|
|
}
|
2020-09-25 01:49:32 +02:00
|
|
|
result := service.EvaluateHealth()
|
2020-04-15 01:20:00 +02:00
|
|
|
if !result.ConditionResults[0].Success {
|
|
|
|
t.Errorf("Condition '%s' should have been a success", condition)
|
|
|
|
}
|
2020-10-05 01:55:19 +02:00
|
|
|
if !result.Connected {
|
|
|
|
t.Error("Because the connection has been established, result.Connected should've been true")
|
|
|
|
}
|
2020-04-15 01:20:00 +02:00
|
|
|
if !result.Success {
|
|
|
|
t.Error("Because all conditions passed, this should have been a success")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 01:49:32 +02:00
|
|
|
func TestIntegrationEvaluateHealthWithFailure(t *testing.T) {
|
2020-04-15 01:20:00 +02:00
|
|
|
condition := Condition("[STATUS] == 500")
|
|
|
|
service := Service{
|
|
|
|
Name: "TwiNNatioN",
|
|
|
|
Url: "https://twinnation.org/health",
|
|
|
|
Conditions: []*Condition{&condition},
|
|
|
|
}
|
2020-09-25 01:49:32 +02:00
|
|
|
result := service.EvaluateHealth()
|
2020-04-15 01:20:00 +02:00
|
|
|
if result.ConditionResults[0].Success {
|
|
|
|
t.Errorf("Condition '%s' should have been a failure", condition)
|
|
|
|
}
|
2020-10-05 01:55:19 +02:00
|
|
|
if !result.Connected {
|
|
|
|
t.Error("Because the connection has been established, result.Connected should've been true")
|
|
|
|
}
|
2020-04-15 01:20:00 +02:00
|
|
|
if result.Success {
|
|
|
|
t.Error("Because one of the conditions failed, success should have been false")
|
|
|
|
}
|
|
|
|
}
|