Alerting: Fix flaky test (#55551) (#55673)

The length of the identifier from the underlying library is 9 or more characters depending on the rate at which the identifiers are generated. See https://pkg.go.dev/github.com/teris-io/shortid

The test previously made the assumption that the length will always be 10, which would intermittently fail.

(cherry picked from commit 647997cc4c)

Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2022-09-23 13:36:45 +02:00
committed by GitHub
co-authored by Emil Tullstedt
parent 8f5fbb88ac
commit c3275d23ff
@@ -110,8 +110,10 @@ func TestMakeAlertRule(t *testing.T) {
require.NoError(t, err)
require.Len(t, ar.Title, DefaultFieldMaxLength)
uniq := ar.Title[len(ar.Title)-11:]
require.Regexp(t, "^_.{10}$", uniq)
parts := strings.SplitN(ar.Title, "_", 2)
require.Len(t, parts, 2)
require.Greater(t, len(parts[1]), 8, "unique identifier should be longer than 9 characters")
require.Equal(t, DefaultFieldMaxLength-1, len(parts[0])+len(parts[1]), "truncated name + underscore + unique identifier should together be DefaultFieldMaxLength")
require.Equal(t, ar.Title, ar.RuleGroup)
})
})