mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-01-28 20:56:03 +00:00
Implement couriers
This patch introduces the couriers, which the queue uses to deliver mail. We have a local courier (using procmail), a remote courier (uses SMTP), and a router courier that decides which of the two to use based on a list of local domains. There are still a few things pending, but they all have their basic functionality working and tested.
This commit is contained in:
44
internal/courier/courier_test.go
Normal file
44
internal/courier/courier_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package courier
|
||||
|
||||
import "testing"
|
||||
|
||||
// Counter courier, for testing purposes.
|
||||
type counter struct {
|
||||
c int
|
||||
}
|
||||
|
||||
func (c *counter) Deliver(from string, to string, data []byte) error {
|
||||
c.c++
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestRouter(t *testing.T) {
|
||||
localC := &counter{}
|
||||
remoteC := &counter{}
|
||||
r := Router{
|
||||
Local: localC,
|
||||
Remote: remoteC,
|
||||
LocalDomains: map[string]bool{
|
||||
"local1": true,
|
||||
"local2": true,
|
||||
},
|
||||
}
|
||||
|
||||
for domain, c := range map[string]int{
|
||||
"local1": 1,
|
||||
"local2": 2,
|
||||
"remote": 9,
|
||||
} {
|
||||
for i := 0; i < c; i++ {
|
||||
r.Deliver("from", "a@"+domain, nil)
|
||||
}
|
||||
}
|
||||
|
||||
if localC.c != 3 {
|
||||
t.Errorf("local mis-count: expected 3, got %d", localC.c)
|
||||
}
|
||||
|
||||
if remoteC.c != 9 {
|
||||
t.Errorf("remote mis-count: expected 9, got %d", remoteC.c)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user