diff --git a/controller/appcontroller_test.go b/controller/appcontroller_test.go index a515f36583edc..6e965fc8f0972 100644 --- a/controller/appcontroller_test.go +++ b/controller/appcontroller_test.go @@ -2408,15 +2408,65 @@ func TestAppStatusIsReplaced(t *testing.T) { func TestAlreadyAttemptSync(t *testing.T) { app := newFakeApp() + + t.Run("no operation state", func(t *testing.T) { + app := app.DeepCopy() + app.Status.OperationState = nil + attempted, _ := alreadyAttemptedSync(app, "", []string{}, false, false) + assert.False(t, attempted) + }) + + t.Run("no sync operation", func(t *testing.T) { + app := app.DeepCopy() + app.Status.OperationState.Operation.Sync = nil + attempted, _ := alreadyAttemptedSync(app, "", []string{}, false, false) + assert.False(t, attempted) + }) + + t.Run("no sync result", func(t *testing.T) { + app := app.DeepCopy() + app.Status.OperationState.SyncResult = nil + attempted, _ := alreadyAttemptedSync(app, "", []string{}, false, false) + assert.False(t, attempted) + }) + t.Run("same manifest with sync result", func(t *testing.T) { attempted, _ := alreadyAttemptedSync(app, "sha", []string{}, false, false) assert.True(t, attempted) }) - t.Run("different manifest with sync result", func(t *testing.T) { + t.Run("different manifest with sync result, different SHA", func(t *testing.T) { + app := app.DeepCopy() + app.Status.OperationState.SyncResult.Revision = "sha1" + attempted, _ := alreadyAttemptedSync(app, "sha2", []string{}, false, true) + assert.False(t, attempted) + }) + + t.Run("different manifest with sync result, same SHA", func(t *testing.T) { + app := app.DeepCopy() + app.Status.OperationState.SyncResult.Revision = "sha" attempted, _ := alreadyAttemptedSync(app, "sha", []string{}, false, true) + assert.True(t, attempted) + }) + + t.Run("same manifest with sync result", func(t *testing.T) { + attempted, _ := alreadyAttemptedSync(app, "", []string{"sha"}, true, false) + assert.True(t, attempted) + }) + + t.Run("different manifest with sync result, different SHAs", func(t *testing.T) { + app := app.DeepCopy() + app.Status.OperationState.SyncResult.Revisions = []string{"sha_a_=", "sha_b_1"} + attempted, _ := alreadyAttemptedSync(app, "", []string{"sha_a_2", "sha_b_2"}, true, true) assert.False(t, attempted) }) + + t.Run("different manifest with sync result, same SHAs", func(t *testing.T) { + app := app.DeepCopy() + app.Status.OperationState.SyncResult.Revisions = []string{"sha_a", "sha_b"} + attempted, _ := alreadyAttemptedSync(app, "", []string{"sha_a", "sha_b"}, true, true) + assert.True(t, attempted) + }) } func assertDurationAround(t *testing.T, expected time.Duration, actual time.Duration) {