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:
Santiago 2023-01-24 15:07:37 -03:00 committed by GitHub
parent 6ab79c4fba
commit e5920c211e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 8 deletions

View File

@ -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) {

View File

@ -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))],
},
}
}

View File

@ -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)

View File

@ -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

View File

@ -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