rpclogger_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package internal
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/wuntsong-org/go-zero-plus/core/logx/logtest"
  6. )
  7. const content = "foo"
  8. func TestLoggerError(t *testing.T) {
  9. c := logtest.NewCollector(t)
  10. logger := new(Logger)
  11. logger.Error(content)
  12. assert.Contains(t, c.String(), content)
  13. }
  14. func TestLoggerErrorf(t *testing.T) {
  15. c := logtest.NewCollector(t)
  16. logger := new(Logger)
  17. logger.Errorf(content)
  18. assert.Contains(t, c.String(), content)
  19. }
  20. func TestLoggerErrorln(t *testing.T) {
  21. c := logtest.NewCollector(t)
  22. logger := new(Logger)
  23. logger.Errorln(content)
  24. assert.Contains(t, c.String(), content)
  25. }
  26. func TestLoggerFatal(t *testing.T) {
  27. c := logtest.NewCollector(t)
  28. logger := new(Logger)
  29. logger.Fatal(content)
  30. assert.Contains(t, c.String(), content)
  31. }
  32. func TestLoggerFatalf(t *testing.T) {
  33. c := logtest.NewCollector(t)
  34. logger := new(Logger)
  35. logger.Fatalf(content)
  36. assert.Contains(t, c.String(), content)
  37. }
  38. func TestLoggerFatalln(t *testing.T) {
  39. c := logtest.NewCollector(t)
  40. logger := new(Logger)
  41. logger.Fatalln(content)
  42. assert.Contains(t, c.String(), content)
  43. }
  44. func TestLoggerInfo(t *testing.T) {
  45. c := logtest.NewCollector(t)
  46. logger := new(Logger)
  47. logger.Info(content)
  48. assert.Empty(t, c.String())
  49. }
  50. func TestLoggerInfof(t *testing.T) {
  51. c := logtest.NewCollector(t)
  52. logger := new(Logger)
  53. logger.Infof(content)
  54. assert.Empty(t, c.String())
  55. }
  56. func TestLoggerWarning(t *testing.T) {
  57. c := logtest.NewCollector(t)
  58. logger := new(Logger)
  59. logger.Warning(content)
  60. assert.Empty(t, c.String())
  61. }
  62. func TestLoggerInfoln(t *testing.T) {
  63. c := logtest.NewCollector(t)
  64. logger := new(Logger)
  65. logger.Infoln(content)
  66. assert.Empty(t, c.String())
  67. }
  68. func TestLoggerWarningf(t *testing.T) {
  69. c := logtest.NewCollector(t)
  70. logger := new(Logger)
  71. logger.Warningf(content)
  72. assert.Empty(t, c.String())
  73. }
  74. func TestLoggerWarningln(t *testing.T) {
  75. c := logtest.NewCollector(t)
  76. logger := new(Logger)
  77. logger.Warningln(content)
  78. assert.Empty(t, c.String())
  79. }
  80. func TestLogger_V(t *testing.T) {
  81. logger := new(Logger)
  82. // grpclog.fatalLog
  83. assert.True(t, logger.V(3))
  84. // grpclog.infoLog
  85. assert.False(t, logger.V(0))
  86. }