rpclogger_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package internal
  2. import (
  3. "log"
  4. "strings"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. const content = "foo"
  9. func TestLoggerError(t *testing.T) {
  10. var builder strings.Builder
  11. log.SetOutput(&builder)
  12. logger := new(Logger)
  13. logger.Error(content)
  14. assert.Contains(t, builder.String(), content)
  15. }
  16. func TestLoggerErrorf(t *testing.T) {
  17. var builder strings.Builder
  18. log.SetOutput(&builder)
  19. logger := new(Logger)
  20. logger.Errorf(content)
  21. assert.Contains(t, builder.String(), content)
  22. }
  23. func TestLoggerErrorln(t *testing.T) {
  24. var builder strings.Builder
  25. log.SetOutput(&builder)
  26. logger := new(Logger)
  27. logger.Errorln(content)
  28. assert.Contains(t, builder.String(), content)
  29. }
  30. func TestLoggerFatal(t *testing.T) {
  31. var builder strings.Builder
  32. log.SetOutput(&builder)
  33. logger := new(Logger)
  34. logger.Fatal(content)
  35. assert.Contains(t, builder.String(), content)
  36. }
  37. func TestLoggerFatalf(t *testing.T) {
  38. var builder strings.Builder
  39. log.SetOutput(&builder)
  40. logger := new(Logger)
  41. logger.Fatalf(content)
  42. assert.Contains(t, builder.String(), content)
  43. }
  44. func TestLoggerFatalln(t *testing.T) {
  45. var builder strings.Builder
  46. log.SetOutput(&builder)
  47. logger := new(Logger)
  48. logger.Fatalln(content)
  49. assert.Contains(t, builder.String(), content)
  50. }
  51. func TestLoggerWarning(t *testing.T) {
  52. var builder strings.Builder
  53. log.SetOutput(&builder)
  54. logger := new(Logger)
  55. logger.Warning(content)
  56. assert.Empty(t, builder.String())
  57. }
  58. func TestLoggerWarningf(t *testing.T) {
  59. var builder strings.Builder
  60. log.SetOutput(&builder)
  61. logger := new(Logger)
  62. logger.Warningf(content)
  63. assert.Empty(t, builder.String())
  64. }
  65. func TestLoggerWarningln(t *testing.T) {
  66. var builder strings.Builder
  67. log.SetOutput(&builder)
  68. logger := new(Logger)
  69. logger.Warningln(content)
  70. assert.Empty(t, builder.String())
  71. }