From 54b7010061eb2f43fd304af713641d7752a0ecfb Mon Sep 17 00:00:00 2001 From: Xiaonan Shen Date: Mon, 23 Dec 2024 20:44:11 +0800 Subject: [PATCH] test: add UT Signed-off-by: Xiaonan Shen --- controller/appcontroller_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/controller/appcontroller_test.go b/controller/appcontroller_test.go index 8c4c3b4d88341..70b3bc915668d 100644 --- a/controller/appcontroller_test.go +++ b/controller/appcontroller_test.go @@ -1409,6 +1409,25 @@ func TestNeedRefreshAppStatus(t *testing.T) { assert.Equal(t, CompareWithRecent, compareWith) }) + t.Run("requesting refresh with delay gives correct compression level", func(t *testing.T) { + needRefresh, _, _ := ctrl.needRefreshAppStatus(app, 1*time.Hour, 2*time.Hour) + assert.False(t, needRefresh) + + // use a one-off controller so other tests don't have a manual refresh request + ctrl := newFakeController(&fakeData{apps: []runtime.Object{}}, nil) + + // refresh app with a non-nil delay + // Use zero-second delay to test the add later logic without waiting in the test + delay := time.Duration(0) + ctrl.requestAppRefresh(app.Name, CompareWithRecent.Pointer(), &delay) + + ctrl.processAppComparisonTypeQueueItem() + needRefresh, refreshType, compareWith := ctrl.needRefreshAppStatus(app, 1*time.Hour, 2*time.Hour) + assert.True(t, needRefresh) + assert.Equal(t, v1alpha1.RefreshTypeNormal, refreshType) + assert.Equal(t, CompareWithRecent, compareWith) + }) + t.Run("refresh application which status is not reconciled using latest commit", func(t *testing.T) { app := app.DeepCopy() needRefresh, _, _ := ctrl.needRefreshAppStatus(app, 1*time.Hour, 2*time.Hour)