diff --git a/pkg/sync/sync_context_test.go b/pkg/sync/sync_context_test.go index 6d3832279..9382fb78c 100644 --- a/pkg/sync/sync_context_test.go +++ b/pkg/sync/sync_context_test.go @@ -8,6 +8,7 @@ import ( "net/http/httptest" "reflect" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -25,7 +26,6 @@ import ( "github.com/argoproj/gitops-engine/pkg/diff" "github.com/argoproj/gitops-engine/pkg/health" - "github.com/argoproj/gitops-engine/pkg/sync/common" synccommon "github.com/argoproj/gitops-engine/pkg/sync/common" "github.com/argoproj/gitops-engine/pkg/utils/kube" "github.com/argoproj/gitops-engine/pkg/utils/kube/kubetest" @@ -568,7 +568,7 @@ func TestServerResourcesRetry(t *testing.T) { apiFailureCount: 0, expectedAPICalls: 1, expectedResources: 1, - expectedPhase: common.OperationSucceeded, + expectedPhase: synccommon.OperationSucceeded, expectedMessage: "success", }, { @@ -576,7 +576,7 @@ func TestServerResourcesRetry(t *testing.T) { apiFailureCount: 1, expectedAPICalls: 2, expectedResources: 1, - expectedPhase: common.OperationSucceeded, + expectedPhase: synccommon.OperationSucceeded, expectedMessage: "success", }, { @@ -584,7 +584,7 @@ func TestServerResourcesRetry(t *testing.T) { apiFailureCount: 2, expectedAPICalls: 3, expectedResources: 1, - expectedPhase: common.OperationSucceeded, + expectedPhase: synccommon.OperationSucceeded, expectedMessage: "success", }, { @@ -592,7 +592,7 @@ func TestServerResourcesRetry(t *testing.T) { apiFailureCount: 3, expectedAPICalls: 4, expectedResources: 1, - expectedPhase: common.OperationSucceeded, + expectedPhase: synccommon.OperationSucceeded, expectedMessage: "success", }, { @@ -600,7 +600,7 @@ func TestServerResourcesRetry(t *testing.T) { apiFailureCount: 4, expectedAPICalls: 5, expectedResources: 1, - expectedPhase: common.OperationSucceeded, + expectedPhase: synccommon.OperationSucceeded, expectedMessage: "success", }, { @@ -608,7 +608,7 @@ func TestServerResourcesRetry(t *testing.T) { apiFailureCount: 5, expectedAPICalls: 5, expectedResources: 1, - expectedPhase: common.OperationFailed, + expectedPhase: synccommon.OperationFailed, expectedMessage: "not valid", }, { @@ -617,7 +617,7 @@ func TestServerResourcesRetry(t *testing.T) { apiFailureCount: 1, expectedAPICalls: 1, expectedResources: 1, - expectedPhase: common.OperationFailed, + expectedPhase: synccommon.OperationFailed, expectedMessage: "not valid", }, } @@ -1029,8 +1029,25 @@ func TestSyncFailureHookWithFailedSync(t *testing.T) { func TestBeforeHookCreation(t *testing.T) { syncCtx := newTestSyncCtx() - hook := Annotate(Annotate(NewPod(), synccommon.AnnotationKeyHook, "Sync"), synccommon.AnnotationKeyHookDeletePolicy, "BeforeHookCreation") + syncCtx.startedAt = time.Date(2022, 9, 14, 0, 0, 0, 0, time.UTC) + previousCreatedAt := syncCtx.startedAt.Add(-time.Hour) + //newCreatedAt := syncCtx.startedAt.Add(time.Hour) + hook := NewPod() hook.SetNamespace(FakeArgoCDNamespace) + hook = Annotate(hook, synccommon.AnnotationKeyHook, string(synccommon.HookTypePreSync)) + hook = Annotate(hook, synccommon.AnnotationKeyHookDeletePolicy, string(synccommon.HookDeletePolicyBeforeHookCreation)) + hook.SetCreationTimestamp(metav1.NewTime(previousCreatedAt)) + hookKey := kube.GetResourceKey(hook) + syncCtx.syncRes[fmt.Sprintf("%s:%s", hookKey.String(), synccommon.HookTypePreSync)] = synccommon.ResourceSyncResult{ + ResourceKey: hookKey, + Version: hook.GroupVersionKind().Version, + Status: synccommon.ResultCodeSynced, + Message: "created", + HookType: synccommon.HookTypePreSync, + HookPhase: synccommon.OperationSucceeded, + SyncPhase: synccommon.SyncPhasePreSync, + Order: 1, + } syncCtx.resources = groupResources(ReconciliationResult{ Live: []*unstructured.Unstructured{hook}, Target: []*unstructured.Unstructured{nil},