consul/state: more tests for EnsureNode/GetNode
This commit is contained in:
parent
f0dd8b2923
commit
a5d5577cdd
|
@ -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…
Reference in New Issue