@@ -261,6 +261,69 @@ func TestAlertProvider_buildHTTPRequestWithCustomPlaceholder(t *testing.T) {
261261 }
262262}
263263
264+ func TestAlertProvider_buildHTTPRequestWithCustomPlaceholderAndResultConditions (t * testing.T ) {
265+ alertProvider := & AlertProvider {
266+ DefaultConfig : Config {
267+ URL : "https://example.com/[ENDPOINT_GROUP]/[ENDPOINT_NAME]?event=[ALERT_TRIGGERED_OR_RESOLVED]&description=[ALERT_DESCRIPTION]" ,
268+ Body : "[ENDPOINT_NAME],[ENDPOINT_GROUP],[ALERT_DESCRIPTION],[ALERT_TRIGGERED_OR_RESOLVED],[RESULT_CONDITIONS]" ,
269+ Headers : nil ,
270+ Placeholders : map [string ]map [string ]string {
271+ "ALERT_TRIGGERED_OR_RESOLVED" : {
272+ "RESOLVED" : "fixed" ,
273+ "TRIGGERED" : "boom" ,
274+ },
275+ },
276+ },
277+ }
278+ alertDescription := "alert-description"
279+ scenarios := []struct {
280+ AlertProvider * AlertProvider
281+ Resolved bool
282+ ExpectedURL string
283+ ExpectedBody string
284+ NoConditions bool
285+ }{
286+ {
287+ AlertProvider : alertProvider ,
288+ Resolved : true ,
289+ ExpectedURL : "https://example.com/endpoint-group/endpoint-name?event=fixed&description=alert-description" ,
290+ ExpectedBody : "endpoint-name,endpoint-group,alert-description,fixed,✅ - `[CONNECTED] == true`, ✅ - `[STATUS] == 200`" ,
291+ },
292+ {
293+ AlertProvider : alertProvider ,
294+ Resolved : false ,
295+ ExpectedURL : "https://example.com/endpoint-group/endpoint-name?event=boom&description=alert-description" ,
296+ ExpectedBody : "endpoint-name,endpoint-group,alert-description,boom,❌ - `[CONNECTED] == true`, ❌ - `[STATUS] == 200`" ,
297+ },
298+ }
299+ for _ , scenario := range scenarios {
300+ t .Run (fmt .Sprintf ("resolved-%v-with-custom-placeholders" , scenario .Resolved ), func (t * testing.T ) {
301+ var conditionResults []* endpoint.ConditionResult
302+ if ! scenario .NoConditions {
303+ conditionResults = []* endpoint.ConditionResult {
304+ {Condition : "[CONNECTED] == true" , Success : scenario .Resolved },
305+ {Condition : "[STATUS] == 200" , Success : scenario .Resolved },
306+ }
307+ }
308+
309+ request := alertProvider .buildHTTPRequest (
310+ & alertProvider .DefaultConfig ,
311+ & endpoint.Endpoint {Name : "endpoint-name" , Group : "endpoint-group" },
312+ & alert.Alert {Description : & alertDescription },
313+ & endpoint.Result {ConditionResults : conditionResults },
314+ scenario .Resolved ,
315+ )
316+ if request .URL .String () != scenario .ExpectedURL {
317+ t .Error ("expected URL to be" , scenario .ExpectedURL , "got" , request .URL .String ())
318+ }
319+ body , _ := io .ReadAll (request .Body )
320+ if string (body ) != scenario .ExpectedBody {
321+ t .Error ("expected body to be" , scenario .ExpectedBody , "got" , string (body ))
322+ }
323+ })
324+ }
325+ }
326+
264327func TestAlertProvider_GetAlertStatePlaceholderValueDefaults (t * testing.T ) {
265328 alertProvider := & AlertProvider {
266329 DefaultConfig : Config {
0 commit comments