mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-06-27 21:00:05 +02:00
chore: sort mailer messages in test assertion (#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. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8226 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
ae00a1d61b
commit
5fa37539de
2 changed files with 10 additions and 0 deletions
|
@ -19,6 +19,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -40,6 +41,7 @@ import (
|
||||||
"forgejo.org/routers"
|
"forgejo.org/routers"
|
||||||
"forgejo.org/services/auth/source/remote"
|
"forgejo.org/services/auth/source/remote"
|
||||||
gitea_context "forgejo.org/services/context"
|
gitea_context "forgejo.org/services/context"
|
||||||
|
"forgejo.org/services/mailer"
|
||||||
user_service "forgejo.org/services/user"
|
user_service "forgejo.org/services/user"
|
||||||
"forgejo.org/tests"
|
"forgejo.org/tests"
|
||||||
|
|
||||||
|
@ -694,3 +696,9 @@ func GetHTMLTitle(t testing.TB, session *TestSession, urlStr string) string {
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
return doc.Find("head title").Text()
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -680,6 +680,7 @@ func TestPullRequestReplyMail(t *testing.T) {
|
||||||
called := false
|
called := false
|
||||||
defer test.MockVariableValue(&mailer.SendAsync, func(msgs ...*mailer.Message) {
|
defer test.MockVariableValue(&mailer.SendAsync, func(msgs ...*mailer.Message) {
|
||||||
assert.Len(t, msgs, 2)
|
assert.Len(t, msgs, 2)
|
||||||
|
SortMailerMessages(msgs)
|
||||||
assert.Equal(t, "user1@example.com", msgs[0].To)
|
assert.Equal(t, "user1@example.com", msgs[0].To)
|
||||||
assert.Equal(t, "Re: [user2/repo1] issue2 (PR #2)", msgs[0].Subject)
|
assert.Equal(t, "Re: [user2/repo1] issue2 (PR #2)", msgs[0].Subject)
|
||||||
assert.Contains(t, msgs[0].Body, "Notification time!")
|
assert.Contains(t, msgs[0].Body, "Notification time!")
|
||||||
|
@ -708,6 +709,7 @@ func TestPullRequestReplyMail(t *testing.T) {
|
||||||
called := false
|
called := false
|
||||||
defer test.MockVariableValue(&mailer.SendAsync, func(msgs ...*mailer.Message) {
|
defer test.MockVariableValue(&mailer.SendAsync, func(msgs ...*mailer.Message) {
|
||||||
assert.Len(t, msgs, 2)
|
assert.Len(t, msgs, 2)
|
||||||
|
SortMailerMessages(msgs)
|
||||||
assert.Equal(t, "user1@example.com", msgs[0].To)
|
assert.Equal(t, "user1@example.com", msgs[0].To)
|
||||||
assert.Equal(t, "Re: [user2/repo1] issue2 (PR #2)", msgs[0].Subject)
|
assert.Equal(t, "Re: [user2/repo1] issue2 (PR #2)", msgs[0].Subject)
|
||||||
assert.Contains(t, msgs[0].Body, "Notification time 2!")
|
assert.Contains(t, msgs[0].Body, "Notification time 2!")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue