Files
grafana/pkg/services/ngalert/api/tooling/definitions/provisioning_policies_test.go
Rodrigo Villablanca ab83bc7346 Alerting: Fix export of notification policy to JSON (#78021)
* Export Notification Policy correctly (#78020)

The JSON version of an exported Notification Policy now
inline correctly the policy in the same way the Yaml version
does.

Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
2023-12-04 16:57:37 -05:00

31 lines
688 B
Go

package definitions
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
func TestNotificationPolicyExportMarshal(t *testing.T) {
c := true
npe := &NotificationPolicyExport{
OrgID: 1,
RouteExport: &RouteExport{
Receiver: "receiver",
Continue: &c,
},
}
t.Run("json", func(t *testing.T) {
val, err := json.Marshal(npe)
require.NoError(t, err)
require.Equal(t, "{\"orgId\":1,\"receiver\":\"receiver\",\"continue\":true}", string(val))
})
t.Run("yaml", func(t *testing.T) {
val, err := yaml.Marshal(npe)
require.NoError(t, err)
require.Equal(t, "orgId: 1\nreceiver: receiver\ncontinue: true\n", string(val))
})
}