mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 04:04:00 -06:00
52a0f59706
* copy AlertQuery from ngmodels to the definition package * replaces usages of ngmodels.AlertQuery in API models * create a converter between models of AlertQuery --------- Co-authored-by: Alex Moreno <alexander.moreno@grafana.com>
38 lines
889 B
Go
38 lines
889 B
Go
package api
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
|
)
|
|
|
|
func TestToModel(t *testing.T) {
|
|
t.Run("if no rules are provided the rule field should be nil", func(t *testing.T) {
|
|
ruleGroup := definitions.AlertRuleGroup{
|
|
Title: "123",
|
|
FolderUID: "123",
|
|
Interval: 10,
|
|
}
|
|
tm, err := AlertRuleGroupFromApiAlertRuleGroup(ruleGroup)
|
|
require.NoError(t, err)
|
|
require.Nil(t, tm.Rules)
|
|
})
|
|
t.Run("if rules are provided the rule field should be not nil", func(t *testing.T) {
|
|
ruleGroup := definitions.AlertRuleGroup{
|
|
Title: "123",
|
|
FolderUID: "123",
|
|
Interval: 10,
|
|
Rules: []definitions.ProvisionedAlertRule{
|
|
{
|
|
UID: "1",
|
|
},
|
|
},
|
|
}
|
|
tm, err := AlertRuleGroupFromApiAlertRuleGroup(ruleGroup)
|
|
require.NoError(t, err)
|
|
require.Len(t, tm.Rules, 1)
|
|
})
|
|
}
|