mirror of https://github.com/status-im/consul.git
Support getting node checks in the snapshot
This commit is contained in:
parent
2b79c125f2
commit
1f02461f8c
|
@ -518,3 +518,8 @@ func (s *StateSnapshot) Nodes() structs.Nodes {
|
|||
func (s *StateSnapshot) NodeServices(name string) *structs.NodeServices {
|
||||
return s.store.parseNodeServices(s.tx, name)
|
||||
}
|
||||
|
||||
// NodeChecks is used to return all the checks of a given node
|
||||
func (s *StateSnapshot) NodeChecks(node string) structs.HealthChecks {
|
||||
return parseHealthChecks(s.store.checkTable.GetTxn(s.tx, "id", node))
|
||||
}
|
||||
|
|
|
@ -479,6 +479,17 @@ func TestStoreSnapshot(t *testing.T) {
|
|||
t.Fatalf("err: %v")
|
||||
}
|
||||
|
||||
check := &structs.HealthCheck{
|
||||
Node: "foo",
|
||||
CheckID: "db",
|
||||
Name: "Can connect",
|
||||
Status: structs.HealthPassing,
|
||||
ServiceID: "db",
|
||||
}
|
||||
if err := store.EnsureCheck(check); err != nil {
|
||||
t.Fatalf("err: %v")
|
||||
}
|
||||
|
||||
// Take a snapshot
|
||||
snap, err := store.Snapshot()
|
||||
if err != nil {
|
||||
|
@ -506,6 +517,15 @@ func TestStoreSnapshot(t *testing.T) {
|
|||
t.Fatalf("bad: %v", services)
|
||||
}
|
||||
|
||||
// Ensure we get the checks
|
||||
checks := snap.NodeChecks("foo")
|
||||
if len(checks) != 1 {
|
||||
t.Fatalf("bad: %v", checks)
|
||||
}
|
||||
if !reflect.DeepEqual(checks[0], check) {
|
||||
t.Fatalf("bad: %v", checks[0])
|
||||
}
|
||||
|
||||
// Make some changes!
|
||||
if err := store.EnsureService("foo", "db", "db", "slave", 8000); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
@ -516,6 +536,16 @@ func TestStoreSnapshot(t *testing.T) {
|
|||
if err := store.EnsureNode(structs.Node{"baz", "127.0.0.3"}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
checkAfter := &structs.HealthCheck{
|
||||
Node: "foo",
|
||||
CheckID: "db",
|
||||
Name: "Can connect",
|
||||
Status: structs.HealthCritical,
|
||||
ServiceID: "db",
|
||||
}
|
||||
if err := store.EnsureCheck(checkAfter); err != nil {
|
||||
t.Fatalf("err: %v")
|
||||
}
|
||||
|
||||
// Check snapshot has old values
|
||||
nodes = snap.Nodes()
|
||||
|
@ -536,6 +566,14 @@ func TestStoreSnapshot(t *testing.T) {
|
|||
if services.Services["db"].Tag != "slave" {
|
||||
t.Fatalf("bad: %v", services)
|
||||
}
|
||||
|
||||
checks = snap.NodeChecks("foo")
|
||||
if len(checks) != 1 {
|
||||
t.Fatalf("bad: %v", checks)
|
||||
}
|
||||
if !reflect.DeepEqual(checks[0], check) {
|
||||
t.Fatalf("bad: %v", checks[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureCheck(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue