test: tests Go para funciones email SMTP

Tests para builders puros (build_html, build_text, with_attachment),
template_render, smtp_connect y smtp_send con mock TCP server.
Todos los tests pasan: 18 casos cubriendo pureza, inmutabilidad y envio SMTP.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-13 02:01:18 +02:00
parent 53deb8e9a8
commit ab868bcea7
4 changed files with 443 additions and 0 deletions
@@ -0,0 +1,46 @@
package infra
import (
"strings"
"testing"
)
func TestEmailTemplateRender(t *testing.T) {
t.Run("renderiza template simple con datos", func(t *testing.T) {
got, err := EmailTemplateRender("Hola {{.Name}}", map[string]any{"Name": "Alice"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got != "Hola Alice" {
t.Errorf("got %q, want %q", got, "Hola Alice")
}
})
t.Run("sustituye multiples variables", func(t *testing.T) {
tmpl := "Pedido {{.OrderID}} para {{.Customer}} listo."
got, err := EmailTemplateRender(tmpl, map[string]any{"OrderID": "ORD-42", "Customer": "Bob"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !strings.Contains(got, "ORD-42") || !strings.Contains(got, "Bob") {
t.Errorf("got %q, expected OrderID and Customer", got)
}
})
t.Run("error en template invalido", func(t *testing.T) {
_, err := EmailTemplateRender("{{.Unclosed", nil)
if err == nil {
t.Error("expected error for invalid template, got nil")
}
})
t.Run("template vacio retorna string vacio", func(t *testing.T) {
got, err := EmailTemplateRender("", nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got != "" {
t.Errorf("got %q, want empty string", got)
}
})
}