8
8
"net/http/httptest"
9
9
"reflect"
10
10
"testing"
11
+ "time"
11
12
12
13
"github.com/stretchr/testify/assert"
13
14
"github.com/stretchr/testify/require"
@@ -25,7 +26,6 @@ import (
25
26
26
27
"github.com/argoproj/gitops-engine/pkg/diff"
27
28
"github.com/argoproj/gitops-engine/pkg/health"
28
- "github.com/argoproj/gitops-engine/pkg/sync/common"
29
29
synccommon "github.com/argoproj/gitops-engine/pkg/sync/common"
30
30
"github.com/argoproj/gitops-engine/pkg/utils/kube"
31
31
"github.com/argoproj/gitops-engine/pkg/utils/kube/kubetest"
@@ -568,47 +568,47 @@ func TestServerResourcesRetry(t *testing.T) {
568
568
apiFailureCount : 0 ,
569
569
expectedAPICalls : 1 ,
570
570
expectedResources : 1 ,
571
- expectedPhase : common .OperationSucceeded ,
571
+ expectedPhase : synccommon .OperationSucceeded ,
572
572
expectedMessage : "success" ,
573
573
},
574
574
{
575
575
desc : "will return success after 1 api failure attempt" ,
576
576
apiFailureCount : 1 ,
577
577
expectedAPICalls : 2 ,
578
578
expectedResources : 1 ,
579
- expectedPhase : common .OperationSucceeded ,
579
+ expectedPhase : synccommon .OperationSucceeded ,
580
580
expectedMessage : "success" ,
581
581
},
582
582
{
583
583
desc : "will return success after 2 api failure attempt" ,
584
584
apiFailureCount : 2 ,
585
585
expectedAPICalls : 3 ,
586
586
expectedResources : 1 ,
587
- expectedPhase : common .OperationSucceeded ,
587
+ expectedPhase : synccommon .OperationSucceeded ,
588
588
expectedMessage : "success" ,
589
589
},
590
590
{
591
591
desc : "will return success after 3 api failure attempt" ,
592
592
apiFailureCount : 3 ,
593
593
expectedAPICalls : 4 ,
594
594
expectedResources : 1 ,
595
- expectedPhase : common .OperationSucceeded ,
595
+ expectedPhase : synccommon .OperationSucceeded ,
596
596
expectedMessage : "success" ,
597
597
},
598
598
{
599
599
desc : "will return success after 4 api failure attempt" ,
600
600
apiFailureCount : 4 ,
601
601
expectedAPICalls : 5 ,
602
602
expectedResources : 1 ,
603
- expectedPhase : common .OperationSucceeded ,
603
+ expectedPhase : synccommon .OperationSucceeded ,
604
604
expectedMessage : "success" ,
605
605
},
606
606
{
607
607
desc : "will fail after 5 api failure attempt" ,
608
608
apiFailureCount : 5 ,
609
609
expectedAPICalls : 5 ,
610
610
expectedResources : 1 ,
611
- expectedPhase : common .OperationFailed ,
611
+ expectedPhase : synccommon .OperationFailed ,
612
612
expectedMessage : "not valid" ,
613
613
},
614
614
{
@@ -617,7 +617,7 @@ func TestServerResourcesRetry(t *testing.T) {
617
617
apiFailureCount : 1 ,
618
618
expectedAPICalls : 1 ,
619
619
expectedResources : 1 ,
620
- expectedPhase : common .OperationFailed ,
620
+ expectedPhase : synccommon .OperationFailed ,
621
621
expectedMessage : "not valid" ,
622
622
},
623
623
}
@@ -1029,8 +1029,25 @@ func TestSyncFailureHookWithFailedSync(t *testing.T) {
1029
1029
1030
1030
func TestBeforeHookCreation (t * testing.T ) {
1031
1031
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 ()
1033
1036
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
+ }
1034
1051
syncCtx .resources = groupResources (ReconciliationResult {
1035
1052
Live : []* unstructured.Unstructured {hook },
1036
1053
Target : []* unstructured.Unstructured {nil },
0 commit comments