feat: test secure
This commit is contained in:
parent
624a269454
commit
83ef9c2076
|
@ -146,3 +146,39 @@ func TestNewInsecure(t *testing.T) {
|
|||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSecure(t *testing.T) {
|
||||
cfg := newConfig(".env.test")
|
||||
|
||||
emailService := NewSecure(MailServiceConfig{
|
||||
Auth: smtp.PlainAuth("", cfg.MailUser, cfg.MailPassword, cfg.MailHost),
|
||||
Host: cfg.MailHost,
|
||||
Port: cfg.MailPort,
|
||||
From: cfg.MailFrom,
|
||||
})
|
||||
|
||||
// Assert that the tls.Config is set up correctly
|
||||
assert.NotNil(t, emailService.tlsconfig)
|
||||
assert.True(t, emailService.tlsconfig.InsecureSkipVerify)
|
||||
assert.Equal(t, cfg.MailHost, emailService.tlsconfig.ServerName)
|
||||
assert.NotNil(t, emailService.tlsconfig.VerifyConnection)
|
||||
|
||||
t.Run("TestSendEmail", func(t *testing.T) {
|
||||
// Mock the client and test the StartTLS method
|
||||
var called bool
|
||||
mockDialFn := func(hostPort string) (SMTPClientIface, error) {
|
||||
called = true
|
||||
return &mockSMTP{}, nil
|
||||
}
|
||||
emailService.dial = mockDialFn
|
||||
|
||||
data := EmailMessage{
|
||||
To: cfg.MailTo,
|
||||
Subject: "Mail Sender",
|
||||
Body: "Hello this is a test email",
|
||||
}
|
||||
require.NoError(t, emailService.SendEmail(data))
|
||||
assert.Equal(t, true, called)
|
||||
})
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue