gitea源码

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package test
  4. import (
  5. "testing"
  6. "time"
  7. "code.gitea.io/gitea/modules/log"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestLogChecker(t *testing.T) {
  11. lc, cleanup := NewLogChecker(log.DEFAULT)
  12. defer cleanup()
  13. lc.Filter("First", "Third").StopMark("End")
  14. log.Info("test")
  15. filtered, stopped := lc.Check(100 * time.Millisecond)
  16. assert.ElementsMatch(t, []bool{false, false}, filtered)
  17. assert.False(t, stopped)
  18. log.Info("First")
  19. filtered, stopped = lc.Check(100 * time.Millisecond)
  20. assert.ElementsMatch(t, []bool{true, false}, filtered)
  21. assert.False(t, stopped)
  22. log.Info("Second")
  23. filtered, stopped = lc.Check(100 * time.Millisecond)
  24. assert.ElementsMatch(t, []bool{true, false}, filtered)
  25. assert.False(t, stopped)
  26. log.Info("Third")
  27. filtered, stopped = lc.Check(100 * time.Millisecond)
  28. assert.ElementsMatch(t, []bool{true, true}, filtered)
  29. assert.False(t, stopped)
  30. log.Info("End")
  31. filtered, stopped = lc.Check(100 * time.Millisecond)
  32. assert.ElementsMatch(t, []bool{true, true}, filtered)
  33. assert.True(t, stopped)
  34. }