mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Goconvey migration for cleanup package (#40547)
This commit is contained in:
parent
7bad00118a
commit
e47d7532e5
@ -5,37 +5,33 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCleanUpTmpFiles(t *testing.T) {
|
||||
Convey("Cleanup service tests", t, func() {
|
||||
cfg := setting.Cfg{}
|
||||
cfg.TempDataLifetime, _ = time.ParseDuration("24h")
|
||||
service := CleanUpService{
|
||||
Cfg: &cfg,
|
||||
}
|
||||
now := time.Now()
|
||||
secondAgo := now.Add(-time.Second)
|
||||
twoDaysAgo := now.Add(-time.Second * 3600 * 24 * 2)
|
||||
weekAgo := now.Add(-time.Second * 3600 * 24 * 7)
|
||||
cfg := setting.Cfg{}
|
||||
cfg.TempDataLifetime, _ = time.ParseDuration("24h")
|
||||
service := CleanUpService{
|
||||
Cfg: &cfg,
|
||||
}
|
||||
now := time.Now()
|
||||
secondAgo := now.Add(-time.Second)
|
||||
twoDaysAgo := now.Add(-time.Second * 3600 * 24 * 2)
|
||||
weekAgo := now.Add(-time.Second * 3600 * 24 * 7)
|
||||
t.Run("Should not cleanup recent files", func(t *testing.T) {
|
||||
require.False(t, service.shouldCleanupTempFile(secondAgo, now))
|
||||
})
|
||||
t.Run("Should cleanup older files", func(t *testing.T) {
|
||||
require.True(t, service.shouldCleanupTempFile(twoDaysAgo, now))
|
||||
})
|
||||
|
||||
Convey("Should not cleanup recent files", func() {
|
||||
So(service.shouldCleanupTempFile(secondAgo, now), ShouldBeFalse)
|
||||
})
|
||||
t.Run("After increasing temporary files lifetime, older files should be kept", func(t *testing.T) {
|
||||
cfg.TempDataLifetime, _ = time.ParseDuration("1000h")
|
||||
require.False(t, service.shouldCleanupTempFile(weekAgo, now))
|
||||
})
|
||||
|
||||
Convey("Should cleanup older files", func() {
|
||||
So(service.shouldCleanupTempFile(twoDaysAgo, now), ShouldBeTrue)
|
||||
})
|
||||
|
||||
Convey("After increasing temporary files lifetime, older files should be kept", func() {
|
||||
cfg.TempDataLifetime, _ = time.ParseDuration("1000h")
|
||||
So(service.shouldCleanupTempFile(weekAgo, now), ShouldBeFalse)
|
||||
})
|
||||
|
||||
Convey("If lifetime is 0, files should never be cleaned up", func() {
|
||||
cfg.TempDataLifetime = 0
|
||||
So(service.shouldCleanupTempFile(weekAgo, now), ShouldBeFalse)
|
||||
})
|
||||
t.Run("If lifetime is 0, files should never be cleaned up", func(t *testing.T) {
|
||||
cfg.TempDataLifetime = 0
|
||||
require.False(t, service.shouldCleanupTempFile(weekAgo, now))
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user