From 396760f750514f0425914caf5e7df2c0dc74171d Mon Sep 17 00:00:00 2001 From: Roberto Losanno Date: Wed, 3 Jun 2026 14:31:03 +0100 Subject: [PATCH] feat: add notifiers field to WebHook and WebHookInput structs --- .../unreleased/Added-20260603-143053.yaml | 3 ++ management/webhook.go | 2 + management/webhook_test.go | 54 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 .changes/unreleased/Added-20260603-143053.yaml create mode 100644 management/webhook_test.go diff --git a/.changes/unreleased/Added-20260603-143053.yaml b/.changes/unreleased/Added-20260603-143053.yaml new file mode 100644 index 0000000..0356f46 --- /dev/null +++ b/.changes/unreleased/Added-20260603-143053.yaml @@ -0,0 +1,3 @@ +kind: Added +body: Added Notifiers field to WebHook and WebHookInput structs to support email notification on circuit breaker events +time: 2026-06-03T14:30:53.347423+01:00 diff --git a/management/webhook.go b/management/webhook.go index 18a8ebc..e8df25a 100644 --- a/management/webhook.go +++ b/management/webhook.go @@ -30,6 +30,7 @@ type WebHook struct { RetryPolicy string `json:"retry_policy"` Disabled bool `json:"disabled"` ConcisePayload bool `json:"concise_payload"` + Notifiers []string `json:"notifiers"` } type WebhookDestination struct { @@ -53,6 +54,7 @@ type WebHookInput struct { RetryPolicy string `json:"retry_policy"` Disabled bool `json:"disabled"` ConcisePayload bool `json:"concise_payload"` + Notifiers []string `json:"notifiers"` } func (si *StackInstance) WebHookCreate(ctx context.Context, input WebHookInput) (*WebHook, error) { diff --git a/management/webhook_test.go b/management/webhook_test.go new file mode 100644 index 0000000..02c81d1 --- /dev/null +++ b/management/webhook_test.go @@ -0,0 +1,54 @@ +package management + +import ( + "encoding/json" + "testing" +) + +func TestWebHookInput_NotifiersSerializedToJSON(t *testing.T) { + input := WebHookRequest{ + WebHook: WebHookInput{ + Name: "test-hook", + Notifiers: []string{"ops@example.com", "dev@example.com"}, + }, + } + data, err := json.Marshal(input) + if err != nil { + t.Fatalf("unexpected marshal error: %v", err) + } + var result map[string]interface{} + if err := json.Unmarshal(data, &result); err != nil { + t.Fatalf("unexpected unmarshal error: %v", err) + } + webhook, ok := result["webhook"].(map[string]interface{}) + if !ok { + t.Fatal("expected webhook key in JSON") + } + notifiers, ok := webhook["notifiers"].([]interface{}) + if !ok { + t.Fatalf("expected notifiers to be an array, got: %v", webhook["notifiers"]) + } + if len(notifiers) != 2 { + t.Errorf("expected 2 notifiers, got %d", len(notifiers)) + } + if notifiers[0].(string) != "ops@example.com" { + t.Errorf("expected ops@example.com, got %s", notifiers[0]) + } + if notifiers[1].(string) != "dev@example.com" { + t.Errorf("expected dev@example.com, got %s", notifiers[1]) + } +} + +func TestWebHook_NotifiersDeserializedFromJSON(t *testing.T) { + raw := `{"webhook":{"name":"test","notifiers":["ops@example.com"]}}` + var result WebHookResponse + if err := json.Unmarshal([]byte(raw), &result); err != nil { + t.Fatalf("unexpected unmarshal error: %v", err) + } + if len(result.WebHook.Notifiers) != 1 { + t.Errorf("expected 1 notifier, got %d", len(result.WebHook.Notifiers)) + } + if result.WebHook.Notifiers[0] != "ops@example.com" { + t.Errorf("expected ops@example.com, got %s", result.WebHook.Notifiers[0]) + } +}