1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

test: Add small miscellaneous tests

This patch extends various packages and integration tests, increasing
test coverage. They're small enough that it's not worth splitting them
up, as it would add a lot of noise to the history.
This commit is contained in:
Alberto Bertogli
2018-03-02 16:14:10 +00:00
parent d80c76f746
commit 0611b7a7fc
7 changed files with 149 additions and 9 deletions

View File

@@ -141,6 +141,9 @@ func TestDSNOnTimeout(t *testing.T) {
t.Errorf("failed to write item: %v", err)
}
// Exercise DumpString while at it.
q.DumpString()
// Launch the sending loop, expect 1 local delivery (the DSN).
localC.wg.Add(1)
go item.SendLoop(q)
@@ -296,3 +299,43 @@ func TestNextDelay(t *testing.T) {
}
}
}
func TestSerialization(t *testing.T) {
dir := testlib.MustTempDir(t)
defer testlib.RemoveIfOk(t, dir)
// Save an item in the queue directory.
item := &Item{
Message: Message{
ID: <-newID,
From: fmt.Sprintf("from@loco"),
Rcpt: []*Recipient{
{"to@to", Recipient_EMAIL, Recipient_PENDING, "err", "to@to"}},
Data: []byte("data"),
},
CreatedAt: time.Now().Add(-1 * time.Hour),
}
err := item.WriteTo(dir)
if err != nil {
t.Errorf("failed to write item: %v", err)
}
// Create the queue; should load the
remoteC := newTestCourier()
remoteC.wg.Add(1)
q := New(dir, set.NewString("loco"), aliases.NewResolver(),
dumbCourier, remoteC)
q.Load()
// Launch the sending loop, expect 1 remote delivery for the item we saved.
remoteC.wg.Wait()
req := remoteC.reqFor["to@to"]
if req == nil {
t.Fatal("email not delivered")
}
if req.from != "from@loco" || req.to != "to@to" {
t.Errorf("wrong email: %v", req)
}
}