Browse Source

consul/state: more tests for EnsureNode/GetNode

pull/1291/head
Ryan Uber 9 years ago committed by James Phillips
parent
commit
0085512eb8
  1. 19
      consul/state/state_store_test.go

19
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) {

Loading…
Cancel
Save