consul/command/agent/structs_test.go
Frank Schroeder eddb1af603 Remove duplicate constants
This patch removes duplicate internal copies of constants in the structs
package which are also defined in the api package. The api.KVOp type
with all its values for the TXN endpoint and the api.HealthXXX constants
are now used throughout the codebase.

This resulted in some circular dependencies in the testutil package
which have been resolved by copying code and constants and moving the
WaitForLeader function into a separate testrpc package.
2017-04-20 09:54:49 -07:00

53 lines
1.0 KiB
Go

package agent
import (
"testing"
"time"
"github.com/hashicorp/consul/api"
)
func TestAgentStructs_HealthCheck(t *testing.T) {
def := CheckDefinition{}
check := def.HealthCheck("node1")
// Health checks default to critical state
if check.Status != api.HealthCritical {
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)
}
}