Files
deploy/gitops-engine/pkg/sync/sync_task_test.go
T
zeekayandHanzo Dev 1ab6e799c1 cd: the module is github.com/hanzoai/cd, where it is actually hosted
go.mod still declared `module github.com/hanzoai/deploy` after the repo was
renamed. A Go module path is not cosmetic — it is the resolvable location. So
`go get github.com/hanzoai/cd` could not work, and anything importing this
module had to spell a name that no longer exists at that address. The build log
of v3.6.0 is where it surfaced: the compiler was still emitting
github.com/hanzoai/deploy/cmd/cd/commands.

3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile
and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to
ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from
the module path, replaced separately so neither could clobber the other.

go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-28 21:16:24 -07:00

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/cd/gitops-engine/pkg/sync/common"
testingutils "github.com/hanzoai/cd/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())
}