From a5d5577cdd73be7b73c8e203418460a019e12ecc Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Sat, 22 Aug 2015 13:29:44 -0700 Subject: [PATCH] consul/state: more tests for EnsureNode/GetNode --- consul/state/state_store_test.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/consul/state/state_store_test.go b/consul/state/state_store_test.go index b1ff85617..6bb495da2 100644 --- a/consul/state/state_store_test.go +++ b/consul/state/state_store_test.go @@ -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) {