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.

event_format_test.go 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package log
  4. import (
  5. "testing"
  6. "time"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestItoa(t *testing.T) {
  10. b := itoa(nil, 0, 0)
  11. assert.Equal(t, "0", string(b))
  12. b = itoa(nil, 0, 1)
  13. assert.Equal(t, "0", string(b))
  14. b = itoa(nil, 0, 2)
  15. assert.Equal(t, "00", string(b))
  16. }
  17. func TestEventFormatTextMessage(t *testing.T) {
  18. res := EventFormatTextMessage(&WriterMode{Prefix: "[PREFIX] ", Colorize: false, Flags: Flags{defined: true, flags: 0xffffffff}},
  19. &Event{
  20. Time: time.Date(2020, 1, 2, 3, 4, 5, 6, time.UTC),
  21. Caller: "caller",
  22. Filename: "filename",
  23. Line: 123,
  24. GoroutinePid: "pid",
  25. Level: ERROR,
  26. Stacktrace: "stacktrace",
  27. },
  28. "msg format: %v %v", "arg0", NewColoredValue("arg1", FgBlue),
  29. )
  30. assert.Equal(t, `[PREFIX] 2020/01/02 03:04:05.000000 filename:123:caller [E] [pid] msg format: arg0 arg1
  31. stacktrace
  32. `, string(res))
  33. res = EventFormatTextMessage(&WriterMode{Prefix: "[PREFIX] ", Colorize: true, Flags: Flags{defined: true, flags: 0xffffffff}},
  34. &Event{
  35. Time: time.Date(2020, 1, 2, 3, 4, 5, 6, time.UTC),
  36. Caller: "caller",
  37. Filename: "filename",
  38. Line: 123,
  39. GoroutinePid: "pid",
  40. Level: ERROR,
  41. Stacktrace: "stacktrace",
  42. },
  43. "msg format: %v %v", "arg0", NewColoredValue("arg1", FgBlue),
  44. )
  45. assert.Equal(t, "[PREFIX] \x1b[36m2020/01/02 03:04:05.000000 \x1b[0m\x1b[32mfilename:123:\x1b[32mcaller\x1b[0m \x1b[1;31m[E]\x1b[0m [\x1b[93mpid\x1b[0m] msg format: arg0 \x1b[34marg1\x1b[0m\n\tstacktrace\n\n", string(res))
  46. }