(t *testing.T)
| 1840 | } |
| 1841 | |
| 1842 | func TestNeedRefreshAppStatus(t *testing.T) { |
| 1843 | testCases := []struct { |
| 1844 | name string |
| 1845 | app *v1alpha1.Application |
| 1846 | }{ |
| 1847 | { |
| 1848 | name: "single-source app", |
| 1849 | app: newFakeApp(), |
| 1850 | }, |
| 1851 | { |
| 1852 | name: "multi-source app", |
| 1853 | app: newFakeMultiSourceApp(), |
| 1854 | }, |
| 1855 | } |
| 1856 | |
| 1857 | for _, tc := range testCases { |
| 1858 | t.Run(tc.name, func(t *testing.T) { |
| 1859 | app := tc.app |
| 1860 | now := metav1.Now() |
| 1861 | app.Status.ReconciledAt = &now |
| 1862 | |
| 1863 | app.Status.Sync = v1alpha1.SyncStatus{ |
| 1864 | Status: v1alpha1.SyncStatusCodeSynced, |
| 1865 | ComparedTo: v1alpha1.ComparedTo{ |
| 1866 | Destination: app.Spec.Destination, |
| 1867 | IgnoreDifferences: app.Spec.IgnoreDifferences, |
| 1868 | }, |
| 1869 | } |
| 1870 | |
| 1871 | if app.Spec.HasMultipleSources() { |
| 1872 | app.Status.Sync.ComparedTo.Sources = app.Spec.Sources |
| 1873 | } else { |
| 1874 | app.Status.Sync.ComparedTo.Source = app.Spec.GetSource() |
| 1875 | } |
| 1876 | |
| 1877 | ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{}}, nil) |
| 1878 | |
| 1879 | t.Run("no need to refresh just reconciled application", func(t *testing.T) { |
| 1880 | needRefresh, _, _ := ctrl.needRefreshAppStatus(app, 1*time.Hour, 2*time.Hour) |
| 1881 | assert.False(t, needRefresh) |
| 1882 | }) |
| 1883 | |
| 1884 | t.Run("requested refresh is respected", func(t *testing.T) { |
| 1885 | needRefresh, _, _ := ctrl.needRefreshAppStatus(app, 1*time.Hour, 2*time.Hour) |
| 1886 | assert.False(t, needRefresh) |
| 1887 | |
| 1888 | // use a one-off controller so other tests don't have a manual refresh request |
| 1889 | ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{}}, nil) |
| 1890 | |
| 1891 | // refresh app using the 'deepest' requested comparison level |
| 1892 | ctrl.requestAppRefresh(app.Name, CompareWithRecent.Pointer(), nil) |
| 1893 | ctrl.requestAppRefresh(app.Name, ComparisonWithNothing.Pointer(), nil) |
| 1894 | |
| 1895 | needRefresh, refreshType, compareWith := ctrl.needRefreshAppStatus(app, 1*time.Hour, 2*time.Hour) |
| 1896 | assert.True(t, needRefresh) |
| 1897 | assert.Equal(t, v1alpha1.RefreshTypeNormal, refreshType) |
| 1898 | assert.Equal(t, CompareWithRecent, compareWith) |
| 1899 | }) |
nothing calls this directly
no test coverage detected
searching dependent graphs…