mirror of https://github.com/hashicorp/consul
agent: http checks work inside of service definitions
parent
a95b5a63bb
commit
3c85d7e231
|
@ -32,7 +32,7 @@ func (s *ServiceDefinition) NodeService() *structs.NodeService {
|
||||||
func (s *ServiceDefinition) CheckTypes() (checks CheckTypes) {
|
func (s *ServiceDefinition) CheckTypes() (checks CheckTypes) {
|
||||||
s.Checks = append(s.Checks, &s.Check)
|
s.Checks = append(s.Checks, &s.Check)
|
||||||
for _, check := range s.Checks {
|
for _, check := range s.Checks {
|
||||||
if (check.Script != "" && check.Interval != 0) || check.TTL != 0 {
|
if check.Valid() {
|
||||||
checks = append(checks, check)
|
checks = append(checks, check)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hashicorp/consul/consul/structs"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/consul/consul/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAgentStructs_HealthCheck(t *testing.T) {
|
func TestAgentStructs_HealthCheck(t *testing.T) {
|
||||||
|
@ -14,3 +16,37 @@ func TestAgentStructs_HealthCheck(t *testing.T) {
|
||||||
t.Fatalf("bad: %v", check.Status)
|
t.Fatalf("bad: %v", check.Status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue