Skip to content

Commit 65d131e

Browse files
committed
test: use unique app name per test
Signed-off-by: Alexandre Gaudreault <[email protected]>
1 parent 0a2ae95 commit 65d131e

File tree

6 files changed

+56
-40
lines changed

6 files changed

+56
-40
lines changed

test/e2e/admin_test.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ func TestBackupExportImport(t *testing.T) {
2121
// Create application in argocd namespace
2222
appctx := appfixture.GivenWithSameState(t)
2323

24+
var appTestNamespace Application
25+
var appOtherNamespace Application
26+
2427
// Create application in test namespace
2528
appctx.
2629
Path(guestbookPath).
@@ -29,8 +32,9 @@ func TestBackupExportImport(t *testing.T) {
2932
CreateApp().
3033
Then().
3134
And(func(app *Application) {
32-
assert.Equal(t, "exported-app1", app.Name)
33-
assert.Equal(t, fixture.TestNamespace(), app.Namespace)
35+
assert.Equal(t, appctx.AppName(), app.Name)
36+
assert.Equal(t, appctx.AppNamespace(), app.Namespace)
37+
appTestNamespace = *app
3438
})
3539

3640
// Create app in other namespace
@@ -42,8 +46,9 @@ func TestBackupExportImport(t *testing.T) {
4246
CreateApp().
4347
Then().
4448
And(func(app *Application) {
45-
assert.Equal(t, "exported-app-other-namespace", app.Name)
46-
assert.Equal(t, fixture.AppNamespace(), app.Namespace)
49+
assert.Equal(t, appctx.AppName(), app.Name)
50+
assert.Equal(t, appctx.AppNamespace(), app.Namespace)
51+
appOtherNamespace = *app
4752
})
4853

4954
ctx.
@@ -57,8 +62,8 @@ func TestBackupExportImport(t *testing.T) {
5762
AndExportedResources(func(exportResources *ExportedResources, err error) {
5863
require.NoError(t, err, "export format not valid")
5964
assert.True(t, exportResources.HasResource(kube.NewResourceKey("", "ConfigMap", "", "argocd-cm")), "argocd-cm not found in export")
60-
assert.True(t, exportResources.HasResource(kube.NewResourceKey(ApplicationSchemaGroupVersionKind.Group, ApplicationSchemaGroupVersionKind.Kind, "", "exported-app1")), "test namespace application not in export")
61-
assert.True(t, exportResources.HasResource(kube.NewResourceKey(ApplicationSchemaGroupVersionKind.Group, ApplicationSchemaGroupVersionKind.Kind, fixture.AppNamespace(), "exported-app-other-namespace")), "app namespace application not in export")
65+
assert.True(t, exportResources.HasResource(kube.NewResourceKey(ApplicationSchemaGroupVersionKind.Group, ApplicationSchemaGroupVersionKind.Kind, "", appTestNamespace.GetName())), "test namespace application not in export")
66+
assert.True(t, exportResources.HasResource(kube.NewResourceKey(ApplicationSchemaGroupVersionKind.Group, ApplicationSchemaGroupVersionKind.Kind, appOtherNamespace.GetNamespace(), appOtherNamespace.GetName())), "app namespace application not in export")
6267
})
6368

6469
// Test import - clean state
@@ -70,9 +75,9 @@ func TestBackupExportImport(t *testing.T) {
7075
Then().
7176
AndCLIOutput(func(_ string, err error) {
7277
require.NoError(t, err, "import finished with error")
73-
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Get(t.Context(), "exported-app1", metav1.GetOptions{})
78+
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(appTestNamespace.GetNamespace()).Get(t.Context(), appTestNamespace.GetName(), metav1.GetOptions{})
7479
require.NoError(t, err, "failed getting test namespace application after import")
75-
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Get(t.Context(), "exported-app-other-namespace", metav1.GetOptions{})
80+
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(appOtherNamespace.GetNamespace()).Get(t.Context(), appOtherNamespace.GetName(), metav1.GetOptions{})
7681
require.NoError(t, err, "failed getting app namespace application after import")
7782
})
7883
}

test/e2e/app_management_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ func TestAppWithSecrets(t *testing.T) {
845845
assert.Empty(t, diffOutput)
846846

847847
// make sure resource update error does not print secret details
848-
_, err = fixture.RunCli("app", "patch-resource", "test-app-with-secrets", "--resource-name", "test-secret",
848+
_, err = fixture.RunCli("app", "patch-resource", app.GetName(), "--resource-name", "test-secret",
849849
"--kind", "Secret", "--patch", `{"op": "add", "path": "/data", "value": "hello"}'`,
850850
"--patch-type", "application/json-patch+json")
851851
require.ErrorContains(t, err, fmt.Sprintf("failed to patch Secret %s/test-secret", fixture.DeploymentNamespace()))
@@ -1571,10 +1571,9 @@ func assertResourceActions(t *testing.T, appName string, successful bool) {
15711571

15721572
func TestPermissions(t *testing.T) {
15731573
appCtx := Given(t)
1574-
projName := "argo-project"
1575-
projActions := projectFixture.
1576-
GivenWithSameState(t).
1577-
Name(projName).
1574+
projCtx := projectFixture.GivenWithSameState(t)
1575+
projActions := projCtx.
1576+
Name("argo-project").
15781577
When().
15791578
Create()
15801579

@@ -1583,7 +1582,7 @@ func TestPermissions(t *testing.T) {
15831582

15841583
appCtx.
15851584
Path("guestbook-logs").
1586-
Project(projName).
1585+
Project(projCtx.GetName()).
15871586
When().
15881587
IgnoreErrors().
15891588
// ensure app is not created if project permissions are missing
@@ -1641,8 +1640,8 @@ func TestPermissions(t *testing.T) {
16411640
Refresh(RefreshTypeNormal).
16421641
Then().
16431642
// make sure application resource actions are failing
1644-
And(func(_ *Application) {
1645-
assertResourceActions(t, "test-permissions", false)
1643+
And(func(a *Application) {
1644+
assertResourceActions(t, a.GetName(), false)
16461645
})
16471646
}
16481647

test/e2e/cli_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ func createTestPlugin(t *testing.T, name, content string) string {
3535

3636
// TestCliAppCommand verifies the basic Argo CD CLI commands for app synchronization and listing.
3737
func TestCliAppCommand(t *testing.T) {
38-
Given(t).
39-
Path("hook").
38+
ctx := Given(t)
39+
ctx.Path("hook").
4040
When().
4141
CreateApp().
4242
And(func() {
43-
output, err := RunCli("app", "sync", Name(), "--timeout", "90")
43+
output, err := RunCli("app", "sync", ctx.AppName(), "--timeout", "90")
4444
require.NoError(t, err)
45-
vars := map[string]any{"Name": Name(), "Namespace": DeploymentNamespace()}
45+
vars := map[string]any{"Name": ctx.AppName(), "Namespace": DeploymentNamespace()}
4646
assert.Contains(t, NormalizeOutput(output), Tmpl(t, `Pod {{.Namespace}} pod Synced Progressing pod/pod created`, vars))
4747
assert.Contains(t, NormalizeOutput(output), Tmpl(t, `Pod {{.Namespace}} hook Succeeded Sync pod/hook created`, vars))
4848
}).
4949
Then().
5050
Expect(OperationPhaseIs(OperationSucceeded)).
5151
Expect(HealthIs(health.HealthStatusHealthy)).
52-
And(func(_ *Application) {
52+
And(func(a *Application) {
5353
output, err := RunCli("app", "list")
5454
require.NoError(t, err)
5555
expected := Tmpl(
5656
t,
5757
`{{.Name}} https://kubernetes.default.svc {{.Namespace}} default Synced Healthy Manual <none>`,
58-
map[string]any{"Name": Name(), "Namespace": DeploymentNamespace()})
58+
map[string]any{"Name": a.GetName(), "Namespace": DeploymentNamespace()})
5959
assert.Contains(t, NormalizeOutput(output), expected)
6060
})
6161
}
@@ -75,17 +75,18 @@ func TestNormalArgoCDCommandsExecuteOverPluginsWithSameName(t *testing.T) {
7575
})
7676
t.Setenv("PATH", filepath.Dir(pluginPath)+":"+origPath)
7777

78-
Given(t).
78+
ctx := Given(t)
79+
ctx.Path("hook").
7980
Path("hook").
8081
When().
8182
CreateApp().
8283
And(func() {
83-
output, err := RunCli("app", "sync", Name(), "--timeout", "90")
84+
output, err := RunCli("app", "sync", ctx.AppName(), "--timeout", "90")
8485
require.NoError(t, err)
8586

8687
assert.NotContains(t, NormalizeOutput(output), "I am a plugin, not Argo CD!")
8788

88-
vars := map[string]any{"Name": Name(), "Namespace": DeploymentNamespace()}
89+
vars := map[string]any{"Name": ctx.AppName(), "Namespace": DeploymentNamespace()}
8990
assert.Contains(t, NormalizeOutput(output), Tmpl(t, `Pod {{.Namespace}} pod Synced Progressing pod/pod created`, vars))
9091
assert.Contains(t, NormalizeOutput(output), Tmpl(t, `Pod {{.Namespace}} hook Succeeded Sync pod/hook created`, vars))
9192
}).
@@ -101,7 +102,7 @@ func TestNormalArgoCDCommandsExecuteOverPluginsWithSameName(t *testing.T) {
101102
expected := Tmpl(
102103
t,
103104
`{{.Name}} https://kubernetes.default.svc {{.Namespace}} default Synced Healthy Manual <none>`,
104-
map[string]any{"Name": Name(), "Namespace": DeploymentNamespace()})
105+
map[string]any{"Name": ctx.AppName(), "Namespace": DeploymentNamespace()})
105106
assert.Contains(t, NormalizeOutput(output), expected)
106107
})
107108
}

test/e2e/cluster_test.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,16 @@ https://kubernetes.default.svc in-cluster %v Successful `, fixtu
5656
}
5757

5858
func TestClusterAdd(t *testing.T) {
59-
clusterFixture.
60-
Given(t).
61-
Project(fixture.ProjectName).
59+
ctx := clusterFixture.Given(t)
60+
ctx.Project(fixture.ProjectName).
6261
Upsert(true).
6362
Server(KubernetesInternalAPIServerAddr).
6463
When().
6564
Create().
6665
List().
6766
Then().
6867
AndCLIOutput(func(output string, _ error) {
69-
assert.Equal(t, fmt.Sprintf(`SERVER NAME VERSION STATUS MESSAGE PROJECT
70-
https://kubernetes.default.svc test-cluster-add %v Successful %s`, fixture.GetVersions(t).ServerVersion, fixture.ProjectName), output)
68+
assert.Contains(t, fixture.NormalizeOutput(output), fmt.Sprintf(`https://kubernetes.default.svc %s %v Successful %s`, ctx.GetName(), fixture.GetVersions(t).ServerVersion, fixture.ProjectName))
7169
})
7270
}
7371

@@ -112,8 +110,8 @@ func TestClusterAddAllowed(t *testing.T) {
112110
},
113111
}, "org-admin")
114112

115-
clusterFixture.
116-
GivenWithSameState(t).
113+
ctx := clusterFixture.GivenWithSameState(t)
114+
ctx.Project(fixture.ProjectName).
117115
Project(fixture.ProjectName).
118116
Upsert(true).
119117
Server(KubernetesInternalAPIServerAddr).
@@ -122,8 +120,7 @@ func TestClusterAddAllowed(t *testing.T) {
122120
List().
123121
Then().
124122
AndCLIOutput(func(output string, _ error) {
125-
assert.Equal(t, fmt.Sprintf(`SERVER NAME VERSION STATUS MESSAGE PROJECT
126-
https://kubernetes.default.svc test-cluster-add-allowed %v Successful argo-project`, fixture.GetVersions(t).ServerVersion), output)
123+
assert.Contains(t, fixture.NormalizeOutput(output), fmt.Sprintf(`https://kubernetes.default.svc %s %v Successful %s`, ctx.GetName(), fixture.GetVersions(t).ServerVersion, fixture.ProjectName))
127124
})
128125
}
129126

test/e2e/fixture/app/context.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package app
22

33
import (
4+
"strings"
45
"testing"
56
"time"
67

@@ -93,8 +94,15 @@ func GivenWithSameState(t *testing.T) *Context {
9394
}
9495
}
9596

97+
// AppName returns the unique application name for the test context.
98+
// Unique application names protects from potential conflicts between test run
99+
// caused by the tracking annotation on existing objects
96100
func (c *Context) AppName() string {
97-
return c.name
101+
suffix := "-" + fixture.ShortId()
102+
if strings.HasSuffix(c.name, suffix) {
103+
return c.name
104+
}
105+
return fixture.DnsFriendly(c.name, suffix)
98106
}
99107

100108
func (c *Context) AppQualifiedName() string {

test/e2e/fixture/fixture.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const (
9090

9191
var (
9292
id string
93+
shortId string
9394
deploymentNamespace string
9495
name string
9596
KubeClientset kubernetes.Interface
@@ -301,6 +302,10 @@ func Name() string {
301302
return name
302303
}
303304

305+
func ShortId() string {
306+
return shortId
307+
}
308+
304309
func repoDirectory() string {
305310
return path.Join(TmpDir, repoDir)
306311
}
@@ -1056,10 +1061,11 @@ func EnsureCleanState(t *testing.T, opts ...TestOption) {
10561061
if err != nil {
10571062
return err
10581063
}
1059-
postFix := "-" + strings.ToLower(randString)
1060-
id = t.Name() + postFix
1061-
name = DnsFriendly(t.Name(), "")
1062-
deploymentNamespace = DnsFriendly("argocd-e2e-"+t.Name(), postFix)
1064+
shortId = strings.ToLower(randString)
1065+
id = fmt.Sprintf("%s-%s", t.Name(), shortId)
1066+
name = DnsFriendly(t.Name(), "-"+shortId)
1067+
deploymentNamespace = DnsFriendly("argocd-e2e-"+t.Name(), "-"+shortId)
1068+
10631069
// create namespace
10641070
_, err = Run("", "kubectl", "create", "ns", DeploymentNamespace())
10651071
if err != nil {

0 commit comments

Comments
 (0)