Skip to content

Commit

Permalink
WIP: thoroughly test BeforeHookCreation
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Nazarewski <[email protected]>
  • Loading branch information
nazarewk committed Sep 14, 2022
1 parent 327f8d9 commit 4382fe9
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions pkg/sync/sync_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http/httptest"
"reflect"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -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"
Expand Down Expand Up @@ -568,47 +568,47 @@ func TestServerResourcesRetry(t *testing.T) {
apiFailureCount: 0,
expectedAPICalls: 1,
expectedResources: 1,
expectedPhase: common.OperationSucceeded,
expectedPhase: synccommon.OperationSucceeded,
expectedMessage: "success",
},
{
desc: "will return success after 1 api failure attempt",
apiFailureCount: 1,
expectedAPICalls: 2,
expectedResources: 1,
expectedPhase: common.OperationSucceeded,
expectedPhase: synccommon.OperationSucceeded,
expectedMessage: "success",
},
{
desc: "will return success after 2 api failure attempt",
apiFailureCount: 2,
expectedAPICalls: 3,
expectedResources: 1,
expectedPhase: common.OperationSucceeded,
expectedPhase: synccommon.OperationSucceeded,
expectedMessage: "success",
},
{
desc: "will return success after 3 api failure attempt",
apiFailureCount: 3,
expectedAPICalls: 4,
expectedResources: 1,
expectedPhase: common.OperationSucceeded,
expectedPhase: synccommon.OperationSucceeded,
expectedMessage: "success",
},
{
desc: "will return success after 4 api failure attempt",
apiFailureCount: 4,
expectedAPICalls: 5,
expectedResources: 1,
expectedPhase: common.OperationSucceeded,
expectedPhase: synccommon.OperationSucceeded,
expectedMessage: "success",
},
{
desc: "will fail after 5 api failure attempt",
apiFailureCount: 5,
expectedAPICalls: 5,
expectedResources: 1,
expectedPhase: common.OperationFailed,
expectedPhase: synccommon.OperationFailed,
expectedMessage: "not valid",
},
{
Expand All @@ -617,7 +617,7 @@ func TestServerResourcesRetry(t *testing.T) {
apiFailureCount: 1,
expectedAPICalls: 1,
expectedResources: 1,
expectedPhase: common.OperationFailed,
expectedPhase: synccommon.OperationFailed,
expectedMessage: "not valid",
},
}
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit 4382fe9

Please sign in to comment.