You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
907 B

  1. package test
  2. import (
  3. "testing"
  4. "github.com/sirupsen/logrus"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestAllHooks(t *testing.T) {
  8. assert := assert.New(t)
  9. logger, hook := NewNullLogger()
  10. assert.Nil(hook.LastEntry())
  11. assert.Equal(0, len(hook.Entries))
  12. logger.Error("Hello error")
  13. assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level)
  14. assert.Equal("Hello error", hook.LastEntry().Message)
  15. assert.Equal(1, len(hook.Entries))
  16. logger.Warn("Hello warning")
  17. assert.Equal(logrus.WarnLevel, hook.LastEntry().Level)
  18. assert.Equal("Hello warning", hook.LastEntry().Message)
  19. assert.Equal(2, len(hook.Entries))
  20. hook.Reset()
  21. assert.Nil(hook.LastEntry())
  22. assert.Equal(0, len(hook.Entries))
  23. hook = NewGlobal()
  24. logrus.Error("Hello error")
  25. assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level)
  26. assert.Equal("Hello error", hook.LastEntry().Message)
  27. assert.Equal(1, len(hook.Entries))
  28. }