更新
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
mailx "code.yun.ink/pkg/mailx"
|
||||
)
|
||||
|
||||
var _ mailx.Sender = (*Aliyun)(nil)
|
||||
|
||||
func TestConfigDefaults(t *testing.T) {
|
||||
a := New(Config{})
|
||||
if a.cfg.Endpoint != "dm.aliyuncs.com" {
|
||||
t.Errorf("default endpoint = %q, want dm.aliyuncs.com", a.cfg.Endpoint)
|
||||
}
|
||||
// 显式指定 Endpoint 时不应被覆盖
|
||||
a = New(Config{Endpoint: "dm.eu-central-1.aliyuncs.com"})
|
||||
if a.cfg.Endpoint != "dm.eu-central-1.aliyuncs.com" {
|
||||
t.Errorf("explicit endpoint overwritten: %q", a.cfg.Endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
func TestName(t *testing.T) {
|
||||
if got := New(Config{}).Name(); got != "aliyun" {
|
||||
t.Errorf("Name() = %q, want aliyun", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapSendStatus(t *testing.T) {
|
||||
cases := []struct {
|
||||
in int32
|
||||
want mailx.EmailSendStatus
|
||||
}{
|
||||
{0, mailx.EmailSendStatusSuccess},
|
||||
{2, mailx.EmailSendStatusInvalidAddress},
|
||||
{3, mailx.EmailSendStatusSpam},
|
||||
{4, mailx.EmailSendStatusFailed},
|
||||
{9, mailx.EmailSendStatusUnknown},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := mapSendStatus(c.in); got != c.want {
|
||||
t.Errorf("mapSendStatus(%d) = %v, want %v", c.in, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendWithoutConfig(t *testing.T) {
|
||||
// 缺少 AccountName 时应在发送前报错,而不是触发网络请求
|
||||
a := New(Config{AccessKeyID: "ak", AccessKeySecret: "sk"})
|
||||
err := a.Send(context.Background(), mailx.NewMessage().
|
||||
To("a@b.com").
|
||||
Subject("s").
|
||||
Build())
|
||||
if err == nil {
|
||||
t.Fatal("Send without AccountName should error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user