Alerting: Add UID of rules to response that were affected by update group request (#75985)

* update storage's method InstertRules to return ids of added rules as slice to keep the same order as rules in the argument
* schematize response of update rule group endpoint, add created, updated, deleted fields that contain UID of affected rules.
* update integration tests to use the new fields
This commit is contained in:
Yuri Tseretyan
2023-10-06 18:11:24 -04:00
committed by GitHub
parent 6086a0916b
commit 2497db4bd6
16 changed files with 274 additions and 79 deletions

View File

@@ -524,7 +524,7 @@ func TestIntegrationAlertAndGroupsQuery(t *testing.T) {
},
}
status, _ := apiClient.PostRulesGroup(t, "default", &rules)
_, status, _ := apiClient.PostRulesGroupWithStatus(t, "default", &rules)
assert.Equal(t, http.StatusAccepted, status)
}
@@ -664,7 +664,7 @@ func TestIntegrationRulerAccess(t *testing.T) {
},
},
}
status, body := tc.client.PostRulesGroup(t, "default", &rules)
_, status, body := tc.client.PostRulesGroupWithStatus(t, "default", &rules)
assert.Equal(t, tc.expStatus, status)
res := &Response{}
err = json.Unmarshal([]byte(body), &res)
@@ -1097,7 +1097,7 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
tc.rule,
},
}
status, body := apiClient.PostRulesGroup(t, "default", &rules)
_, status, body := apiClient.PostRulesGroupWithStatus(t, "default", &rules)
res := &Response{}
err = json.Unmarshal([]byte(body), &res)
require.NoError(t, err)
@@ -1170,9 +1170,12 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
},
},
}
status, body := apiClient.PostRulesGroup(t, "default", &rules)
resp, status, _ := apiClient.PostRulesGroupWithStatus(t, "default", &rules)
assert.Equal(t, http.StatusAccepted, status)
require.JSONEq(t, `{"message":"rule group updated successfully"}`, body)
require.Equal(t, "rule group updated successfully", resp.Message)
assert.Len(t, resp.Created, 2)
assert.Empty(t, resp.Updated)
assert.Empty(t, resp.Deleted)
}
// With the rules created, let's make sure that rule definition is stored correctly.
@@ -1339,7 +1342,7 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
Interval: interval,
}
status, body := apiClient.PostRulesGroup(t, "default", &rules)
_, status, body := apiClient.PostRulesGroupWithStatus(t, "default", &rules)
assert.Equal(t, http.StatusNotFound, status)
var res map[string]any
assert.NoError(t, json.Unmarshal([]byte(body), &res))
@@ -1445,7 +1448,7 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
},
Interval: interval,
}
status, body := apiClient.PostRulesGroup(t, "default", &rules)
_, status, body := apiClient.PostRulesGroupWithStatus(t, "default", &rules)
assert.Equal(t, http.StatusBadRequest, status)
var res map[string]any
require.NoError(t, json.Unmarshal([]byte(body), &res))
@@ -1519,9 +1522,10 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
},
Interval: interval,
}
status, body := apiClient.PostRulesGroup(t, "default", &rules)
respModel, status, _ := apiClient.PostRulesGroupWithStatus(t, "default", &rules)
assert.Equal(t, http.StatusAccepted, status)
require.JSONEq(t, `{"message":"rule group updated successfully"}`, body)
require.Equal(t, respModel.Updated, []string{ruleUID})
require.Len(t, respModel.Deleted, 1)
// let's make sure that rule definitions are updated correctly.
u := fmt.Sprintf("http://grafana:password@%s/api/ruler/grafana/api/v1/rules/default", grafanaListedAddr)
@@ -1637,9 +1641,9 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
},
Interval: interval,
}
status, body := apiClient.PostRulesGroup(t, "default", &rules)
respModel, status, _ := apiClient.PostRulesGroupWithStatus(t, "default", &rules)
assert.Equal(t, http.StatusAccepted, status)
require.JSONEq(t, `{"message":"rule group updated successfully"}`, body)
require.Equal(t, respModel.Updated, []string{ruleUID})
// let's make sure that rule definitions are updated correctly.
u := fmt.Sprintf("http://grafana:password@%s/api/ruler/grafana/api/v1/rules/default", grafanaListedAddr)
@@ -1723,9 +1727,12 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
},
Interval: interval,
}
status, body := apiClient.PostRulesGroup(t, "default", &rules)
respModel, status, _ := apiClient.PostRulesGroupWithStatus(t, "default", &rules)
assert.Equal(t, http.StatusAccepted, status)
require.JSONEq(t, `{"message":"no changes detected in the rule group"}`, body)
require.Equal(t, "no changes detected in the rule group", respModel.Message)
assert.Empty(t, respModel.Created)
assert.Empty(t, respModel.Updated)
assert.Empty(t, respModel.Deleted)
// let's make sure that rule definitions are updated correctly.
u := fmt.Sprintf("http://grafana:password@%s/api/ruler/grafana/api/v1/rules/default", grafanaListedAddr)
@@ -1993,7 +2000,7 @@ func TestIntegrationQuota(t *testing.T) {
},
},
}
status, body := apiClient.PostRulesGroup(t, "default", &rules)
_, status, body := apiClient.PostRulesGroupWithStatus(t, "default", &rules)
assert.Equal(t, http.StatusForbidden, status)
var res map[string]any
require.NoError(t, json.Unmarshal([]byte(body), &res))
@@ -2030,9 +2037,9 @@ func TestIntegrationQuota(t *testing.T) {
},
}
status, body := apiClient.PostRulesGroup(t, "default", &rules)
respModel, status, _ := apiClient.PostRulesGroupWithStatus(t, "default", &rules)
assert.Equal(t, http.StatusAccepted, status)
require.JSONEq(t, `{"message":"rule group updated successfully"}`, body)
require.Len(t, respModel.Updated, 1)
// let's make sure that rule definitions are updated correctly.
u := fmt.Sprintf("http://grafana:password@%s/api/ruler/grafana/api/v1/rules/default", grafanaListedAddr)

