1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-08-01 17:38:33 +00:00

[v11.0/forgejo] chore: sort mailer messages in test assertion (#8292)

**Backport:** https://codeberg.org/forgejo/forgejo/pulls/8226

- Ref https://codeberg.org/forgejo/forgejo/issues/8221#issuecomment-5461218
- Databases might return users in a different order, sort them before doing assertions on them.

Co-authored-by: Gusted <postmaster@gusted.xyz>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8292
Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This commit is contained in:
forgejo-backport-action 2025-06-26 08:14:22 +02:00 committed by Earl Warren
parent 956e1e8aac
commit 08b361ca29
2 changed files with 10 additions and 0 deletions

View file

@ -19,6 +19,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"strconv"
"strings"
"sync/atomic"
@ -40,6 +41,7 @@ import (
"forgejo.org/routers"
"forgejo.org/services/auth/source/remote"
gitea_context "forgejo.org/services/context"
"forgejo.org/services/mailer"
user_service "forgejo.org/services/user"
"forgejo.org/tests"
@ -691,3 +693,9 @@ func GetHTMLTitle(t testing.TB, session *TestSession, urlStr string) string {
doc := NewHTMLParser(t, resp.Body)
return doc.Find("head title").Text()
}
func SortMailerMessages(msgs []*mailer.Message) {
slices.SortFunc(msgs, func(a, b *mailer.Message) int {
return strings.Compare(b.To, a.To)
})
}

View file

@ -712,6 +712,7 @@ func TestPullRequestReplyMail(t *testing.T) {
called := false
defer test.MockVariableValue(&mailer.SendAsync, func(msgs ...*mailer.Message) {
assert.Len(t, msgs, 2)
SortMailerMessages(msgs)
assert.Equal(t, "user1@example.com", msgs[0].To)
assert.EqualValues(t, "Re: [user2/repo1] issue2 (PR #2)", msgs[0].Subject)
assert.Contains(t, msgs[0].Body, "Notification time!")
@ -740,6 +741,7 @@ func TestPullRequestReplyMail(t *testing.T) {
called := false
defer test.MockVariableValue(&mailer.SendAsync, func(msgs ...*mailer.Message) {
assert.Len(t, msgs, 2)
SortMailerMessages(msgs)
assert.Equal(t, "user1@example.com", msgs[0].To)
assert.EqualValues(t, "Re: [user2/repo1] issue2 (PR #2)", msgs[0].Subject)
assert.Contains(t, msgs[0].Body, "Notification time 2!")