From 8c6f40f299cfc46cdd845e58b5e075207117f47c Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Mon, 24 Aug 2015 22:31:53 -0700 Subject: [PATCH] consul/state: negative tests --- consul/state/state_store_test.go | 34 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/consul/state/state_store_test.go b/consul/state/state_store_test.go index facaeae40c..2545fe99c0 100644 --- a/consul/state/state_store_test.go +++ b/consul/state/state_store_test.go @@ -278,6 +278,23 @@ func TestStateStore_DeleteNodeService(t *testing.T) { func TestStateStore_EnsureCheck(t *testing.T) { s := testStateStore(t) + // Create a check associated with the node + check := &structs.HealthCheck{ + Node: "node1", + CheckID: "check1", + Name: "redis check", + Status: structs.HealthPassing, + Notes: "test check", + Output: "aaa", + ServiceID: "service1", + ServiceName: "redis", + } + + // Creating a check without a node returns error + if err := s.EnsureCheck(1, check); err != ErrMissingNode { + t.Fatalf("expected %#v, got: %#v", ErrMissingNode, err) + } + // Create a node and insert it node := &structs.Node{ Node: "node1", @@ -287,6 +304,11 @@ func TestStateStore_EnsureCheck(t *testing.T) { t.Fatalf("err: %s", err) } + // Creating a check with a bad services returns error + if err := s.EnsureCheck(1, check); err != ErrMissingService { + t.Fatalf("expected: %#v, got: %#v", ErrMissingService, err) + } + // Create a service and insert it service := &structs.NodeService{ ID: "service1", @@ -299,17 +321,7 @@ func TestStateStore_EnsureCheck(t *testing.T) { t.Fatalf("err: %s", err) } - // Create a check associated with the node and insert it - check := &structs.HealthCheck{ - Node: "node1", - CheckID: "check1", - Name: "redis check", - Status: structs.HealthPassing, - Notes: "test check", - Output: "aaa", - ServiceID: "service1", - ServiceName: "redis", - } + // Inserting the check with the prerequisites succeeds if err := s.EnsureCheck(3, check); err != nil { t.Fatalf("err: %s", err) }