mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-28 19:45:41 +00:00
03df23d97c
* fix inaccruate 401 error on SQL db error
* init golangci-lint config
* linter autofix
* testify auto fixes
* fix sqlite busy errors
* fix naming
* more linter errors
* fix rest of linter issues
Former-commit-id: e8449b3a73
63 lines
948 B
Go
63 lines
948 B
Go
package mailer
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
const (
|
|
TestMailerConfig = "test-mailer.json"
|
|
)
|
|
|
|
func GetTestMailer() (*Mailer, error) {
|
|
// Read JSON File
|
|
bytes, err := os.ReadFile(TestMailerConfig)
|
|
|
|
mailer := &Mailer{}
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Unmarshal JSON
|
|
err = json.Unmarshal(bytes, mailer)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return mailer, nil
|
|
}
|
|
|
|
func Test_Mailer(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
mailer, err := GetTestMailer()
|
|
if err != nil {
|
|
t.Skip("Error Reading Test Mailer Config - Skipping")
|
|
}
|
|
|
|
if !mailer.Ready() {
|
|
t.Skip("Mailer not ready - Skipping")
|
|
}
|
|
|
|
message, err := RenderWelcome()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
mb := NewMessageBuilder().
|
|
SetBody(message).
|
|
SetSubject("Hello").
|
|
SetTo("John Doe", "john@doe.com").
|
|
SetFrom("Jane Doe", "jane@doe.com")
|
|
|
|
msg := mb.Build()
|
|
|
|
err = mailer.Send(msg)
|
|
|
|
require.NoError(t, err)
|
|
}
|