mirror of
https://github.com/grafana/grafana.git
synced 2025-01-15 19:22:34 -06:00
Chore: Fix random indices for slices in test files (#61884)
* Fix random indices for slices in test files * Empty commit
This commit is contained in:
parent
6ab79c4fba
commit
e5920c211e
@ -169,7 +169,7 @@ func TestReduceExecute(t *testing.T) {
|
||||
|
||||
func randomReduceFunc() string {
|
||||
res := mathexp.GetSupportedReduceFuncs()
|
||||
return res[rand.Intn(len(res)-1)]
|
||||
return res[rand.Intn(len(res))]
|
||||
}
|
||||
|
||||
func TestResampleCommand_Execute(t *testing.T) {
|
||||
|
@ -69,8 +69,8 @@ func validRule() apimodels.PostableExtendedRuleNode {
|
||||
},
|
||||
},
|
||||
UID: util.GenerateShortUID(),
|
||||
NoDataState: allNoData[rand.Intn(len(allNoData)-1)],
|
||||
ExecErrState: allExecError[rand.Intn(len(allExecError)-1)],
|
||||
NoDataState: allNoData[rand.Intn(len(allNoData))],
|
||||
ExecErrState: allExecError[rand.Intn(len(allExecError))],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -163,14 +163,15 @@ func Test_containsProvisionedAlerts(t *testing.T) {
|
||||
t.Run("should return true if at least one rule is provisioned", func(t *testing.T) {
|
||||
_, rules := models2.GenerateUniqueAlertRules(rand.Intn(4)+2, models2.AlertRuleGen())
|
||||
provenance := map[string]models2.Provenance{
|
||||
rules[rand.Intn(len(rules)-1)].UID: []models2.Provenance{models2.ProvenanceAPI, models2.ProvenanceFile}[rand.Intn(2)],
|
||||
rules[rand.Intn(len(rules))].UID: []models2.Provenance{models2.ProvenanceAPI, models2.ProvenanceFile}[rand.Intn(2)],
|
||||
}
|
||||
require.Truef(t, containsProvisionedAlerts(provenance, rules), "the group of rules is expected to be considered as provisioned but it isn't. Provenances: %v", provenance)
|
||||
})
|
||||
t.Run("should return false if map does not contain or has ProvenanceNone", func(t *testing.T) {
|
||||
_, rules := models2.GenerateUniqueAlertRules(rand.Intn(5)+1, models2.AlertRuleGen())
|
||||
provenance := make(map[string]models2.Provenance)
|
||||
for i := 0; i < rand.Intn(len(rules)); i++ {
|
||||
numProvenanceNone := rand.Intn(len(rules))
|
||||
for i := 0; i < numProvenanceNone; i++ {
|
||||
provenance[rules[i].UID] = models2.ProvenanceNone
|
||||
}
|
||||
require.Falsef(t, containsProvisionedAlerts(provenance, rules), "the group of rules is not expected to be provisioned but it is. Provenances: %v", provenance)
|
||||
|
@ -25,7 +25,7 @@ func AlertRuleGen(mutators ...AlertRuleMutator) func() *AlertRule {
|
||||
NoData,
|
||||
OK,
|
||||
}
|
||||
return s[rand.Intn(len(s)-1)]
|
||||
return s[rand.Intn(len(s))]
|
||||
}
|
||||
|
||||
randErrState := func() ExecutionErrorState {
|
||||
@ -34,7 +34,7 @@ func AlertRuleGen(mutators ...AlertRuleMutator) func() *AlertRule {
|
||||
ErrorErrState,
|
||||
OkErrState,
|
||||
}
|
||||
return s[rand.Intn(len(s)-1)]
|
||||
return s[rand.Intn(len(s))]
|
||||
}
|
||||
|
||||
interval := (rand.Int63n(6) + 1) * 10
|
||||
|
@ -328,7 +328,7 @@ func TestCalculateAutomaticChanges(t *testing.T) {
|
||||
group2 := models.GenerateGroupKey(orgID)
|
||||
rules2 := models.GenerateAlertRules(4, models.AlertRuleGen(withGroupKey(group2), models.WithSequentialGroupIndex()))
|
||||
|
||||
movedIndex := rand.Intn(len(rules2) - 1)
|
||||
movedIndex := rand.Intn(len(rules2))
|
||||
movedRule := rules2[movedIndex]
|
||||
copyRule := models.CopyRule(movedRule)
|
||||
copyRule.RuleGroup = group.RuleGroup
|
||||
|
Loading…
Reference in New Issue
Block a user