chore: smtp template and error handling for error@error.error
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/playwright Pipeline was successful
ci/woodpecker/push/deplyoment Pipeline was successful

This commit is contained in:
kekskurse 2025-03-13 23:48:42 +01:00
parent 12591859b8
commit 9f2c0f6b9c
4 changed files with 14 additions and 3 deletions

View file

@ -46,7 +46,7 @@ func TestRegistration(t *testing.T) {
password: "abc123d,.,jfhfh",
mail: "error@error.error",
exptErr: ErrCantSendMail,
exptErrString: "cant send mail: error mail send",
exptErrString: "cant send mail: cant send mail to error mail",
},
{
name: "success",

5
pkg/smtpclient/error.go Normal file
View file

@ -0,0 +1,5 @@
package smtpclient
import "errors"
var ErrCantSendMailToErrorMail = errors.New("cant send mail to error mail")

View file

@ -3,7 +3,6 @@ package smtpclient
import (
"bytes"
"embed"
"errors"
"fmt"
"html/template"
"strings"
@ -16,7 +15,7 @@ var templates embed.FS
func (s SMTPClient) SendMail(templateName string, to string, data any) error {
if to == "error@error.error" {
return errors.New("error mail send")
return ErrCantSendMailToErrorMail
}
return nil
}

View file

@ -6,6 +6,13 @@ import (
"github.com/stretchr/testify/assert"
)
func TestSendMailToErrorAddress(t *testing.T) {
smtp := NewDummySMTPClient()
err := smtp.SendMail("foobar", "error@error.error", nil)
assert.ErrorIs(t, ErrCantSendMailToErrorMail, err)
}
func TestRenderFile(t *testing.T) {
smtp := NewDummySMTPClient()
subject, err := smtp.renderFile("register.subject", nil)