Skip to content

Commit 7307884

Browse files
authored
Merge pull request #216 from mackerelio/notification-group-type
Add notification group type field
2 parents db2c9a2 + dd862a1 commit 7307884

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

notification_groups.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,23 @@ const (
1414
NotificationLevelCritical NotificationLevel = "critical"
1515
)
1616

17+
// NotificationGroupType represents a type of notification group.
18+
type NotificationGroupType string
19+
20+
// NotificationGroupTypes
21+
const (
22+
NotificationGroupTypeGroup NotificationGroupType = "group"
23+
NotificationGroupTypeGroupDefault NotificationGroupType = "group-default"
24+
)
25+
1726
// NotificationGroup represents a Mackerel notification group.
1827
// ref. https://mackerel.io/api-docs/entry/notification-groups
1928
type NotificationGroup struct {
20-
ID string `json:"id,omitempty"`
29+
// ID is excluded when used to call CreateNotificationGroup.
30+
ID string `json:"id,omitempty"`
31+
32+
// Type is excluded when used to call CreateNotificationGroup or UpdateNotificationGroup.
33+
Type NotificationGroupType `json:"type,omitempty"`
2134
Name string `json:"name"`
2235
NotificationLevel NotificationLevel `json:"notificationLevel"`
2336
ChildNotificationGroupIDs []string `json:"childNotificationGroupIds"`

notification_groups_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestCreateNotificationGroup(t *testing.T) {
2929

3030
respJSON, _ := json.Marshal(map[string]any{
3131
"id": "3JwREyrZGQ9",
32+
"type": "group",
3233
"name": notificationGroup.Name,
3334
"notificationLevel": notificationGroup.NotificationLevel,
3435
"childNotificationGroupIds": notificationGroup.ChildNotificationGroupIDs,
@@ -66,6 +67,7 @@ func TestCreateNotificationGroup(t *testing.T) {
6667

6768
want := &NotificationGroup{
6869
ID: "3JwREyrZGQ9",
70+
Type: NotificationGroupTypeGroup,
6971
Name: param.Name,
7072
NotificationLevel: param.NotificationLevel,
7173
ChildNotificationGroupIDs: param.ChildNotificationGroupIDs,
@@ -92,20 +94,23 @@ func TestFindNotificationGroups(t *testing.T) {
9294
"notificationGroups": {
9395
{
9496
"id": "3Ja3HG3bTwq",
97+
"type": "group-default",
9598
"name": "Default",
9699
"notificationLevel": "all",
97100
"childNotificationGroupIDs": []string{},
98101
"childChannelIDs": []string{"3Ja3HG3VTaA"},
99102
},
100103
{
101104
"id": "3UJaU9eREvw",
105+
"type": "group",
102106
"name": "Notification Group #01",
103107
"notificationLevel": "all",
104108
"childNotificationGroupIds": []string{"3Tdq1pz9aLm"},
105109
"childChannelIds": []string{},
106110
},
107111
{
108112
"id": "3Tdq1pz9aLm",
113+
"type": "group",
109114
"name": "Notification Group #02",
110115
"notificationLevel": "critical",
111116
"childNotificationGroupIds": []string{},
@@ -135,20 +140,23 @@ func TestFindNotificationGroups(t *testing.T) {
135140
want := []*NotificationGroup{
136141
{
137142
ID: "3Ja3HG3bTwq",
143+
Type: NotificationGroupTypeGroupDefault,
138144
Name: "Default",
139145
NotificationLevel: NotificationLevelAll,
140146
ChildNotificationGroupIDs: []string{},
141147
ChildChannelIDs: []string{"3Ja3HG3VTaA"},
142148
},
143149
{
144150
ID: "3UJaU9eREvw",
151+
Type: NotificationGroupTypeGroup,
145152
Name: "Notification Group #01",
146153
NotificationLevel: NotificationLevelAll,
147154
ChildNotificationGroupIDs: []string{"3Tdq1pz9aLm"},
148155
ChildChannelIDs: []string{},
149156
},
150157
{
151158
ID: "3Tdq1pz9aLm",
159+
Type: NotificationGroupTypeGroup,
152160
Name: "Notification Group #02",
153161
NotificationLevel: NotificationLevelCritical,
154162
ChildNotificationGroupIDs: []string{},
@@ -186,6 +194,7 @@ func TestUpdateNotificationGroup(t *testing.T) {
186194

187195
respJSON, _ := json.Marshal(map[string]any{
188196
"id": id,
197+
"type": "group",
189198
"name": notificationGroup.Name,
190199
"notificationLevel": notificationGroup.NotificationLevel,
191200
"childNotificationGroupIds": notificationGroup.ChildNotificationGroupIDs,
@@ -223,6 +232,7 @@ func TestUpdateNotificationGroup(t *testing.T) {
223232

224233
want := &NotificationGroup{
225234
ID: id,
235+
Type: NotificationGroupTypeGroup,
226236
Name: param.Name,
227237
NotificationLevel: param.NotificationLevel,
228238
ChildNotificationGroupIDs: param.ChildNotificationGroupIDs,
@@ -248,6 +258,7 @@ func TestDeleteNotificationGroup(t *testing.T) {
248258

249259
respJSON, _ := json.Marshal(map[string]any{
250260
"id": id,
261+
"type": "group",
251262
"name": "My Notification Group",
252263
"notificationLevel": "all",
253264
"childNotificationGroupIds": []string{},
@@ -274,6 +285,7 @@ func TestDeleteNotificationGroup(t *testing.T) {
274285

275286
want := &NotificationGroup{
276287
ID: id,
288+
Type: NotificationGroupTypeGroup,
277289
Name: "My Notification Group",
278290
NotificationLevel: NotificationLevelAll,
279291
ChildNotificationGroupIDs: []string{},

0 commit comments

Comments
 (0)