View File

@@ -11,11 +11,12 @@ import (
"testing"
"time"
"github.com/grafana/grafana/pkg/expr"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/expr"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions"
"github.com/grafana/grafana/pkg/services/featuremgmt"
@@ -155,8 +156,10 @@ func TestIntegrationPrometheusRules(t *testing.T) {
b, err := io.ReadAll(resp.Body)
require.NoError(t, err)
assert.Equal(t, resp.StatusCode, 202)
require.JSONEq(t, `{"message":"rule group updated successfully"}`, string(b))
assert.Equal(t, http.StatusAccepted, resp.StatusCode)
var respModel apimodels.UpdateRuleGroupResponse
require.NoError(t, json.Unmarshal(b, &respModel))
require.Len(t, respModel.Created, len(rules.Rules))
}
// Check that we cannot create a rule that has a panel_id and no dashboard_uid
@@ -434,8 +437,10 @@ func TestIntegrationPrometheusRulesFilterByDashboard(t *testing.T) {
b, err := io.ReadAll(resp.Body)
require.NoError(t, err)
assert.Equal(t, resp.StatusCode, 202)
require.JSONEq(t, `{"message":"rule group updated successfully"}`, string(b))
assert.Equal(t, http.StatusAccepted, resp.StatusCode)
var respModel apimodels.UpdateRuleGroupResponse
require.NoError(t, json.Unmarshal(b, &respModel))
require.Len(t, respModel.Created, len(rules.Rules))
}
expectedAllJSON := fmt.Sprintf(`

View File

@@ -71,7 +71,7 @@ func TestIntegrationAlertRulePermissions(t *testing.T) {
require.NoError(t, json.Unmarshal(postGroupRaw, &group1))
// Create rule under folder1
status, response := apiClient.PostRulesGroup(t, "folder1", &group1)
_, status, response := apiClient.PostRulesGroupWithStatus(t, "folder1", &group1)
require.Equalf(t, http.StatusAccepted, status, response)
postGroupRaw, err = testData.ReadFile(path.Join("test-data", "rulegroup-2-post.json"))
@@ -80,7 +80,7 @@ func TestIntegrationAlertRulePermissions(t *testing.T) {
require.NoError(t, json.Unmarshal(postGroupRaw, &group2))
// Create rule under folder2
status, response = apiClient.PostRulesGroup(t, "folder2", &group2)
_, status, response = apiClient.PostRulesGroupWithStatus(t, "folder2", &group2)
require.Equalf(t, http.StatusAccepted, status, response)
// With the rules created, let's make sure that rule definitions are stored.
@@ -322,7 +322,7 @@ func TestIntegrationAlertRulePermissions(t *testing.T) {
})
}
func createRule(t *testing.T, client apiClient, folder string) apimodels.PostableRuleGroupConfig {
func createRule(t *testing.T, client apiClient, folder string) (apimodels.PostableRuleGroupConfig, string) {
t.Helper()
interval, err := model.ParseDuration("1m")
@@ -359,10 +359,10 @@ func createRule(t *testing.T, client apiClient, folder string) apimodels.Postabl
},
},
}
status, body := client.PostRulesGroup(t, folder, &rules)
resp, status, _ := client.PostRulesGroupWithStatus(t, folder, &rules)
assert.Equal(t, http.StatusAccepted, status)
require.JSONEq(t, `{"message":"rule group updated successfully"}`, body)
return rules
require.Len(t, resp.Created, 1)
return rules, resp.Created[0]
}
func TestAlertRulePostExport(t *testing.T) {
@@ -474,9 +474,9 @@ func TestIntegrationAlertRuleConflictingTitle(t *testing.T) {
rules := newTestingRuleConfig(t)
status, body := apiClient.PostRulesGroup(t, "folder1", &rules)
respModel, status, _ := apiClient.PostRulesGroupWithStatus(t, "folder1", &rules)
assert.Equal(t, http.StatusAccepted, status)
require.JSONEq(t, `{"message":"rule group updated successfully"}`, body)
require.Len(t, respModel.Created, len(rules.Rules))
// fetch the created rules, so we can get the uid's and trigger
// and update by reusing the uid's
@@ -487,7 +487,7 @@ func TestIntegrationAlertRuleConflictingTitle(t *testing.T) {
rulesWithUID := convertGettableRuleGroupToPostable(createdRuleGroup)
rulesWithUID.Rules = append(rulesWithUID.Rules, rules.Rules[0]) // Create new copy of first rule.
status, body := apiClient.PostRulesGroup(t, "folder1", &rulesWithUID)
_, status, body := apiClient.PostRulesGroupWithStatus(t, "folder1", &rulesWithUID)
assert.Equal(t, http.StatusInternalServerError, status)
var res map[string]any
@@ -499,7 +499,7 @@ func TestIntegrationAlertRuleConflictingTitle(t *testing.T) {
rulesWithUID := convertGettableRuleGroupToPostable(createdRuleGroup)
rulesWithUID.Rules[1].GrafanaManagedAlert.Title = "AlwaysFiring"
status, body := apiClient.PostRulesGroup(t, "folder1", &rulesWithUID)
_, status, body := apiClient.PostRulesGroupWithStatus(t, "folder1", &rulesWithUID)
assert.Equal(t, http.StatusInternalServerError, status)
var res map[string]any
@@ -509,9 +509,9 @@ func TestIntegrationAlertRuleConflictingTitle(t *testing.T) {
t.Run("trying to create alert with same title under another folder should succeed", func(t *testing.T) {
rules := newTestingRuleConfig(t)
status, body := apiClient.PostRulesGroup(t, "folder2", &rules)
resp, status, _ := apiClient.PostRulesGroupWithStatus(t, "folder2", &rules)
assert.Equal(t, http.StatusAccepted, status)
require.JSONEq(t, `{"message":"rule group updated successfully"}`, body)
require.Len(t, resp.Created, len(rules.Rules))
})
t.Run("trying to swap titles of existing alerts in the same folder should work", func(t *testing.T) {
@@ -521,9 +521,9 @@ func TestIntegrationAlertRuleConflictingTitle(t *testing.T) {
rulesWithUID.Rules[0].GrafanaManagedAlert.Title = title1
rulesWithUID.Rules[1].GrafanaManagedAlert.Title = title0
status, body := apiClient.PostRulesGroup(t, "folder1", &rulesWithUID)
resp, status, _ := apiClient.PostRulesGroupWithStatus(t, "folder1", &rulesWithUID)
assert.Equal(t, http.StatusAccepted, status)
require.JSONEq(t, `{"message":"rule group updated successfully"}`, body)
require.Len(t, resp.Updated, 2)
})
t.Run("trying to update titles of existing alerts in a chain in the same folder should work", func(t *testing.T) {
@@ -531,9 +531,9 @@ func TestIntegrationAlertRuleConflictingTitle(t *testing.T) {
rulesWithUID.Rules[0].GrafanaManagedAlert.Title = rulesWithUID.Rules[1].GrafanaManagedAlert.Title
rulesWithUID.Rules[1].GrafanaManagedAlert.Title = "something new"
status, body := apiClient.PostRulesGroup(t, "folder1", &rulesWithUID)
resp, status, _ := apiClient.PostRulesGroupWithStatus(t, "folder1", &rulesWithUID)
assert.Equal(t, http.StatusAccepted, status)
require.JSONEq(t, `{"message":"rule group updated successfully"}`, body)
require.Len(t, resp.Updated, len(rulesWithUID.Rules))
})
}
@@ -621,9 +621,9 @@ func TestIntegrationRulerRulesFilterByDashboard(t *testing.T) {
},
},
}
status, body := apiClient.PostRulesGroup(t, "default", &rules)
resp, status, _ := apiClient.PostRulesGroupWithStatus(t, "default", &rules)
assert.Equal(t, http.StatusAccepted, status)
require.JSONEq(t, `{"message":"rule group updated successfully"}`, body)
require.Len(t, resp.Created, len(rules.Rules))
}
expectedAllJSON := fmt.Sprintf(`
@@ -905,9 +905,9 @@ func TestIntegrationRuleGroupSequence(t *testing.T) {
group1 := generateAlertRuleGroup(5, alertRuleGen())
group2 := generateAlertRuleGroup(5, alertRuleGen())
status, _ := client.PostRulesGroup(t, folder1Title, &group1)
_, status, _ := client.PostRulesGroupWithStatus(t, folder1Title, &group1)
require.Equal(t, http.StatusAccepted, status)
status, _ = client.PostRulesGroup(t, folder1Title, &group2)
_, status, _ = client.PostRulesGroupWithStatus(t, folder1Title, &group2)
require.Equal(t, http.StatusAccepted, status)
t.Run("should persist order of the rules in a group", func(t *testing.T) {
@@ -930,7 +930,7 @@ func TestIntegrationRuleGroupSequence(t *testing.T) {
for _, rule := range postableGroup1.Rules {
expectedUids = append(expectedUids, rule.GrafanaManagedAlert.UID)
}
status, _ := client.PostRulesGroup(t, folder1Title, &postableGroup1)
_, status, _ := client.PostRulesGroupWithStatus(t, folder1Title, &postableGroup1)
require.Equal(t, http.StatusAccepted, status)
group1Get = client.GetRulesGroup(t, folder1Title, group1.Name)
@@ -956,7 +956,7 @@ func TestIntegrationRuleGroupSequence(t *testing.T) {
for _, rule := range postableGroup1.Rules {
expectedUids = append(expectedUids, rule.GrafanaManagedAlert.UID)
}
status, _ := client.PostRulesGroup(t, folder1Title, &postableGroup1)
_, status, _ := client.PostRulesGroupWithStatus(t, folder1Title, &postableGroup1)
require.Equal(t, http.StatusAccepted, status)
group1Get = client.GetRulesGroup(t, folder1Title, group1.Name)
@@ -1031,7 +1031,7 @@ func TestIntegrationRuleUpdate(t *testing.T) {
expected := model.Duration(10 * time.Second)
group.Rules[0].ApiRuleNode.For = &expected
status, body := client.PostRulesGroup(t, folder1Title, &group)
_, status, body := client.PostRulesGroupWithStatus(t, folder1Title, &group)
require.Equalf(t, http.StatusAccepted, status, "failed to post rule group. Response: %s", body)
getGroup := client.GetRulesGroup(t, folder1Title, group.Name)
require.Equal(t, expected, *getGroup.Rules[0].ApiRuleNode.For)
@@ -1039,7 +1039,7 @@ func TestIntegrationRuleUpdate(t *testing.T) {
group = convertGettableRuleGroupToPostable(getGroup.GettableRuleGroupConfig)
expected = 0
group.Rules[0].ApiRuleNode.For = &expected
status, body = client.PostRulesGroup(t, folder1Title, &group)
_, status, body = client.PostRulesGroupWithStatus(t, folder1Title, &group)
require.Equalf(t, http.StatusAccepted, status, "failed to post rule group. Response: %s", body)
getGroup = client.GetRulesGroup(t, folder1Title, group.Name)
@@ -1051,7 +1051,7 @@ func TestIntegrationRuleUpdate(t *testing.T) {
ds1 := adminClient.CreateTestDatasource(t)
group := generateAlertRuleGroup(3, alertRuleGen(withDatasourceQuery(ds1.Body.Datasource.UID)))
status, body := client.PostRulesGroup(t, folder1Title, &group)
_, status, body := client.PostRulesGroupWithStatus(t, folder1Title, &group)
require.Equalf(t, http.StatusAccepted, status, "failed to post rule group. Response: %s", body)
getGroup := client.GetRulesGroup(t, folder1Title, group.Name)
@@ -1071,7 +1071,7 @@ func TestIntegrationRuleUpdate(t *testing.T) {
getGroup := client.GetRulesGroup(t, folder1Title, groupName)
group := convertGettableRuleGroupToPostable(getGroup.GettableRuleGroupConfig)
status, body := client.PostRulesGroup(t, folder1Title, &group)
_, status, body := client.PostRulesGroupWithStatus(t, folder1Title, &group)
require.Equalf(t, http.StatusAccepted, status, "failed to post noop rule group. Response: %s", body)
})
t.Run("should not let update rule if it does not fix datasource", func(t *testing.T) {
@@ -1079,9 +1079,10 @@ func TestIntegrationRuleUpdate(t *testing.T) {
group := convertGettableRuleGroupToPostable(getGroup.GettableRuleGroupConfig)
group.Rules[0].GrafanaManagedAlert.Title = uuid.NewString()
status, body := client.PostRulesGroup(t, folder1Title, &group)
resp, status, body := client.PostRulesGroupWithStatus(t, folder1Title, &group)
if status == http.StatusAccepted {
assert.Len(t, resp.Deleted, 1)
getGroup = client.GetRulesGroup(t, folder1Title, group.Name)
assert.NotEqualf(t, group.Rules[0].GrafanaManagedAlert.Title, getGroup.Rules[0].GrafanaManagedAlert.Title, "group was updated")
}
@@ -1094,8 +1095,9 @@ func TestIntegrationRuleUpdate(t *testing.T) {
// remove the last rule.
group.Rules = group.Rules[0 : len(group.Rules)-1]
status, body := client.PostRulesGroup(t, folder1Title, &group)
resp, status, body := client.PostRulesGroupWithStatus(t, folder1Title, &group)
require.Equalf(t, http.StatusAccepted, status, "failed to delete last rule from group. Response: %s", body)
assert.Len(t, resp.Deleted, 1)
getGroup = client.GetRulesGroup(t, folder1Title, group.Name)
group = convertGettableRuleGroupToPostable(getGroup.GettableRuleGroupConfig)
@@ -1107,8 +1109,11 @@ func TestIntegrationRuleUpdate(t *testing.T) {
ds2 := adminClient.CreateTestDatasource(t)
withDatasourceQuery(ds2.Body.Datasource.UID)(&group.Rules[0])
status, body := client.PostRulesGroup(t, folder1Title, &group)
resp, status, body := client.PostRulesGroupWithStatus(t, folder1Title, &group)
require.Equalf(t, http.StatusAccepted, status, "failed to post noop rule group. Response: %s", body)
assert.Len(t, resp.Deleted, 0)
assert.Len(t, resp.Updated, 2)
assert.Len(t, resp.Created, 0)
getGroup = client.GetRulesGroup(t, folder1Title, group.Name)
group = convertGettableRuleGroupToPostable(getGroup.GettableRuleGroupConfig)
@@ -1217,8 +1222,9 @@ func TestIntegrationRulePause(t *testing.T) {
expectedIsPaused := true
group.Rules[0].GrafanaManagedAlert.IsPaused = &expectedIsPaused
status, body := client.PostRulesGroup(t, folder1Title, &group)
resp, status, body := client.PostRulesGroupWithStatus(t, folder1Title, &group)
require.Equalf(t, http.StatusAccepted, status, "failed to post rule group. Response: %s", body)
require.Len(t, resp.Created, 1)
getGroup := client.GetRulesGroup(t, folder1Title, group.Name)
require.Equalf(t, http.StatusAccepted, status, "failed to get rule group. Response: %s", body)
require.Equal(t, expectedIsPaused, getGroup.Rules[0].GrafanaManagedAlert.IsPaused)
@@ -1229,8 +1235,9 @@ func TestIntegrationRulePause(t *testing.T) {
expectedIsPaused := false
group.Rules[0].GrafanaManagedAlert.IsPaused = &expectedIsPaused
status, body := client.PostRulesGroup(t, folder1Title, &group)
resp, status, body := client.PostRulesGroupWithStatus(t, folder1Title, &group)
require.Equalf(t, http.StatusAccepted, status, "failed to post rule group. Response: %s", body)
require.Len(t, resp.Created, 1)
getGroup := client.GetRulesGroup(t, folder1Title, group.Name)
require.Equalf(t, http.StatusAccepted, status, "failed to get rule group. Response: %s", body)
require.Equal(t, expectedIsPaused, getGroup.Rules[0].GrafanaManagedAlert.IsPaused)
@@ -1240,8 +1247,9 @@ func TestIntegrationRulePause(t *testing.T) {
group := generateAlertRuleGroup(1, alertRuleGen())
group.Rules[0].GrafanaManagedAlert.IsPaused = nil
status, body := client.PostRulesGroup(t, folder1Title, &group)
resp, status, body := client.PostRulesGroupWithStatus(t, folder1Title, &group)
require.Equalf(t, http.StatusAccepted, status, "failed to post rule group. Response: %s", body)
require.Len(t, resp.Created, 1)
getGroup := client.GetRulesGroup(t, folder1Title, group.Name)
require.Equalf(t, http.StatusAccepted, status, "failed to get rule group. Response: %s", body)
require.False(t, getGroup.Rules[0].GrafanaManagedAlert.IsPaused)
@@ -1297,14 +1305,14 @@ func TestIntegrationRulePause(t *testing.T) {
group := generateAlertRuleGroup(1, alertRuleGen())
group.Rules[0].GrafanaManagedAlert.IsPaused = &tc.isPausedInDb
status, body := client.PostRulesGroup(t, folder1Title, &group)
_, status, body := client.PostRulesGroupWithStatus(t, folder1Title, &group)
require.Equalf(t, http.StatusAccepted, status, "failed to post rule group. Response: %s", body)
getGroup := client.GetRulesGroup(t, folder1Title, group.Name)
require.Equalf(t, http.StatusAccepted, status, "failed to get rule group. Response: %s", body)
group = convertGettableRuleGroupToPostable(getGroup.GettableRuleGroupConfig)
group.Rules[0].GrafanaManagedAlert.IsPaused = tc.isPausedInBody
status, body = client.PostRulesGroup(t, folder1Title, &group)
_, status, body = client.PostRulesGroupWithStatus(t, folder1Title, &group)
require.Equalf(t, http.StatusAccepted, status, "failed to post rule group. Response: %s", body)
getGroup = client.GetRulesGroup(t, folder1Title, group.Name)

View File

@@ -328,7 +328,7 @@ func (a apiClient) UpdateAlertRuleOrgQuota(t *testing.T, orgID int64, limit int6
assert.Equal(t, http.StatusOK, resp.StatusCode)
}
func (a apiClient) PostRulesGroup(t *testing.T, folder string, group *apimodels.PostableRuleGroupConfig) (int, string) {
func (a apiClient) PostRulesGroupWithStatus(t *testing.T, folder string, group *apimodels.PostableRuleGroupConfig) (apimodels.UpdateRuleGroupResponse, int, string) {
t.Helper()
buf := bytes.Buffer{}
enc := json.NewEncoder(&buf)
@@ -344,7 +344,11 @@ func (a apiClient) PostRulesGroup(t *testing.T, folder string, group *apimodels.
}()
b, err := io.ReadAll(resp.Body)
require.NoError(t, err)
return resp.StatusCode, string(b)
var m apimodels.UpdateRuleGroupResponse
if resp.StatusCode == http.StatusAccepted {
require.NoError(t, json.Unmarshal(b, &m))
}
return m, resp.StatusCode, string(b)
}
func (a apiClient) PostRulesExportWithStatus(t *testing.T, folder string, group *apimodels.PostableRuleGroupConfig, params *apimodels.ExportQueryParams) (int, string) {