From e9ef82cbec123598ba080b64401e7438621e55e3 Mon Sep 17 00:00:00 2001 From: almostinf Date: Fri, 1 Nov 2024 15:24:21 +0300 Subject: [PATCH] add validate heartbeater base config tests --- .../selfstate/heartbeat/heartbeat_test.go | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/notifier/selfstate/heartbeat/heartbeat_test.go b/notifier/selfstate/heartbeat/heartbeat_test.go index daec4cff8..539c44587 100644 --- a/notifier/selfstate/heartbeat/heartbeat_test.go +++ b/notifier/selfstate/heartbeat/heartbeat_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/moira-alert/moira" logging "github.com/moira-alert/moira/logging/zerolog_adapter" mock_clock "github.com/moira-alert/moira/mock/clock" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" @@ -94,3 +95,41 @@ func TestNewHeartbeaterBase(t *testing.T) { So(heartbeaterBase, ShouldResemble, expected) }) } + +func TestValidateHeartbeaterBaseConfig(t *testing.T) { + Convey("Test validation heartbeaterBaseConfig", t, func() { + Convey("With disabled config", func() { + hbCfg := HeartbeaterBaseConfig{} + err := moira.ValidateStruct(hbCfg) + So(err, ShouldBeNil) + }) + + Convey("With just enabled config", func() { + hbCfg := HeartbeaterBaseConfig{ + Enabled: true, + } + err := moira.ValidateStruct(hbCfg) + So(err, ShouldNotBeNil) + }) + + Convey("With enabled config and added alert config", func() { + hbCfg := HeartbeaterBaseConfig{ + Enabled: true, + AlertCfg: AlertConfig{}, + } + err := moira.ValidateStruct(hbCfg) + So(err, ShouldNotBeNil) + }) + + Convey("With enabled config, added and filled alert config", func() { + hbCfg := HeartbeaterBaseConfig{ + Enabled: true, + AlertCfg: AlertConfig{ + Name: "test name", + }, + } + err := moira.ValidateStruct(hbCfg) + So(err, ShouldBeNil) + }) + }) +}