mirror of
https://github.com/status-im/consul.git
synced 2025-02-17 08:07:35 +00:00
consul/state: more tests for EnsureNode/GetNode
This commit is contained in:
parent
b2d9c10fad
commit
0085512eb8
@ -18,9 +18,14 @@ func testStateStore(t *testing.T) *StateStore {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStateStore_EnsureNode(t *testing.T) {
|
func TestStateStore_EnsureNode_GetNode(t *testing.T) {
|
||||||
s := testStateStore(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
|
// Create a node registration request
|
||||||
in := &structs.Node{
|
in := &structs.Node{
|
||||||
Node: "node1",
|
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" {
|
if out.CreateIndex != 1 || out.ModifyIndex != 2 || out.Address != "1.1.1.2" {
|
||||||
t.Fatalf("bad: %#v", out)
|
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) {
|
func TestStateStore_EnsureService(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user