mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
Two corrections on top of the naming pass, both found by checking the live cluster rather than the source. The rename had silently changed the user-facing annotation key from argocd.argoproj.io/sync-wave to cd.argoproj.io/sync-wave — 63 live Applications carry the old key, so deploying that would have ignored every sync-wave and broken fleet deploy ordering. The key is now cd.hanzo.ai/*, and universe 575650286 moves the ApplicationSet template that stamps it, so the controller regenerates all 63 consistently. The API group in code said argoproj.io/v1alpha1 in 157 places while the cluster has served apps.hanzo.ai/v1alpha1 since 2026-07-23 (the CRDs are applications.apps.hanzo.ai). Code now matches what is actually served. The legacy applications.argoproj.io/app-name label had ZERO live users, so it went with the rest. foo.argoproj.io test fixtures became foo.example.com — arbitrary test domains should not carry a vendor name. go build ./... exit 0. Co-authored-by: Hanzo Dev <[email protected]>
72 lines
4.5 KiB
Go
72 lines
4.5 KiB
Go
package sync
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
|
|
"github.com/hanzoai/deploy/gitops-engine/pkg/sync/common"
|
|
testingutils "github.com/hanzoai/deploy/gitops-engine/pkg/utils/testing"
|
|
)
|
|
|
|
func Test_syncTask_hookType(t *testing.T) {
|
|
type fields struct {
|
|
phase common.SyncPhase
|
|
liveObj *unstructured.Unstructured
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
want common.HookType
|
|
}{
|
|
{"Empty", fields{common.SyncPhaseSync, testingutils.NewPod()}, ""},
|
|
{"PreSyncHook", fields{common.SyncPhasePreSync, newHook("hook", common.HookTypePreSync, common.HookDeletePolicyBeforeHookCreation)}, common.HookTypePreSync},
|
|
{"SyncHook", fields{common.SyncPhaseSync, newHook("hook", common.HookTypeSync, common.HookDeletePolicyBeforeHookCreation)}, common.HookTypeSync},
|
|
{"PostSyncHook", fields{common.SyncPhasePostSync, newHook("hook", common.HookTypePostSync, common.HookDeletePolicyBeforeHookCreation)}, common.HookTypePostSync},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
task := &syncTask{
|
|
phase: tt.fields.phase,
|
|
liveObj: tt.fields.liveObj,
|
|
}
|
|
hookType := task.hookType()
|
|
assert.Equal(t, tt.want, hookType)
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_syncTask_hasHookDeletePolicy(t *testing.T) {
|
|
assert.False(t, (&syncTask{targetObj: testingutils.NewPod()}).hasHookDeletePolicy(common.HookDeletePolicyBeforeHookCreation))
|
|
assert.False(t, (&syncTask{targetObj: testingutils.NewPod()}).hasHookDeletePolicy(common.HookDeletePolicyHookSucceeded))
|
|
assert.False(t, (&syncTask{targetObj: testingutils.NewPod()}).hasHookDeletePolicy(common.HookDeletePolicyHookFailed))
|
|
// must be hook
|
|
assert.False(t, (&syncTask{targetObj: testingutils.Annotate(testingutils.NewPod(), "cd.hanzo.ai/hook-delete-policy", "BeforeHookCreation")}).hasHookDeletePolicy(common.HookDeletePolicyBeforeHookCreation))
|
|
assert.True(t, (&syncTask{targetObj: testingutils.Annotate(testingutils.Annotate(testingutils.NewPod(), "cd.hanzo.ai/hook", "Sync"), "cd.hanzo.ai/hook-delete-policy", "BeforeHookCreation")}).hasHookDeletePolicy(common.HookDeletePolicyBeforeHookCreation))
|
|
assert.True(t, (&syncTask{targetObj: testingutils.Annotate(testingutils.Annotate(testingutils.NewPod(), "cd.hanzo.ai/hook", "Sync"), "cd.hanzo.ai/hook-delete-policy", "HookSucceeded")}).hasHookDeletePolicy(common.HookDeletePolicyHookSucceeded))
|
|
assert.True(t, (&syncTask{targetObj: testingutils.Annotate(testingutils.Annotate(testingutils.NewPod(), "cd.hanzo.ai/hook", "Sync"), "cd.hanzo.ai/hook-delete-policy", "HookFailed")}).hasHookDeletePolicy(common.HookDeletePolicyHookFailed))
|
|
}
|
|
|
|
func Test_syncTask_deleteOnPhaseCompletion(t *testing.T) {
|
|
assert.False(t, (&syncTask{liveObj: testingutils.NewPod()}).deleteOnPhaseCompletion())
|
|
// must be hook
|
|
assert.True(t, (&syncTask{operationState: common.OperationSucceeded, liveObj: testingutils.Annotate(testingutils.Annotate(testingutils.NewPod(), "cd.hanzo.ai/hook", "Sync"), "cd.hanzo.ai/hook-delete-policy", "HookSucceeded")}).deleteOnPhaseCompletion())
|
|
assert.True(t, (&syncTask{operationState: common.OperationFailed, liveObj: testingutils.Annotate(testingutils.Annotate(testingutils.NewPod(), "cd.hanzo.ai/hook", "Sync"), "cd.hanzo.ai/hook-delete-policy", "HookFailed")}).deleteOnPhaseCompletion())
|
|
}
|
|
|
|
func Test_syncTask_deleteBeforeCreation(t *testing.T) {
|
|
assert.False(t, (&syncTask{liveObj: testingutils.NewPod()}).deleteBeforeCreation())
|
|
// must be hook
|
|
assert.False(t, (&syncTask{liveObj: testingutils.Annotate(testingutils.NewPod(), "cd.hanzo.ai/hook-delete-policy", "BeforeHookCreation")}).deleteBeforeCreation())
|
|
// no need to delete if no live obj
|
|
assert.False(t, (&syncTask{targetObj: testingutils.Annotate(testingutils.Annotate(testingutils.NewPod(), "cd.hanzo.ai/hook", "Sync"), "cd.hanzo.ai/hook-delete-policy", "BeforeHookCreation")}).deleteBeforeCreation())
|
|
assert.True(t, (&syncTask{liveObj: testingutils.Annotate(testingutils.Annotate(testingutils.NewPod(), "cd.hanzo.ai/hook", "Sync"), "cd.hanzo.ai/hook-delete-policy", "BeforeHookCreation")}).deleteBeforeCreation())
|
|
assert.True(t, (&syncTask{liveObj: testingutils.Annotate(testingutils.Annotate(testingutils.NewPod(), "cd.hanzo.ai/hook", "Sync"), "cd.hanzo.ai/hook-delete-policy", "BeforeHookCreation")}).deleteBeforeCreation())
|
|
}
|
|
|
|
func Test_syncTask_wave(t *testing.T) {
|
|
assert.Equal(t, 0, (&syncTask{targetObj: testingutils.NewPod()}).wave())
|
|
assert.Equal(t, 1, (&syncTask{targetObj: testingutils.Annotate(testingutils.NewPod(), "cd.hanzo.ai/sync-wave", "1")}).wave())
|
|
}
|