Esempio n. 1
0
func TestDaemonOfflineLogger(t *testing.T) {
	offLog := mail.OfflineLogger
	defer func() {
		mail.OfflineLogger = offLog
	}()

	var logBufI bytes.Buffer
	var logBufE bytes.Buffer
	mail.OfflineLogger = log.NewStdLogger(
		log.SetStdLevel(log.StdLevelInfo),
		log.SetStdInfo(&logBufI, "test", std.LstdFlags),
		log.SetStdError(&logBufE, "test", std.LstdFlags),
	)

	dm, err := mail.NewDaemon()
	dm.Config = configMock
	dm.ScopeID = config.ScopeID(3001)

	assert.NoError(t, err)
	assert.NotNil(t, dm)
	assert.True(t, dm.IsOffline())

	go func() { assert.NoError(t, dm.Worker()) }()
	assert.NoError(t, dm.SendPlain("gopher@earth", "apple@mothership", "Phoning home", "Hey Apple stop phoning home or you become apple puree"))
	assert.NoError(t, dm.Stop())
	assert.True(t, mail.OfflineLogger.IsInfo())

	time.Sleep(time.Millisecond) // waiting for channel to drain

	assert.Contains(t, logBufI.String(), `Send from: "gopher@earth" to: []string{"apple@mothership"} msg: "Mime-Version: 1.0`)
	assert.Empty(t, logBufE.String())

}
Esempio n. 2
0
func TestStdLogger(t *testing.T) {

	var buf bytes.Buffer

	sl := log.NewStdLogger(
		log.SetStdLevel(log.StdLevelTrace),
		log.SetStdTrace(&buf, "TEST-TRACE ", std.LstdFlags),
		log.SetStdDebug(&buf, "TEST-DEBUG ", std.LstdFlags),
		log.SetStdInfo(&buf, "TEST-INFO ", std.LstdFlags),
		log.SetStdWarn(&buf, "TEST-WARN ", std.LstdFlags),
		log.SetStdError(&buf, "TEST-ERROR ", std.LstdFlags),
		log.SetStdFatal(&buf, "TEST-FATAL ", std.LstdFlags),
	)
	sl.SetLevel(log.StdLevelInfo)
	assert.False(t, sl.IsTrace())
	assert.False(t, sl.IsDebug())
	assert.True(t, sl.IsInfo())
	assert.True(t, sl.IsWarn())

	sl.Trace("my trace1")
	sl.Trace("my trace2", "int", 29)
	sl.Debug("my Debug", "float", 3.14152)
	sl.Debug("my Debug2", 2.14152)
	sl.Info("InfoTEST")
	sl.Warn("WarnTEST")
	haveErr := sl.Error("ErrorTEST", "err1a", 1, "err2", 32.4232)
	assert.Contains(t, "ErrorTEST53", sl.Error("ErrorTEST53").Error())
	logs := buf.String()

	assert.EqualError(t, haveErr, "ErrorTEST")
	assert.Contains(t, logs, "InfoTEST")
	assert.Contains(t, logs, "WarnTEST")
	assert.Contains(t, logs, "ErrorTEST")
	assert.NotContains(t, logs, "trace1")
	assert.NotContains(t, logs, "Debug2")

	buf.Reset()
	sl.SetLevel(log.StdLevelTrace)
	assert.True(t, sl.IsTrace())
	assert.True(t, sl.IsDebug())
	assert.True(t, sl.IsInfo())
	assert.True(t, sl.IsWarn())
	sl.Trace("my trace1")
	sl.Trace("my trace2", "int", 29)
	sl.Debug("my Debug", "float", 3.14152)
	sl.Debug("my Debug2", 2.14152)
	sl.Info("InfoTEST")

	logs = buf.String()

	assert.Contains(t, logs, "InfoTEST")
	assert.Contains(t, logs, "trace1")
	assert.Contains(t, logs, "Debug2")

}
Esempio n. 3
0
func init() {
	log.Set(log.NewStdLogger(
		log.SetStdError(&errLogBuf, "testErr: ", std.Lshortfile),
	))
	log.SetLevel(log.StdLevelError)
}
Esempio n. 4
0
func init() {
	log.Set(log.NewStdLogger(
		log.SetStdError(&errLogBuf, "testErr", std.LstdFlags),
	))
}