backblaze-backup/internal/services/email/email_test.go

55 lines
1.1 KiB
Go
Raw Normal View History

package email
import (
"net/smtp"
"os"
"testing"
"gitea.urkob.com/urko/backblaze-backup/kit"
"gitea.urkob.com/urko/backblaze-backup/kit/config"
"github.com/stretchr/testify/require"
)
func Test_mailService_SendOK(t *testing.T) {
cfg := config.NewConfig(kit.RootDir() + "/.env.test")
mailSrv := NewMailService(MailServiceConfig{
Auth: smtp.PlainAuth("", cfg.MailUser, cfg.MailPassword, cfg.MailHost),
Host: cfg.MailHost,
Port: cfg.MailPort,
From: cfg.MailUser,
},
)
reader, err := os.Open("testdata/attachment1.txt")
require.NoError(t, err)
defer reader.Close()
reader2, err := os.Open("testdata/attachment2.txt")
require.NoError(t, err)
defer reader2.Close()
reader3, err := os.Open("testdata/attachment3.txt")
require.NoError(t, err)
defer reader3.Close()
data := EmailWithAttachments{
To: cfg.MailTo,
Attachments: []EmailAttachment{
{
Title: "attachment1.txt",
File: reader,
},
{
Title: "attachment2.txt",
File: reader2,
},
{
Title: "attachment3.txt",
File: reader3,
},
},
}
err = mailSrv.SendOK(data)
require.NoError(t, err)
}