logger_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2016 beego Author. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package logs
  15. import (
  16. "bytes"
  17. "testing"
  18. "time"
  19. )
  20. func TestFormatHeader_0(t *testing.T) {
  21. tm := time.Now()
  22. if tm.Year() >= 2100 {
  23. t.FailNow()
  24. }
  25. dur := time.Second
  26. for {
  27. if tm.Year() >= 2100 {
  28. break
  29. }
  30. h, _ := formatTimeHeader(tm)
  31. if tm.Format("2006/01/02 15:04:05 ") != string(h) {
  32. t.Log(tm)
  33. t.FailNow()
  34. }
  35. tm = tm.Add(dur)
  36. dur *= 2
  37. }
  38. }
  39. func TestFormatHeader_1(t *testing.T) {
  40. tm := time.Now()
  41. year := tm.Year()
  42. dur := time.Second
  43. for {
  44. if tm.Year() >= year+1 {
  45. break
  46. }
  47. h, _ := formatTimeHeader(tm)
  48. if tm.Format("2006/01/02 15:04:05 ") != string(h) {
  49. t.Log(tm)
  50. t.FailNow()
  51. }
  52. tm = tm.Add(dur)
  53. }
  54. }
  55. func TestNewAnsiColor1(t *testing.T) {
  56. inner := bytes.NewBufferString("")
  57. w := NewAnsiColorWriter(inner)
  58. if w == inner {
  59. t.Errorf("Get %#v, want %#v", w, inner)
  60. }
  61. }
  62. func TestNewAnsiColor2(t *testing.T) {
  63. inner := bytes.NewBufferString("")
  64. w1 := NewAnsiColorWriter(inner)
  65. w2 := NewAnsiColorWriter(w1)
  66. if w1 != w2 {
  67. t.Errorf("Get %#v, want %#v", w1, w2)
  68. }
  69. }