consul/state: more tests for EnsureNode/GetNode

This commit is contained in:
Ryan Uber 2015-08-22 13:29:44 -07:00 committed by James Phillips
parent f0dd8b2923
commit a5d5577cdd
1 changed files with 18 additions and 1 deletions

View File

@ -18,9 +18,14 @@ func testStateStore(t *testing.T) *StateStore {
return s
}
func TestStateStore_EnsureNode(t *testing.T) {
func TestStateStore_EnsureNode_GetNode(t *testing.T) {
s := testStateStore(t)
// Fetching a non-existent node returns nil
if node, err := s.GetNode("node1"); node != nil || err != nil {
t.Fatalf("expected (nil, nil), got: (%#v, %#v)", node, err)
}
// Create a node registration request
in := &structs.Node{
Node: "node1",
@ -64,6 +69,18 @@ func TestStateStore_EnsureNode(t *testing.T) {
if out.CreateIndex != 1 || out.ModifyIndex != 2 || out.Address != "1.1.1.2" {
t.Fatalf("bad: %#v", out)
}
// Node upsert is idempotent
if err := s.EnsureNode(2, in); err != nil {
t.Fatalf("err: %s", err)
}
out, err = s.GetNode("node1")
if err != nil {
t.Fatalf("err: %s", err)
}
if out.Address != "1.1.1.2" || out.CreateIndex != 1 || out.ModifyIndex != 2 {
t.Fatalf("node was modified: %#v", out)
}
}
func TestStateStore_EnsureService(t *testing.T) {