2021-12-08 13:04:23 +05:30
|
|
|
// Copyright 2021 The Gogs Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2021-12-08 13:04:23 +05:30
|
|
|
|
|
|
|
package mailer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2024-04-18 15:41:12 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-12-08 13:04:23 +05:30
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2021-12-15 11:09:34 +05:30
|
|
|
|
2021-12-08 13:04:23 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGenerateMessageID(t *testing.T) {
|
2022-01-05 11:57:53 +05:30
|
|
|
mailService := setting.Mailer{
|
2021-12-11 01:13:28 +05:30
|
|
|
From: "test@gitea.com",
|
|
|
|
}
|
|
|
|
|
|
|
|
setting.MailService = &mailService
|
|
|
|
setting.Domain = "localhost"
|
2021-12-08 13:04:23 +05:30
|
|
|
|
2022-01-05 11:57:53 +05:30
|
|
|
date := time.Date(2000, 1, 2, 3, 4, 5, 6, time.UTC)
|
2023-01-22 19:53:52 +05:30
|
|
|
m := NewMessageFrom("", "display-name", "from-address", "subject", "body")
|
2021-12-08 13:04:23 +05:30
|
|
|
m.Date = date
|
|
|
|
gm := m.ToMessage()
|
|
|
|
assert.Equal(t, "<autogen-946782245000-41e8fc54a8ad3a3f@localhost>", gm.GetHeader("Message-ID")[0])
|
|
|
|
|
2023-01-22 19:53:52 +05:30
|
|
|
m = NewMessageFrom("a@b.com", "display-name", "from-address", "subject", "body")
|
2021-12-08 13:04:23 +05:30
|
|
|
m.Date = date
|
|
|
|
gm = m.ToMessage()
|
|
|
|
assert.Equal(t, "<autogen-946782245000-cc88ce3cfe9bd04f@localhost>", gm.GetHeader("Message-ID")[0])
|
|
|
|
|
2023-01-22 19:53:52 +05:30
|
|
|
m = NewMessageFrom("a@b.com", "display-name", "from-address", "subject", "body")
|
2021-12-08 13:04:23 +05:30
|
|
|
m.SetHeader("Message-ID", "<msg-d@domain.com>")
|
|
|
|
gm = m.ToMessage()
|
|
|
|
assert.Equal(t, "<msg-d@domain.com>", gm.GetHeader("Message-ID")[0])
|
|
|
|
}
|
2024-04-18 15:41:12 +05:30
|
|
|
|
|
|
|
func TestGenerateMessageIDForRelease(t *testing.T) {
|
|
|
|
setting.Domain = "localhost"
|
|
|
|
|
|
|
|
rel := repo_model.Release{
|
|
|
|
ID: 42,
|
|
|
|
Repo: &repo_model.Repository{
|
|
|
|
OwnerName: "test",
|
|
|
|
Name: "tag-test",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
m := createMessageIDForRelease(&rel)
|
|
|
|
assert.Equal(t, "<test/tag-test/releases/42@localhost>", m)
|
|
|
|
}
|