Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v9.3.x] Alerting: Enable interpolation for notification policies in …
…file provisioning (#59140) Alerting: Enable interpolation for notification policies in file provisioning (#58956) (cherry picked from commit 41b3398) Co-authored-by: Jean-Philippe Quéméner <JohnnyQQQQ@users.noreply.github.com>
- Loading branch information
1 parent
692bd0a
commit a2263b9
Showing
3 changed files
with
82 additions
and
10 deletions.
There are no files selected for viewing
42 changes: 35 additions & 7 deletions
42
pkg/services/provisioning/alerting/notification_policy_types.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
pkg/services/provisioning/alerting/notification_policy_types_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package alerting | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"gopkg.in/yaml.v2" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNotificationPolicy(t *testing.T) { | ||
const ( | ||
envKey = "NOTIFIER_EMAIL_REMINDER_FREQUENCY" | ||
envValue = "4h" | ||
) | ||
err := os.Setenv(envKey, envValue) | ||
require.NoError(t, err) | ||
defer func() { | ||
_ = os.Unsetenv(envKey) | ||
}() | ||
data := `orgId: 123 | ||
receiver: test | ||
continue: true | ||
repeat_interval: ${NOTIFIER_EMAIL_REMINDER_FREQUENCY} | ||
` | ||
var model NotificiationPolicyV1 | ||
|
||
err = yaml.Unmarshal([]byte(data), &model) | ||
require.NoError(t, err) | ||
np, err := model.mapToModel() | ||
require.NoError(t, err) | ||
require.Equal(t, int64(123), np.OrgID) | ||
require.Equal(t, "test", np.Policy.Receiver) | ||
require.True(t, np.Policy.Continue) | ||
require.Equal(t, envValue, np.Policy.RepeatInterval.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters