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

143 lines
3.4 KiB
Go

package applicationsets
import (
"context"
"encoding/json"
"time"
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
"github.com/hanzoai/cd/test/e2e/fixture"
"github.com/hanzoai/cd/test/e2e/fixture/applicationsets/utils"
"github.com/hanzoai/cd/util/errors"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/dynamic"
)
// this implements the "then" part of given/when/then
type Consequences struct {
context *Context
actions *Actions
}
func (c *Consequences) Expect(e Expectation) *Consequences {
return c.ExpectWithDuration(e, time.Duration(30)*time.Second)
}
func (c *Consequences) ExpectWithDuration(e Expectation, timeout time.Duration) *Consequences {
// this invocation makes sure this func is not reported as the cause of the failure - we are a "test helper"
c.context.T().Helper()
var message string
var state state
sleepIntervals := []time.Duration{
10 * time.Millisecond,
20 * time.Millisecond,
50 * time.Millisecond,
100 * time.Millisecond,
200 * time.Millisecond,
300 * time.Millisecond,
500 * time.Millisecond,
1 * time.Second,
}
sleepIntervalsIdx := -1
for start := time.Now(); time.Since(start) < timeout; time.Sleep(sleepIntervals[sleepIntervalsIdx]) {
if sleepIntervalsIdx < len(sleepIntervals)-1 {
sleepIntervalsIdx++
}
state, message = e(c)
switch state {
case succeeded:
log.Infof("expectation succeeded: %s", message)
return c
case failed:
c.context.T().Fatalf("failed expectation: %s", message)
return c
}
log.Infof("expectation pending: %s", message)
}
c.context.T().Fatal("timeout waiting for: " + message)
return c
}
func (c *Consequences) And(block func()) *Consequences {
c.context.T().Helper()
block()
return c
}
func (c *Consequences) Given() *Context {
return c.context
}
func (c *Consequences) When() *Actions {
time.Sleep(fixture.WhenThenSleepInterval)
return c.actions
}
func (c *Consequences) app(name string) *v1alpha1.Application {
apps := c.apps()
for index, app := range apps {
if app.Name == name {
return &apps[index]
}
}
return nil
}
func (c *Consequences) apps() []v1alpha1.Application {
c.context.T().Helper()
var namespace string
if c.context.switchToNamespace != "" {
namespace = string(c.context.switchToNamespace)
} else {
namespace = fixture.TestNamespace()
}
fixtureClient := utils.GetE2EFixtureK8sClient(c.context.T())
list, err := fixtureClient.AppClientset.AppsV1alpha1().Applications(namespace).List(context.Background(), metav1.ListOptions{})
errors.CheckError(err)
if list == nil {
list = &v1alpha1.ApplicationList{}
}
return list.Items
}
func (c *Consequences) applicationSet(applicationSetName string) *v1alpha1.ApplicationSet {
c.context.T().Helper()
fixtureClient := utils.GetE2EFixtureK8sClient(c.context.T())
var appSetClientSet dynamic.ResourceInterface
if c.context.switchToNamespace != "" {
appSetClientSet = fixtureClient.ExternalAppSetClientsets[c.context.switchToNamespace]
} else {
appSetClientSet = fixtureClient.AppSetClientset
}
list, err := appSetClientSet.Get(context.Background(), applicationSetName, metav1.GetOptions{})
errors.CheckError(err)
var appSet v1alpha1.ApplicationSet
bytes, err := list.MarshalJSON()
if err != nil {
return &v1alpha1.ApplicationSet{}
}
err = json.Unmarshal(bytes, &appSet)
if err != nil {
return &v1alpha1.ApplicationSet{}
}
if appSet.Name == applicationSetName {
return &appSet
}
return &v1alpha1.ApplicationSet{}
}