package mail import ( "strings" "testing" ) // Both checks must fail cleanly (error, no panic) against an unroutable host. // 127.0.0.1:1 has nothing listening, so the dial fails fast. func TestCheckIMAPFailsCleanly(t *testing.T) { err := CheckIMAP(IMAPConfig{Host: "127.0.0.1", Port: 1, Security: "tls", Username: "u", Password: "p"}) if err == nil { t.Fatal("expected connection error") } } func TestCheckSMTPFailsCleanly(t *testing.T) { err := CheckSMTP(SMTPConfig{Host: "127.0.0.1", Port: 1, Security: "tls", Username: "u", Password: "p"}) if err == nil { t.Fatal("expected connection error") } } func TestCheckSMTPRejectsUnknownSecurity(t *testing.T) { err := CheckSMTP(SMTPConfig{Host: "127.0.0.1", Port: 1, Security: "bogus"}) if err == nil || !strings.Contains(err.Error(), "security") { t.Fatalf("want security error, got %v", err) } }