From f790c7279a171d15e41fb6196e29ddb94370acc7 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Wed, 19 Jul 2017 10:28:52 -0500 Subject: [PATCH] Unit test for failure case of AddCheck --- agent/local_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/agent/local_test.go b/agent/local_test.go index e1ae506c0..5e8d849f9 100644 --- a/agent/local_test.go +++ b/agent/local_test.go @@ -1533,6 +1533,26 @@ func TestAgent_checkCriticalTime(t *testing.T) { } } +func TestAgent_AddCheckFailure(t *testing.T) { + t.Parallel() + cfg := TestConfig() + l := NewLocalState(cfg, nil) + + // Add a check for a service that does not exist and verify that it fails + checkID := types.CheckID("redis:1") + chk := &structs.HealthCheck{ + Node: "node", + CheckID: checkID, + Name: "redis:1", + ServiceID: "redis", + Status: api.HealthPassing, + } + if err := l.AddCheck(chk, ""); err == nil { + t.Fatalf("Expected error when adding a check for a non-existent service") + } + +} + func TestAgent_nestedPauseResume(t *testing.T) { t.Parallel() l := new(localState)