From a644573451dfeb8b1665965946479ed719188c0d Mon Sep 17 00:00:00 2001 From: almostinf Date: Tue, 1 Oct 2024 11:50:12 +0300 Subject: [PATCH] add datatypes module and fix some naming --- datatypes/emergency_contact.go | 25 ++++++++++++++++++++++ datatypes/emergency_contact_test.go | 32 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 datatypes/emergency_contact.go create mode 100644 datatypes/emergency_contact_test.go diff --git a/datatypes/emergency_contact.go b/datatypes/emergency_contact.go new file mode 100644 index 000000000..408242e02 --- /dev/null +++ b/datatypes/emergency_contact.go @@ -0,0 +1,25 @@ +package datatypes + +// HeartbeatType are Moira's special internal types of problems. +type HeartbeatType string + +const ( + HearbeatTypeNotSet HeartbeatType = "type_not_set" + HeartbeatNotifierOff HeartbeatType = "notifier_off" +) + +// IsValid checks if such an heartbeat type exists. +func (heartbeatType HeartbeatType) IsValid() bool { + switch heartbeatType { + case HeartbeatNotifierOff: + return true + default: + return false + } +} + +// EmergencyContact is the structure for contacts to which notifications will go in the event of special internal Moira problems. +type EmergencyContact struct { + ContactID string + HeartbeatTypes []HeartbeatType +} diff --git a/datatypes/emergency_contact_test.go b/datatypes/emergency_contact_test.go new file mode 100644 index 000000000..ec0389b32 --- /dev/null +++ b/datatypes/emergency_contact_test.go @@ -0,0 +1,32 @@ +package datatypes + +import ( + "testing" + + . "github.com/smartystreets/goconvey/convey" +) + +func TestIsValidHeartbeatType(t *testing.T) { + Convey("Test IsValid heartbeat type", t, func() { + Convey("Test valid cases", func() { + testcases := []HeartbeatType{ + HeartbeatNotifierOff, + } + + for _, testcase := range testcases { + So(testcase.IsValid(), ShouldBeTrue) + } + }) + + Convey("Test invalid cases", func() { + testcases := []HeartbeatType{ + "notifier_on", + "checker_off", + } + + for _, testcase := range testcases { + So(testcase.IsValid(), ShouldBeFalse) + } + }) + }) +}