test(e2e): fix invalid AppSet test on master (#25939)

Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
This commit is contained in:
Alexandre Gaudreault
2026-01-12 13:51:27 -05:00
committed by GitHub
parent 05504d623c
commit e988c55a11
3 changed files with 17 additions and 62 deletions

View File

@@ -15,6 +15,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"github.com/argoproj/gitops-engine/pkg/health"
"github.com/argoproj/argo-cd/v3/common"
"github.com/argoproj/argo-cd/v3/pkg/apiclient/applicationset"
"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
@@ -2177,36 +2179,8 @@ func TestApplicationSetAPIListResourceEvents(t *testing.T) {
// TestApplicationSetHealthStatusCLI tests that the CLI commands display the health status field for an ApplicationSet.
func TestApplicationSetHealthStatusCLI(t *testing.T) {
expectedApp := v1alpha1.Application{
TypeMeta: metav1.TypeMeta{
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "health-cli-guestbook",
Namespace: utils.ArgoCDNamespace,
Finalizers: []string{v1alpha1.ResourcesFinalizerName},
},
Spec: v1alpha1.ApplicationSpec{
Project: "default",
Source: &v1alpha1.ApplicationSource{
RepoURL: "https://github.com/argoproj/argocd-example-apps.git",
TargetRevision: "HEAD",
Path: "guestbook",
},
Destination: v1alpha1.ApplicationDestination{
Server: "https://kubernetes.default.svc",
Namespace: "guestbook",
},
},
}
Given(t).
When().Create(v1alpha1.ApplicationSet{
ObjectMeta: metav1.ObjectMeta{
Name: "health-status-cli-test",
Namespace: utils.ArgoCDNamespace,
},
Spec: v1alpha1.ApplicationSetSpec{
GoTemplate: true,
Template: v1alpha1.ApplicationSetTemplate{
@@ -2236,16 +2210,15 @@ func TestApplicationSetHealthStatusCLI(t *testing.T) {
},
}).Then().
// Wait for the ApplicationSet to be ready
Expect(ApplicationSetHasConditions("health-status-cli-test", ExpectedConditions)).
Expect(ApplicationSetHasConditions(ExpectedConditions)).
Expect(ApplicationSetHasHealthStatus(health.HealthStatusHealthy)).
// Test 'argocd appset get' shows Health Status field
When().AppSetGet("health-status-cli-test").
Then().Expect(OutputContains("Health Status:")).
When().AppSetGet().
Then().
Expect(Success("Health Status: Healthy")).
// Test 'argocd appset list' shows HEALTH column header
When().AppSetList().
Then().Expect(OutputContains("HEALTH")).
// Cleanup
When().Delete().Then().Expect(ApplicationsDoNotExist([]v1alpha1.Application{expectedApp}))
Then().
Expect(Success("PROJECT SYNCPOLICY HEALTH CONDITIONS")).
Expect(Success("default nil Healthy "))
}

View File

@@ -538,9 +538,9 @@ func (a *Actions) AppSet(appName string, flags ...string) *Actions {
}
// AppSetGet runs 'argocd appset get' CLI command and stores the output
func (a *Actions) AppSetGet(appSetName string, flags ...string) *Actions {
a.context.t.Helper()
args := []string{"appset", "get", appSetName}
func (a *Actions) AppSetGet(flags ...string) *Actions {
a.context.T().Helper()
args := []string{"appset", "get", a.context.GetName()}
args = append(args, flags...)
a.runCli(args...)
return a
@@ -548,18 +548,13 @@ func (a *Actions) AppSetGet(appSetName string, flags ...string) *Actions {
// AppSetList runs 'argocd appset list' CLI command and stores the output
func (a *Actions) AppSetList(flags ...string) *Actions {
a.context.t.Helper()
a.context.T().Helper()
args := []string{"appset", "list"}
args = append(args, flags...)
a.runCli(args...)
return a
}
// GetLastOutput returns the output from the last CLI command
func (a *Actions) GetLastOutput() string {
return a.lastOutput
}
func (a *Actions) runCli(args ...string) {
a.context.T().Helper()
a.lastOutput, a.lastError = fixture.RunCli(args...)

View File

@@ -40,19 +40,6 @@ func Success(message string) Expectation {
}
}
// OutputContains asserts that the last command output contains the expected substring
func OutputContains(expected string) Expectation {
return func(c *Consequences) (state, string) {
if c.actions.lastError != nil {
return failed, fmt.Sprintf("error: %v", c.actions.lastError)
}
if !strings.Contains(c.actions.lastOutput, expected) {
return failed, fmt.Sprintf("output did not contain '%s', got: %s", expected, c.actions.lastOutput)
}
return succeeded, fmt.Sprintf("output contained '%s'", expected)
}
}
// Error asserts that the last command was an error with substring match
func Error(message, err string) Expectation {
return func(c *Consequences) (state, string) {
@@ -94,12 +81,12 @@ func ApplicationsExist(expectedApps []v1alpha1.Application) Expectation {
}
// ApplicationSetHasHealthStatus checks whether the ApplicationSet has the expected health status.
func ApplicationSetHasHealthStatus(applicationSetName string, expectedHealthStatus health.HealthStatusCode) Expectation {
func ApplicationSetHasHealthStatus(expectedHealthStatus health.HealthStatusCode) Expectation {
return func(c *Consequences) (state, string) {
// retrieve the application set
foundApplicationSet := c.applicationSet(applicationSetName)
foundApplicationSet := c.applicationSet(c.context.GetName())
if foundApplicationSet == nil {
return pending, fmt.Sprintf("application set '%s' not found", applicationSetName)
return pending, fmt.Sprintf("application set '%s' not found", c.context.GetName())
}
if foundApplicationSet.Status.Health.Status != expectedHealthStatus {