Skip to content

Commit 4382fe9

Browse files
committed
WIP: thoroughly test BeforeHookCreation
Signed-off-by: Krzysztof Nazarewski <3494992+nazarewk@users.noreply.github.com>
1 parent 327f8d9 commit 4382fe9

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

pkg/sync/sync_context_test.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http/httptest"
99
"reflect"
1010
"testing"
11+
"time"
1112

1213
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"
@@ -25,7 +26,6 @@ import (
2526

2627
"github.com/argoproj/gitops-engine/pkg/diff"
2728
"github.com/argoproj/gitops-engine/pkg/health"
28-
"github.com/argoproj/gitops-engine/pkg/sync/common"
2929
synccommon "github.com/argoproj/gitops-engine/pkg/sync/common"
3030
"github.com/argoproj/gitops-engine/pkg/utils/kube"
3131
"github.com/argoproj/gitops-engine/pkg/utils/kube/kubetest"
@@ -568,47 +568,47 @@ func TestServerResourcesRetry(t *testing.T) {
568568
apiFailureCount: 0,
569569
expectedAPICalls: 1,
570570
expectedResources: 1,
571-
expectedPhase: common.OperationSucceeded,
571+
expectedPhase: synccommon.OperationSucceeded,
572572
expectedMessage: "success",
573573
},
574574
{
575575
desc: "will return success after 1 api failure attempt",
576576
apiFailureCount: 1,
577577
expectedAPICalls: 2,
578578
expectedResources: 1,
579-
expectedPhase: common.OperationSucceeded,
579+
expectedPhase: synccommon.OperationSucceeded,
580580
expectedMessage: "success",
581581
},
582582
{
583583
desc: "will return success after 2 api failure attempt",
584584
apiFailureCount: 2,
585585
expectedAPICalls: 3,
586586
expectedResources: 1,
587-
expectedPhase: common.OperationSucceeded,
587+
expectedPhase: synccommon.OperationSucceeded,
588588
expectedMessage: "success",
589589
},
590590
{
591591
desc: "will return success after 3 api failure attempt",
592592
apiFailureCount: 3,
593593
expectedAPICalls: 4,
594594
expectedResources: 1,
595-
expectedPhase: common.OperationSucceeded,
595+
expectedPhase: synccommon.OperationSucceeded,
596596
expectedMessage: "success",
597597
},
598598
{
599599
desc: "will return success after 4 api failure attempt",
600600
apiFailureCount: 4,
601601
expectedAPICalls: 5,
602602
expectedResources: 1,
603-
expectedPhase: common.OperationSucceeded,
603+
expectedPhase: synccommon.OperationSucceeded,
604604
expectedMessage: "success",
605605
},
606606
{
607607
desc: "will fail after 5 api failure attempt",
608608
apiFailureCount: 5,
609609
expectedAPICalls: 5,
610610
expectedResources: 1,
611-
expectedPhase: common.OperationFailed,
611+
expectedPhase: synccommon.OperationFailed,
612612
expectedMessage: "not valid",
613613
},
614614
{
@@ -617,7 +617,7 @@ func TestServerResourcesRetry(t *testing.T) {
617617
apiFailureCount: 1,
618618
expectedAPICalls: 1,
619619
expectedResources: 1,
620-
expectedPhase: common.OperationFailed,
620+
expectedPhase: synccommon.OperationFailed,
621621
expectedMessage: "not valid",
622622
},
623623
}
@@ -1029,8 +1029,25 @@ func TestSyncFailureHookWithFailedSync(t *testing.T) {
10291029

10301030
func TestBeforeHookCreation(t *testing.T) {
10311031
syncCtx := newTestSyncCtx()
1032-
hook := Annotate(Annotate(NewPod(), synccommon.AnnotationKeyHook, "Sync"), synccommon.AnnotationKeyHookDeletePolicy, "BeforeHookCreation")
1032+
syncCtx.startedAt = time.Date(2022, 9, 14, 0, 0, 0, 0, time.UTC)
1033+
previousCreatedAt := syncCtx.startedAt.Add(-time.Hour)
1034+
//newCreatedAt := syncCtx.startedAt.Add(time.Hour)
1035+
hook := NewPod()
10331036
hook.SetNamespace(FakeArgoCDNamespace)
1037+
hook = Annotate(hook, synccommon.AnnotationKeyHook, string(synccommon.HookTypePreSync))
1038+
hook = Annotate(hook, synccommon.AnnotationKeyHookDeletePolicy, string(synccommon.HookDeletePolicyBeforeHookCreation))
1039+
hook.SetCreationTimestamp(metav1.NewTime(previousCreatedAt))
1040+
hookKey := kube.GetResourceKey(hook)
1041+
syncCtx.syncRes[fmt.Sprintf("%s:%s", hookKey.String(), synccommon.HookTypePreSync)] = synccommon.ResourceSyncResult{
1042+
ResourceKey: hookKey,
1043+
Version: hook.GroupVersionKind().Version,
1044+
Status: synccommon.ResultCodeSynced,
1045+
Message: "created",
1046+
HookType: synccommon.HookTypePreSync,
1047+
HookPhase: synccommon.OperationSucceeded,
1048+
SyncPhase: synccommon.SyncPhasePreSync,
1049+
Order: 1,
1050+
}
10341051
syncCtx.resources = groupResources(ReconciliationResult{
10351052
Live: []*unstructured.Unstructured{hook},
10361053
Target: []*unstructured.Unstructured{nil},

0 commit comments

Comments
 (0)