Skip to content

Commit

Permalink
add new heartbeat types
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf committed Nov 5, 2024
1 parent c8bf54e commit f9fa73a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
12 changes: 6 additions & 6 deletions database/redis/emergency_contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ var (

testEmergencyContact = datatypes.EmergencyContact{
ContactID: testContactID,
HeartbeatTypes: []datatypes.HeartbeatType{datatypes.HeartbeatNotifierOff},
HeartbeatTypes: []datatypes.HeartbeatType{datatypes.HeartbeatNotifier},
}

testEmergencyContact2 = datatypes.EmergencyContact{
ContactID: testContactID2,
HeartbeatTypes: []datatypes.HeartbeatType{datatypes.HeartbeatNotifierOff},
HeartbeatTypes: []datatypes.HeartbeatType{datatypes.HeartbeatNotifier},
}

testEmergencyContact3 = datatypes.EmergencyContact{
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestGetHeartbeatTypeContactIDs(t *testing.T) {

Convey("Test GetHeartbeatTypeContactIDs", t, func() {
Convey("Without any emergency contacts by heartbeat type", func() {
emergencyContactIDs, err := database.GetHeartbeatTypeContactIDs(datatypes.HeartbeatNotifierOff)
emergencyContactIDs, err := database.GetHeartbeatTypeContactIDs(datatypes.HeartbeatNotifier)
So(err, ShouldBeNil)
So(emergencyContactIDs, ShouldBeEmpty)
})
Expand All @@ -159,7 +159,7 @@ func TestGetHeartbeatTypeContactIDs(t *testing.T) {
testEmergencyContact3,
})

emergencyContactIDs, err := database.GetHeartbeatTypeContactIDs(datatypes.HeartbeatNotifierOff)
emergencyContactIDs, err := database.GetHeartbeatTypeContactIDs(datatypes.HeartbeatNotifier)
So(err, ShouldBeNil)
assert.ElementsMatch(t, emergencyContactIDs, []string{
testContactID,
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestSaveEmergencyContact(t *testing.T) {
So(err, ShouldBeNil)
So(emergencyContacts, ShouldResemble, expectedEmergencyContacts)

emergencyContactIDs, err := database.GetHeartbeatTypeContactIDs(datatypes.HeartbeatNotifierOff)
emergencyContactIDs, err := database.GetHeartbeatTypeContactIDs(datatypes.HeartbeatNotifier)
So(err, ShouldBeNil)
So(emergencyContactIDs, ShouldResemble, expectedEmergencyContactIDs)
})
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestSaveEmergencyContacts(t *testing.T) {
So(err, ShouldBeNil)
assert.ElementsMatch(t, emergencyContacts, expectedEmergencyContacts)

emergencyContactIDs, err := database.GetHeartbeatTypeContactIDs(datatypes.HeartbeatNotifierOff)
emergencyContactIDs, err := database.GetHeartbeatTypeContactIDs(datatypes.HeartbeatNotifier)
So(err, ShouldBeNil)
assert.ElementsMatch(t, emergencyContactIDs, expectedEmergencyContactIDs)
})
Expand Down
4 changes: 2 additions & 2 deletions database/redis/reply/emergency_contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
)

const (
testEmergencyContactVal = `{"contact_id":"test-contact-id","heartbeat_types":["notifier_off"]}`
testEmergencyContactVal = `{"contact_id":"test-contact-id","heartbeat_types":["heartbeat_notifier"]}`
testEmptyEmergencyContactVal = `{"contact_id":"","heartbeat_types":null}`
)

var (
testEmergencyContact = datatypes.EmergencyContact{
ContactID: "test-contact-id",
HeartbeatTypes: []datatypes.HeartbeatType{datatypes.HeartbeatNotifierOff},
HeartbeatTypes: []datatypes.HeartbeatType{datatypes.HeartbeatNotifier},
}
testEmptyEmergencyContact = datatypes.EmergencyContact{}
)
Expand Down
10 changes: 7 additions & 3 deletions datatypes/emergency_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ package datatypes
type HeartbeatType string

const (
HeartbeatTypeNotSet HeartbeatType = "type_not_set"
HeartbeatNotifierOff HeartbeatType = "notifier_off"
HeartbeatTypeNotSet HeartbeatType = "heartbeat_type_not_set"
HeartbeatNotifier HeartbeatType = "heartbeat_notifier"
HeartbeatDatabase HeartbeatType = "heartbeat_database"
HeartbeatLocalChecker HeartbeatType = "heartbeat_local_checker"
HeartbeatRemoteChecker HeartbeatType = "heartbeat_remote_checker"
HeartbeatFilter HeartbeatType = "heartbeat_filter"
)

// IsValid checks if such an heartbeat type exists.
func (heartbeatType HeartbeatType) IsValid() bool {
switch heartbeatType {
case HeartbeatNotifierOff:
case HeartbeatNotifier, HeartbeatDatabase, HeartbeatLocalChecker, HeartbeatRemoteChecker, HeartbeatFilter:
return true
default:
return false
Expand Down
6 changes: 5 additions & 1 deletion datatypes/emergency_contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ func TestIsValidHeartbeatType(t *testing.T) {
Convey("Test IsValid heartbeat type", t, func() {
Convey("Test valid cases", func() {
testcases := []HeartbeatType{
HeartbeatNotifierOff,
HeartbeatNotifier,
HeartbeatDatabase,
HeartbeatLocalChecker,
HeartbeatRemoteChecker,
HeartbeatFilter,
}

for _, testcase := range testcases {
Expand Down

0 comments on commit f9fa73a

Please sign in to comment.