Files
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

126 lines
3.2 KiB
Go

package project
import (
"context"
"strings"
"time"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
"github.com/hanzoai/cd/test/e2e/fixture"
)
// this implements the "when" part of given/when/then
//
// none of the func implement error checks, and that is complete intended, you should check for errors
// using the Then()
type Actions struct {
context *Context
lastError error
ignoreErrors bool
}
func (a *Actions) IgnoreErrors() *Actions {
a.ignoreErrors = true
return a
}
func (a *Actions) DoNotIgnoreErrors() *Actions {
a.ignoreErrors = false
return a
}
func (a *Actions) Create(args ...string) *Actions {
args = a.prepareCreateArgs(args)
// are you adding new context values? if you only use them for this func, then use args instead
a.runCli(args...)
return a
}
func (a *Actions) AddDestination(cluster string, namespace string) *Actions {
a.runCli("proj", "add-destination", a.context.GetName(), cluster, namespace)
return a
}
func (a *Actions) AddDestinationServiceAccount(cluster string, namespace string) *Actions {
a.runCli("proj", "add-destination-service-account", a.context.GetName(), cluster, namespace)
return a
}
func (a *Actions) AddSource(repo string) *Actions {
a.runCli("proj", "add-source", a.context.GetName(), repo)
return a
}
func (a *Actions) UpdateProject(updater func(project *v1alpha1.AppProject)) *Actions {
proj, err := fixture.AppClientset.AppsV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.TODO(), a.context.GetName(), metav1.GetOptions{})
require.NoError(a.context.T(), err)
updater(proj)
_, err = fixture.AppClientset.AppsV1alpha1().AppProjects(fixture.TestNamespace()).Update(context.TODO(), proj, metav1.UpdateOptions{})
require.NoError(a.context.T(), err)
return a
}
func (a *Actions) SetName(name string) *Actions {
a.context.SetName(name)
return a
}
func (a *Actions) prepareCreateArgs(args []string) []string {
a.context.T().Helper()
args = append([]string{
"proj", "create", a.context.GetName(),
}, args...)
if a.context.destination != "" {
args = append(args, "--dest", a.context.destination)
}
if len(a.context.sourceNamespaces) > 0 {
args = append(args, "--source-namespaces", strings.Join(a.context.sourceNamespaces, ","))
}
if len(a.context.repos) > 0 {
for _, repo := range a.context.repos {
args = append(args, "--src", repo)
}
}
if len(a.context.destinationServiceAccounts) != 0 {
for _, destinationServiceAccount := range a.context.destinationServiceAccounts {
args = append(args, "--dest-service-accounts", destinationServiceAccount)
}
}
return args
}
func (a *Actions) Delete() *Actions {
a.context.T().Helper()
a.runCli("proj", "delete", a.context.GetName())
return a
}
func (a *Actions) And(block func()) *Actions {
a.context.T().Helper()
block()
return a
}
func (a *Actions) Then() *Consequences {
a.context.T().Helper()
time.Sleep(fixture.WhenThenSleepInterval)
return &Consequences{a.context, a}
}
func (a *Actions) runCli(args ...string) {
a.context.T().Helper()
_, a.lastError = fixture.RunCli(args...)
if !a.ignoreErrors {
require.NoError(a.context.T(), a.lastError)
}
}