|
1 | 1 | package services
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "testing"
|
5 | 6 | "text/template"
|
6 | 7 |
|
@@ -159,3 +160,46 @@ func Test_AlertManagerNoLabels(t *testing.T) {
|
159 | 160 | err := svc.Send(n, Destination{})
|
160 | 161 | assert.EqualError(t, err, "alertmanager at least one label pair required")
|
161 | 162 | }
|
| 163 | + |
| 164 | +func Test_AlertManagerReusableTemplater(t *testing.T) { |
| 165 | + n := Notification{ |
| 166 | + Alertmanager: &AlertmanagerNotification{ |
| 167 | + Labels: map[string]string{ |
| 168 | + "alertname": "App_Deployed", |
| 169 | + "appname": "{{.app.metadata.name}}", |
| 170 | + }, |
| 171 | + Annotations: map[string]string{ |
| 172 | + "appname": "{{.app.metadata.name}}", |
| 173 | + }, |
| 174 | + }, |
| 175 | + } |
| 176 | + |
| 177 | + templater, err := n.GetTemplater("", template.FuncMap{}) |
| 178 | + if !assert.NoError(t, err) { |
| 179 | + return |
| 180 | + } |
| 181 | + |
| 182 | + for i := 0; i < 2; i++ { |
| 183 | + name := fmt.Sprintf("argocd-notifications-%d", i) |
| 184 | + var notification Notification |
| 185 | + err = templater(¬ification, map[string]interface{}{ |
| 186 | + "app": map[string]interface{}{ |
| 187 | + "metadata": map[string]interface{}{ |
| 188 | + "name": name, |
| 189 | + }, |
| 190 | + "spec": map[string]interface{}{ |
| 191 | + "source": map[string]interface{}{ |
| 192 | + "repoURL": "https://github.com/argoproj-labs/argocd-notifications.git", |
| 193 | + }, |
| 194 | + }, |
| 195 | + }, |
| 196 | + }) |
| 197 | + if !assert.NoError(t, err) { |
| 198 | + return |
| 199 | + } |
| 200 | + |
| 201 | + assert.Equal(t, "App_Deployed", notification.Alertmanager.Labels["alertname"]) |
| 202 | + assert.Equal(t, name, notification.Alertmanager.Labels["appname"]) |
| 203 | + assert.Equal(t, name, notification.Alertmanager.Annotations["appname"]) |
| 204 | + } |
| 205 | +} |
0 commit comments