Initial commit
CI / test (push) Canceled after 0s

This commit is contained in:
2026-09-12 22:22:17 +02:00
commit 904d14b64c
314 changed files with 31884 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
package mailer
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestFileModeAppendsMessages(t *testing.T) {
filePath := filepath.Join(t.TempDir(), "mails.log")
m, err := New(Config{
Mode: ModeFile,
Sender: "gardomatic@example.com",
FilePath: filePath,
})
if err != nil {
t.Fatalf("New() returned an error: %v", err)
}
data := map[string]any{
"userID": 42,
"activationToken": "test-token",
}
for _, recipient := range []string{"alice@example.com", "bob@example.com"} {
if err = m.Send(recipient, "user_welcome.tmpl", data); err != nil {
t.Fatalf("Send() returned an error: %v", err)
}
}
content, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("reading mail output: %v", err)
}
output := string(content)
if got := strings.Count(output, "=== gardomatic mail ==="); got != 2 {
t.Errorf("message count = %d, want 2", got)
}
for _, expected := range []string{
"alice@example.com",
"bob@example.com",
"Subject: Welcome to Gardomatic!",
"test-token",
} {
if !strings.Contains(output, expected) {
t.Errorf("output does not contain %q", expected)
}
}
}
func TestFileModeRequiresPath(t *testing.T) {
_, err := New(Config{Mode: ModeFile, Sender: "gardomatic@example.com"})
if err == nil {
t.Fatal("New() returned no error without a file path")
}
}
func TestNewRejectsUnknownMode(t *testing.T) {
_, err := New(Config{Mode: "unknown", Sender: "gardomatic@example.com"})
if err == nil {
t.Fatal("New() returned no error for an unknown mode")
}
}