lg_test.go 740 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package lg
  2. import (
  3. "testing"
  4. "github.com/nsqio/nsq/internal/test"
  5. )
  6. type mockLogger struct {
  7. Count int
  8. }
  9. func (l *mockLogger) Output(maxdepth int, s string) error {
  10. l.Count++
  11. return nil
  12. }
  13. func TestLogging(t *testing.T) {
  14. logger := &mockLogger{}
  15. // Test only fatal get through
  16. logger.Count = 0
  17. for i := 1; i <= 5; i++ {
  18. Logf(logger, FATAL, LogLevel(i), "Test")
  19. }
  20. test.Equal(t, 1, logger.Count)
  21. // Test only warnings or higher get through
  22. logger.Count = 0
  23. for i := 1; i <= 5; i++ {
  24. Logf(logger, WARN, LogLevel(i), "Test")
  25. }
  26. test.Equal(t, 3, logger.Count)
  27. // Test everything gets through
  28. logger.Count = 0
  29. for i := 1; i <= 5; i++ {
  30. Logf(logger, DEBUG, LogLevel(i), "Test")
  31. }
  32. test.Equal(t, 5, logger.Count)
  33. }