@@ -120,6 +120,63 @@ proxy:
120120 assert .Contains (t , err .Error (), "parsing proxy.write_timeout" )
121121}
122122
123+ func TestParseAlertingOptions (t * testing.T ) {
124+ cfg := config .Default ()
125+ cfg .Alerting .Enabled = true
126+ cfg .Alerting .QueueSize = 256
127+ cfg .Alerting .Events .Block = true
128+ cfg .Alerting .Events .RateLimit = true
129+ cfg .Alerting .Events .ScanError = false
130+ cfg .Alerting .Throttle .WindowSeconds = 45
131+ cfg .Alerting .Webhook .Enabled = true
132+ cfg .Alerting .Webhook .URL = "https://example.com/hook"
133+ cfg .Alerting .Webhook .Timeout = "5s"
134+ cfg .Alerting .Webhook .MaxRetries = 4
135+ cfg .Alerting .Webhook .BackoffInitialMs = 150
136+ cfg .Alerting .Webhook .AuthBearerToken = "token"
137+ cfg .Alerting .Slack .Enabled = true
138+ cfg .Alerting .Slack .IncomingWebhookURL = "https://hooks.slack.test/abc"
139+ cfg .Alerting .Slack .Timeout = "4s"
140+ cfg .Alerting .Slack .MaxRetries = 2
141+ cfg .Alerting .Slack .BackoffInitialMs = 300
142+
143+ opts , err := parseAlertingOptions (cfg )
144+ require .NoError (t , err )
145+
146+ assert .True (t , opts .Enabled )
147+ assert .Equal (t , 256 , opts .QueueSize )
148+ assert .True (t , opts .Events .Block )
149+ assert .True (t , opts .Events .RateLimit )
150+ assert .False (t , opts .Events .ScanError )
151+ assert .Equal (t , 45 * time .Second , opts .ThrottleWindow )
152+ assert .True (t , opts .Webhook .Enabled )
153+ assert .Equal (t , "https://example.com/hook" , opts .Webhook .URL )
154+ assert .Equal (t , 5 * time .Second , opts .Webhook .Timeout )
155+ assert .Equal (t , 4 , opts .Webhook .MaxRetries )
156+ assert .Equal (t , 150 * time .Millisecond , opts .Webhook .BackoffInitial )
157+ assert .Equal (t , "token" , opts .Webhook .AuthBearerToken )
158+ assert .True (t , opts .Slack .Enabled )
159+ assert .Equal (t , "https://hooks.slack.test/abc" , opts .Slack .URL )
160+ assert .Equal (t , 4 * time .Second , opts .Slack .Timeout )
161+ assert .Equal (t , 2 , opts .Slack .MaxRetries )
162+ assert .Equal (t , 300 * time .Millisecond , opts .Slack .BackoffInitial )
163+ }
164+
165+ func TestParseAlertingOptions_InvalidTimeout (t * testing.T ) {
166+ cfg := config .Default ()
167+ cfg .Alerting .Webhook .Timeout = "bad"
168+
169+ _ , err := parseAlertingOptions (cfg )
170+ require .Error (t , err )
171+ assert .Contains (t , err .Error (), "parsing alerting.webhook.timeout" )
172+
173+ cfg = config .Default ()
174+ cfg .Alerting .Slack .Timeout = "bad"
175+ _ , err = parseAlertingOptions (cfg )
176+ require .Error (t , err )
177+ assert .Contains (t , err .Error (), "parsing alerting.slack.timeout" )
178+ }
179+
123180func testContext (t * testing.T ) context.Context {
124181 t .Helper ()
125182 ctx , cancel := context .WithTimeout (context .Background (), time .Second )
0 commit comments