AlertingNG: code refactoring (#30787)
* AlertingNG: refactoring * Fix tests
This commit is contained in:
@@ -9,18 +9,18 @@ import (
|
||||
)
|
||||
|
||||
func TestAlertInstanceOperations(t *testing.T) {
|
||||
ng := setupTestEnv(t)
|
||||
_, store := setupTestEnv(t, baseIntervalSeconds)
|
||||
|
||||
alertDefinition1 := createTestAlertDefinition(t, ng, 60)
|
||||
alertDefinition1 := createTestAlertDefinition(t, store, 60)
|
||||
orgID := alertDefinition1.OrgID
|
||||
|
||||
alertDefinition2 := createTestAlertDefinition(t, ng, 60)
|
||||
alertDefinition2 := createTestAlertDefinition(t, store, 60)
|
||||
require.Equal(t, orgID, alertDefinition2.OrgID)
|
||||
|
||||
alertDefinition3 := createTestAlertDefinition(t, ng, 60)
|
||||
alertDefinition3 := createTestAlertDefinition(t, store, 60)
|
||||
require.Equal(t, orgID, alertDefinition3.OrgID)
|
||||
|
||||
alertDefinition4 := createTestAlertDefinition(t, ng, 60)
|
||||
alertDefinition4 := createTestAlertDefinition(t, store, 60)
|
||||
require.Equal(t, orgID, alertDefinition4.OrgID)
|
||||
|
||||
t.Run("can save and read new alert instance", func(t *testing.T) {
|
||||
@@ -30,7 +30,7 @@ func TestAlertInstanceOperations(t *testing.T) {
|
||||
State: InstanceStateFiring,
|
||||
Labels: InstanceLabels{"test": "testValue"},
|
||||
}
|
||||
err := ng.saveAlertInstance(saveCmd)
|
||||
err := store.saveAlertInstance(saveCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
getCmd := &getAlertInstanceQuery{
|
||||
@@ -39,7 +39,7 @@ func TestAlertInstanceOperations(t *testing.T) {
|
||||
Labels: InstanceLabels{"test": "testValue"},
|
||||
}
|
||||
|
||||
err = ng.getAlertInstance(getCmd)
|
||||
err = store.getAlertInstance(getCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, saveCmd.Labels, getCmd.Result.Labels)
|
||||
@@ -53,7 +53,7 @@ func TestAlertInstanceOperations(t *testing.T) {
|
||||
DefinitionUID: alertDefinition2.UID,
|
||||
State: InstanceStateNormal,
|
||||
}
|
||||
err := ng.saveAlertInstance(saveCmd)
|
||||
err := store.saveAlertInstance(saveCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
getCmd := &getAlertInstanceQuery{
|
||||
@@ -61,7 +61,7 @@ func TestAlertInstanceOperations(t *testing.T) {
|
||||
DefinitionUID: saveCmd.DefinitionUID,
|
||||
}
|
||||
|
||||
err = ng.getAlertInstance(getCmd)
|
||||
err = store.getAlertInstance(getCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, alertDefinition2.OrgID, getCmd.Result.DefinitionOrgID)
|
||||
@@ -77,7 +77,7 @@ func TestAlertInstanceOperations(t *testing.T) {
|
||||
Labels: InstanceLabels{"test": "testValue"},
|
||||
}
|
||||
|
||||
err := ng.saveAlertInstance(saveCmdOne)
|
||||
err := store.saveAlertInstance(saveCmdOne)
|
||||
require.NoError(t, err)
|
||||
|
||||
saveCmdTwo := &saveAlertInstanceCommand{
|
||||
@@ -86,7 +86,7 @@ func TestAlertInstanceOperations(t *testing.T) {
|
||||
State: InstanceStateFiring,
|
||||
Labels: InstanceLabels{"test": "meow"},
|
||||
}
|
||||
err = ng.saveAlertInstance(saveCmdTwo)
|
||||
err = store.saveAlertInstance(saveCmdTwo)
|
||||
require.NoError(t, err)
|
||||
|
||||
listCommand := &listAlertInstancesQuery{
|
||||
@@ -94,7 +94,7 @@ func TestAlertInstanceOperations(t *testing.T) {
|
||||
DefinitionUID: saveCmdOne.DefinitionUID,
|
||||
}
|
||||
|
||||
err = ng.listAlertInstances(listCommand)
|
||||
err = store.listAlertInstances(listCommand)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, listCommand.Result, 2)
|
||||
@@ -105,7 +105,7 @@ func TestAlertInstanceOperations(t *testing.T) {
|
||||
DefinitionOrgID: orgID,
|
||||
}
|
||||
|
||||
err := ng.listAlertInstances(listCommand)
|
||||
err := store.listAlertInstances(listCommand)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, listCommand.Result, 4)
|
||||
@@ -117,7 +117,7 @@ func TestAlertInstanceOperations(t *testing.T) {
|
||||
State: InstanceStateNormal,
|
||||
}
|
||||
|
||||
err := ng.listAlertInstances(listCommand)
|
||||
err := store.listAlertInstances(listCommand)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, listCommand.Result, 1)
|
||||
@@ -131,7 +131,7 @@ func TestAlertInstanceOperations(t *testing.T) {
|
||||
Labels: InstanceLabels{"test": "testValue"},
|
||||
}
|
||||
|
||||
err := ng.saveAlertInstance(saveCmdOne)
|
||||
err := store.saveAlertInstance(saveCmdOne)
|
||||
require.NoError(t, err)
|
||||
|
||||
saveCmdTwo := &saveAlertInstanceCommand{
|
||||
@@ -140,7 +140,7 @@ func TestAlertInstanceOperations(t *testing.T) {
|
||||
State: InstanceStateNormal,
|
||||
Labels: InstanceLabels{"test": "testValue"},
|
||||
}
|
||||
err = ng.saveAlertInstance(saveCmdTwo)
|
||||
err = store.saveAlertInstance(saveCmdTwo)
|
||||
require.NoError(t, err)
|
||||
|
||||
listCommand := &listAlertInstancesQuery{
|
||||
@@ -148,7 +148,7 @@ func TestAlertInstanceOperations(t *testing.T) {
|
||||
DefinitionUID: alertDefinition4.UID,
|
||||
}
|
||||
|
||||
err = ng.listAlertInstances(listCommand)
|
||||
err = store.listAlertInstances(listCommand)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, listCommand.Result, 1)
|
||||
|
||||
Reference in New Issue
Block a user