Add answer worker
Subsystem for message processing: parses messages, generates LLM responses, and replies with SMTP. Introduces: - answer: message processing worker. - llm: OpenAI API compatible client with support for tool execution. - message: message parsing and response logic. - tool: converts YAML configuration into executable subprocesses. - smtp: simple config and client wrapper for sending email.
This commit is contained in:
111
internal/smtp/smtp_test.go
Normal file
111
internal/smtp/smtp_test.go
Normal file
@@ -0,0 +1,111 @@
|
||||
package smtp
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAddress(t *testing.T) {
|
||||
s := &SMTP{
|
||||
Host: "smtp.example.com",
|
||||
Port: "587",
|
||||
}
|
||||
expected := "smtp.example.com:587"
|
||||
if got := s.Address(); got != expected {
|
||||
t.Errorf("Address() = %q, want %q", got, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuth(t *testing.T) {
|
||||
s := &SMTP{
|
||||
User: "user",
|
||||
Password: "password",
|
||||
Host: "smtp.example.com",
|
||||
}
|
||||
|
||||
// Verify return of non-nil Auth mechanism.
|
||||
if got := s.Auth(); got == nil {
|
||||
t.Error("Auth() returned nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
s *SMTP
|
||||
shouldError bool
|
||||
}{
|
||||
{
|
||||
name: "valid configuration",
|
||||
s: &SMTP{
|
||||
From: "sender@example.com",
|
||||
Host: "smtp.example.com",
|
||||
Password: "secretpassword",
|
||||
Port: "587",
|
||||
User: "user",
|
||||
},
|
||||
shouldError: false,
|
||||
},
|
||||
{
|
||||
name: "missing from",
|
||||
s: &SMTP{
|
||||
Host: "smtp.example.com",
|
||||
Password: "p",
|
||||
Port: "587",
|
||||
User: "u",
|
||||
},
|
||||
shouldError: true,
|
||||
},
|
||||
{
|
||||
name: "missing host",
|
||||
s: &SMTP{
|
||||
From: "f",
|
||||
Password: "p",
|
||||
Port: "587",
|
||||
User: "u",
|
||||
},
|
||||
shouldError: true,
|
||||
},
|
||||
{
|
||||
name: "missing password",
|
||||
s: &SMTP{
|
||||
From: "f",
|
||||
Host: "h",
|
||||
Port: "587",
|
||||
User: "u",
|
||||
},
|
||||
shouldError: true,
|
||||
},
|
||||
{
|
||||
name: "missing port",
|
||||
s: &SMTP{
|
||||
From: "f",
|
||||
Host: "h",
|
||||
Password: "p",
|
||||
User: "u",
|
||||
},
|
||||
shouldError: true,
|
||||
},
|
||||
{
|
||||
name: "missing user",
|
||||
s: &SMTP{
|
||||
From: "f",
|
||||
Host: "h",
|
||||
Password: "p",
|
||||
Port: "587",
|
||||
},
|
||||
shouldError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := tt.s.Validate()
|
||||
if tt.shouldError && err == nil {
|
||||
t.Fatalf("expected error, got nil")
|
||||
}
|
||||
if !tt.shouldError && err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user