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.

48 lines
918 B

  1. package log_test
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/require"
  5. "github.com/tendermint/tendermint/libs/log"
  6. )
  7. func TestNewDefaultLogger(t *testing.T) {
  8. testCases := map[string]struct {
  9. format string
  10. level string
  11. expectErr bool
  12. }{
  13. "invalid format": {
  14. format: "foo",
  15. level: log.LogLevelInfo,
  16. expectErr: true,
  17. },
  18. "invalid level": {
  19. format: log.LogFormatJSON,
  20. level: "foo",
  21. expectErr: true,
  22. },
  23. "valid format and level": {
  24. format: log.LogFormatJSON,
  25. level: log.LogLevelInfo,
  26. expectErr: false,
  27. },
  28. }
  29. for name, tc := range testCases {
  30. tc := tc
  31. t.Run(name, func(t *testing.T) {
  32. _, err := log.NewDefaultLogger(tc.format, tc.level)
  33. if tc.expectErr {
  34. require.Error(t, err)
  35. require.Panics(t, func() {
  36. _ = log.MustNewDefaultLogger(tc.format, tc.level)
  37. })
  38. } else {
  39. require.NoError(t, err)
  40. }
  41. })
  42. }
  43. }