Files
cd/test/e2e/app_namespaces_test.go
zeekay 01a52090a9 pkg/client, mocks: regenerate off the apps.hanzo.ai group
clientgen/mockgen hadn't been rerun since the group rename, even though
pkg/apis/application/v1alpha1/doc.go and the shipped CRDs already say
apps.hanzo.ai. pkg/client/** still derived ArgoprojV1alpha1/Argoproj()
from the old argoproj.io group, and .mockery.yaml still named ArgoDB
(renamed to DB in util/db/db.go a few commits back) and
util/notification/cd (deleted in b2d7140a0, we use hanzoai/notify).

Reran clientgen (deepcopy-gen/client-gen/lister-gen/informer-gen) off
the current group, and mockgen after fixing .mockery.yaml. Moved every
hand-written call site that holds a versioned.Interface or
SharedInformerFactory with it: .ArgoprojV1alpha1() -> .AppsV1alpha1(),
ArgoprojV1alpha1Interface/Client -> AppsV1alpha1Interface/Client,
.Argoproj() -> .Apps() across controller, server, util, cmd,
hack/gen-resources, and test/e2e. controller/metrics/metrics_test.go's
mocks.NewArgoDB -> mocks.NewDB. Deleted the orphaned
util/db/mocks/ArgoDB.go; mockery writes DB.go for the renamed
interface but doesn't clean up the old filename on its own.

Left CHANGELOG.md/SECURITY.md's real argoproj/argo-cd history and
gitops-engine/pkg/diff/testdata/openapiv2.bin's Argo Rollouts OpenAPI
fixture untouched - genuine history and a real third-party schema, not
our naming.

go build/vet clean. Same 19 pre-existing package-level test failures
as baseline (missing git-verify-wrapper.sh, no live cluster, etc.),
none new. All 32 manifests/ kustomization paths still build;
manifests/ha/** untouched.
2026-09-05 13:44:46 -07:00

106 lines
3.0 KiB
Go

package e2e
import (
"testing"
. "github.com/hanzoai/cd/gitops-engine/pkg/sync/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
. "github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
. "github.com/hanzoai/cd/test/e2e/fixture"
. "github.com/hanzoai/cd/test/e2e/fixture/app"
. "github.com/hanzoai/cd/util/cd"
"github.com/hanzoai/cd/util/errors"
)
func TestAppCreationInOtherNamespace(t *testing.T) {
ctx := Given(t)
ctx.
Path(guestbookPath).
SetAppNamespace(AppNamespace()).
When().
CreateApp().
Then().
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
And(func(app *Application) {
assert.Equal(t, ctx.AppName(), app.Name)
assert.Equal(t, AppNamespace(), app.Namespace)
assert.Equal(t, RepoURL(RepoURLTypeFile), app.Spec.GetSource().RepoURL)
assert.Equal(t, guestbookPath, app.Spec.GetSource().Path)
assert.Equal(t, ctx.DeploymentNamespace(), app.Spec.Destination.Namespace)
assert.Equal(t, KubernetesInternalAPIServerAddr, app.Spec.Destination.Server)
}).
Expect(NamespacedEvent(ctx.AppNamespace(), EventReasonResourceCreated, "create")).
And(func(_ *Application) {
// app should be listed
output, err := RunCli("app", "list")
require.NoError(t, err)
assert.Contains(t, output, ctx.AppName())
}).
When().
// ensure that create is idempotent
CreateApp().
Then().
Given().
Revision("master").
When().
// ensure that update replaces spec and merge labels and annotations
And(func() {
errors.NewHandler(t).FailOnErr(AppClientset.AppsV1alpha1().Applications(AppNamespace()).Patch(t.Context(),
ctx.AppName(), types.MergePatchType, []byte(`{"metadata": {"labels": { "test": "label" }, "annotations": { "test": "annotation" }}}`), metav1.PatchOptions{}))
}).
CreateApp("--upsert").
Then().
And(func(app *Application) {
assert.Equal(t, "label", app.Labels["test"])
assert.Equal(t, "annotation", app.Annotations["test"])
assert.Equal(t, "master", app.Spec.GetSource().TargetRevision)
})
}
func TestForbiddenNamespace(t *testing.T) {
ctx := Given(t)
ctx.
Path(guestbookPath).
SetAppNamespace("forbidden").
When().
IgnoreErrors().
CreateApp().
Then().
Expect(DoesNotExist())
}
func TestDeletingNamespacedAppStuckInSync(t *testing.T) {
ctx := Given(t)
ctx.And(func() {
require.NoError(t, SetResourceOverrides(map[string]ResourceOverride{
"ConfigMap": {
HealthLua: `return { status = obj.annotations and obj.annotations['health'] or 'Progressing' }`,
},
}))
}).
Async(true).
SetAppNamespace(AppNamespace()).
Path("hook-custom-health").
When().
CreateApp().
Sync().
Then().
// stuck in running state
Expect(OperationPhaseIs(OperationRunning)).
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
When().
Delete(true).
Then().
// delete is ignored, still stuck in running state
Expect(OperationPhaseIs(OperationRunning)).
When().
TerminateOp().
Then().
// delete is successful
Expect(DoesNotExist())
}