log_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2023 EMQ Technologies Co., Ltd.
  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 conf
  15. import (
  16. "testing"
  17. "time"
  18. "github.com/stretchr/testify/require"
  19. )
  20. func TestLogOutdated(t *testing.T) {
  21. now, err := time.Parse("2006-01-02_15-04-05", "2023-06-29_12-00-00")
  22. require.NoError(t, err)
  23. maxDuration := 24 * time.Hour
  24. testcases := []struct {
  25. name string
  26. remove bool
  27. }{
  28. {
  29. name: "stream.log",
  30. remove: false,
  31. },
  32. {
  33. name: "stream.log.2023-06-20_00-00-00",
  34. remove: true,
  35. },
  36. {
  37. name: "stream.log.2023-06-29_00-00-00",
  38. remove: false,
  39. },
  40. {
  41. name: "stream.log.2023-error",
  42. remove: false,
  43. },
  44. }
  45. for _, tc := range testcases {
  46. require.Equal(t, tc.remove, isLogOutdated(tc.name, now, maxDuration))
  47. }
  48. }