2014-10-15 17:08:13 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2015-01-29 20:11:42 +00:00
|
|
|
"time"
|
|
|
|
|
2017-04-19 23:00:11 +00:00
|
|
|
"github.com/hashicorp/consul/api"
|
2014-10-15 17:08:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAgentStructs_HealthCheck(t *testing.T) {
|
|
|
|
def := CheckDefinition{}
|
|
|
|
check := def.HealthCheck("node1")
|
|
|
|
|
|
|
|
// Health checks default to critical state
|
2017-04-19 23:00:11 +00:00
|
|
|
if check.Status != api.HealthCritical {
|
2014-10-15 17:08:13 +00:00
|
|
|
t.Fatalf("bad: %v", check.Status)
|
|
|
|
}
|
|
|
|
}
|
2015-01-29 20:11:42 +00:00
|
|
|
|
|
|
|
func TestAgentStructs_CheckTypes(t *testing.T) {
|
|
|
|
svc := new(ServiceDefinition)
|
|
|
|
|
|
|
|
// Singular Check field works
|
|
|
|
svc.Check = CheckType{
|
|
|
|
Script: "/foo/bar",
|
|
|
|
Interval: 10 * time.Second,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns HTTP checks
|
|
|
|
svc.Checks = append(svc.Checks, &CheckType{
|
|
|
|
HTTP: "http://foo/bar",
|
|
|
|
Interval: 10 * time.Second,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Returns Script checks
|
|
|
|
svc.Checks = append(svc.Checks, &CheckType{
|
|
|
|
Script: "/foo/bar",
|
|
|
|
Interval: 10 * time.Second,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Returns TTL checks
|
|
|
|
svc.Checks = append(svc.Checks, &CheckType{
|
|
|
|
TTL: 10 * time.Second,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Does not return invalid checks
|
|
|
|
svc.Checks = append(svc.Checks, &CheckType{})
|
|
|
|
|
|
|
|
if len(svc.CheckTypes()) != 4 {
|
|
|
|
t.Fatalf("bad: %#v", svc)
|
|
|
|
}
|
|
|
|
}
|