func TestDaemonWorkerReDialCloseError(t *testing.T) { defer errLogBuf.Reset() dm, err := mail.NewDaemon( mail.SetConfig(configMock), mail.SetScope(config.ScopeID(4010)), mail.SetDialer( mockDial{ t: t, closeErr: errors.New("Test Close Error"), }, ), ) assert.NoError(t, err) assert.NotNil(t, dm) assert.False(t, dm.IsOffline()) go func() { assert.EqualError(t, dm.Worker(), "Test Close Error", "See goroutine") }() assert.NoError(t, dm.SendPlain("rust@lang", "apple@cupertino", "Spagetti", "Pastafari meets Rustafari")) time.Sleep(time.Millisecond * 100) assert.NoError(t, dm.Stop()) assert.Contains(t, errLogBuf.String(), "mail.daemon.workerDial.timeout.Close err: Test Close Error") }
func TestDaemonDaemonOptionErrors(t *testing.T) { dm, err := mail.NewDaemon( mail.SetConfig(nil), mail.SetDialer(nil), mail.SetSendFunc(nil), mail.SetSMTPTimeout(0), mail.SetTLSConfig(nil), mail.SetScope(nil), mail.SetMessageChannel(nil), ) assert.EqualError(t, err, "config.Reader cannot be nil\ngomail.Dialer cannot be nil\ngomail.SendFunc cannot be nil\nTime.Duration cannot be 0\n*tls.Config cannot be nil\nconfig.ScopeIDer cannot be nil\n*gomail.Message channel cannot be nil\n") assert.Nil(t, dm) }
func TestDaemonWorkerDialSend(t *testing.T) { dm, err := mail.NewDaemon( mail.SetConfig(configMock), mail.SetScope(config.ScopeID(4010)), mail.SetDialer( mockDial{t: t}, ), ) assert.NoError(t, err) assert.NotNil(t, dm) assert.False(t, dm.IsOffline()) go func() { assert.NoError(t, dm.Worker()) }() assert.NoError(t, dm.SendPlain("rust@lang", "apple@cupertino", "Spagetti", "Pastafari meets Rustafari")) assert.NoError(t, dm.Stop()) }