Skip to content

Commit 18b5875

Browse files
authored
test(e2e): e2e tests should be runnable individually (#541)
Signed-off-by: Jayendra Parsai <[email protected]>
1 parent 4f4f4ea commit 18b5875

File tree

4 files changed

+233
-136
lines changed

4 files changed

+233
-136
lines changed

test/e2e/clusterinfo_test.go

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package e2e
1616

1717
import (
1818
"fmt"
19-
"os"
2019
"testing"
2120
"time"
2221

@@ -77,12 +76,14 @@ var message = "Agent: '%s' is %s with principal"
7776
func (suite *ClusterInfoTestSuite) Test_ClusterInfo_Managed() {
7877
requires := suite.Require()
7978

79+
clusterDetail := suite.ClusterDetails
80+
8081
// Verify that connection status has been updated when agent is already connected
8182
requires.Eventually(func() bool {
82-
return fixture.HasConnectionStatus(os.Getenv(fixture.ManagedAgentServerKey), appv1.ConnectionState{
83+
return fixture.HasConnectionStatus(fixture.AgentManagedName, appv1.ConnectionState{
8384
Status: appv1.ConnectionStatusSuccessful,
8485
Message: fmt.Sprintf(message, fixture.AgentManagedName, "connected"),
85-
})
86+
}, clusterDetail)
8687
}, 30*time.Second, 1*time.Second)
8788

8889
// Stop the agent
@@ -91,11 +92,11 @@ func (suite *ClusterInfoTestSuite) Test_ClusterInfo_Managed() {
9192

9293
// Verify that connection status is updated when agent is disconnected
9394
requires.Eventually(func() bool {
94-
return fixture.HasConnectionStatus(os.Getenv(fixture.ManagedAgentServerKey), appv1.ConnectionState{
95+
return fixture.HasConnectionStatus(fixture.AgentManagedName, appv1.ConnectionState{
9596
Status: appv1.ConnectionStatusFailed,
9697
Message: fmt.Sprintf(message, fixture.AgentManagedName, "disconnected"),
9798
ModifiedAt: &metav1.Time{Time: time.Now()},
98-
})
99+
}, clusterDetail)
99100
}, 30*time.Second, 1*time.Second)
100101

101102
// Restart the agent
@@ -105,23 +106,24 @@ func (suite *ClusterInfoTestSuite) Test_ClusterInfo_Managed() {
105106

106107
// Verify that connection status is updated again when agent is re-connected
107108
requires.Eventually(func() bool {
108-
return fixture.HasConnectionStatus(os.Getenv(fixture.ManagedAgentServerKey), appv1.ConnectionState{
109+
return fixture.HasConnectionStatus(fixture.AgentManagedName, appv1.ConnectionState{
109110
Status: appv1.ConnectionStatusSuccessful,
110111
Message: fmt.Sprintf(message, fixture.AgentManagedName, "connected"),
111112
ModifiedAt: &metav1.Time{Time: time.Now()},
112-
})
113+
}, clusterDetail)
113114
}, 30*time.Second, 1*time.Second)
114115
}
115116

116117
func (suite *ClusterInfoTestSuite) Test_ClusterInfo_Autonomous() {
117118
requires := suite.Require()
119+
clusterDetail := suite.ClusterDetails
118120

119121
// Verify the connection status is updated when agent is already connected
120122
requires.Eventually(func() bool {
121-
return fixture.HasConnectionStatus(os.Getenv(fixture.AutonomousAgentServerKey), appv1.ConnectionState{
123+
return fixture.HasConnectionStatus(fixture.AgentAutonomousName, appv1.ConnectionState{
122124
Status: appv1.ConnectionStatusSuccessful,
123125
Message: fmt.Sprintf(message, fixture.AgentAutonomousName, "connected"),
124-
})
126+
}, clusterDetail)
125127
}, 30*time.Second, 1*time.Second)
126128

127129
// Stop the agent
@@ -130,11 +132,11 @@ func (suite *ClusterInfoTestSuite) Test_ClusterInfo_Autonomous() {
130132

131133
// Verify that connection status is updated when agent is disconnected
132134
requires.Eventually(func() bool {
133-
return fixture.HasConnectionStatus(os.Getenv(fixture.AutonomousAgentServerKey), appv1.ConnectionState{
135+
return fixture.HasConnectionStatus(fixture.AgentAutonomousName, appv1.ConnectionState{
134136
Status: appv1.ConnectionStatusFailed,
135137
Message: fmt.Sprintf(message, fixture.AgentAutonomousName, "disconnected"),
136138
ModifiedAt: &metav1.Time{Time: time.Now()},
137-
})
139+
}, clusterDetail)
138140
}, 30*time.Second, 1*time.Second)
139141

140142
// Restart the agent
@@ -144,21 +146,22 @@ func (suite *ClusterInfoTestSuite) Test_ClusterInfo_Autonomous() {
144146

145147
// Verify that connection status is updated again when agent is re-connected
146148
requires.Eventually(func() bool {
147-
return fixture.HasConnectionStatus(os.Getenv(fixture.AutonomousAgentServerKey), appv1.ConnectionState{
149+
return fixture.HasConnectionStatus(fixture.AgentAutonomousName, appv1.ConnectionState{
148150
Status: appv1.ConnectionStatusSuccessful,
149151
Message: fmt.Sprintf(message, fixture.AgentAutonomousName, "connected"),
150152
ModifiedAt: &metav1.Time{Time: time.Now()},
151-
})
153+
}, clusterDetail)
152154
}, 30*time.Second, 1*time.Second)
153155
}
154156

155157
// This test suite validates the cluster cache info reporting for managed agent.
156158
// It checks that the cluster cache info is correctly propagated from agent to principal.
157159
func (suite *ClusterInfoTestSuite) Test_ClusterCacheInfo() {
158160
requires := suite.Require()
161+
clusterDetail := suite.ClusterDetails
159162

160163
// We need to know the number of existing applications before running test
161-
agentCacheInfo, err := fixture.GetManagedAgentClusterInfo()
164+
agentCacheInfo, err := fixture.GetManagedAgentClusterInfo(clusterDetail)
162165
requires.NoError(err)
163166
appCountBefore := agentCacheInfo.ApplicationsCount
164167

@@ -172,11 +175,11 @@ func (suite *ClusterInfoTestSuite) Test_ClusterCacheInfo() {
172175
// Verify that cluster cache info has been updated for first application in agent cluster by Argo CD
173176
// and then agent updated principal with this information
174177
requires.Eventually(func() bool {
175-
return fixture.HasApplicationsCount(appCountBefore + 1)
178+
return fixture.HasApplicationsCount(appCountBefore+1, clusterDetail)
176179
}, 90*time.Second, 5*time.Second)
177180

178181
requires.Eventually(func() bool {
179-
return fixture.HasClusterCacheInfoSynced(os.Getenv(fixture.ManagedAgentServerKey))
182+
return fixture.HasClusterCacheInfoSynced(fixture.AgentManagedName, clusterDetail)
180183
}, 90*time.Second, 5*time.Second)
181184

182185
// Step 3:
@@ -189,11 +192,11 @@ func (suite *ClusterInfoTestSuite) Test_ClusterCacheInfo() {
189192
// Verify that cluster cache info has been updated by Argo CD for second application in agent cluster
190193
// and then agent again updated principal with this new information
191194
requires.Eventually(func() bool {
192-
return fixture.HasApplicationsCount(appCountBefore + 2)
195+
return fixture.HasApplicationsCount(appCountBefore+2, clusterDetail)
193196
}, 90*time.Second, 5*time.Second)
194197

195198
requires.Eventually(func() bool {
196-
return fixture.HasClusterCacheInfoSynced(os.Getenv(fixture.ManagedAgentServerKey))
199+
return fixture.HasClusterCacheInfoSynced(fixture.AgentManagedName, clusterDetail)
197200
}, 90*time.Second, 5*time.Second)
198201

199202
// Step 5:
@@ -210,37 +213,37 @@ func (suite *ClusterInfoTestSuite) Test_ClusterCacheInfo() {
210213
// Verify that cluster cache info has been updated again by Argo CD after deleting the first application
211214
// and then agent again updated principal with this new information
212215
requires.Eventually(func() bool {
213-
return fixture.HasApplicationsCount(appCountBefore + 1)
216+
return fixture.HasApplicationsCount(appCountBefore+1, clusterDetail)
214217
}, 90*time.Second, 5*time.Second)
215218

216219
requires.Eventually(func() bool {
217-
return fixture.HasClusterCacheInfoSynced(os.Getenv(fixture.ManagedAgentServerKey))
220+
return fixture.HasClusterCacheInfoSynced(fixture.AgentManagedName, clusterDetail)
218221
}, 90*time.Second, 5*time.Second)
219222

220223
// Step 7:
221224
// Verify that existing agent connection status is preserved when cluster cache info is updated
222225
requires.Eventually(func() bool {
223-
return fixture.HasConnectionStatus(os.Getenv(fixture.ManagedAgentServerKey), appv1.ConnectionState{
226+
return fixture.HasConnectionStatus(fixture.AgentManagedName, appv1.ConnectionState{
224227
Status: appv1.ConnectionStatusSuccessful,
225228
Message: fmt.Sprintf(message, fixture.AgentManagedName, "connected"),
226-
})
229+
}, clusterDetail)
227230
}, 30*time.Second, 1*time.Second)
228231

229232
// Step 8:
230233
// Disconnect agent and verify that connection status is changed to Failed
231234
requires.NoError(fixture.StopProcess(fixture.AgentManagedName))
232235
requires.Eventually(func() bool {
233-
return fixture.HasConnectionStatus(os.Getenv(fixture.ManagedAgentServerKey), appv1.ConnectionState{
236+
return fixture.HasConnectionStatus(fixture.AgentManagedName, appv1.ConnectionState{
234237
Status: appv1.ConnectionStatusFailed,
235238
Message: fmt.Sprintf(message, fixture.AgentManagedName, "disconnected"),
236239
ModifiedAt: &metav1.Time{Time: time.Now()},
237-
})
240+
}, clusterDetail)
238241
}, 60*time.Second, 2*time.Second)
239242

240243
// Step 9:
241244
// Since agent is disconnected, cluster cache info should reset to default
242245
requires.Eventually(func() bool {
243-
ci, err := fixture.GetPrincipalClusterInfo(os.Getenv(fixture.ManagedAgentServerKey))
246+
ci, err := fixture.GetPrincipalClusterInfo(fixture.AgentManagedName, clusterDetail)
244247
if err != nil {
245248
return false
246249
}
@@ -253,14 +256,14 @@ func (suite *ClusterInfoTestSuite) Test_ClusterCacheInfo() {
253256
fixture.CheckReadiness(suite.T(), fixture.AgentManagedName)
254257

255258
requires.Eventually(func() bool {
256-
return fixture.HasConnectionStatus(os.Getenv(fixture.ManagedAgentServerKey), appv1.ConnectionState{
259+
return fixture.HasConnectionStatus(fixture.AgentManagedName, appv1.ConnectionState{
257260
Status: appv1.ConnectionStatusSuccessful,
258261
Message: fmt.Sprintf(message, fixture.AgentManagedName, "connected"),
259262
ModifiedAt: &metav1.Time{Time: time.Now()},
260-
})
263+
}, clusterDetail)
261264
}, 60*time.Second, 2*time.Second)
262265

263266
requires.Eventually(func() bool {
264-
return fixture.HasClusterCacheInfoSynced(os.Getenv(fixture.ManagedAgentServerKey))
267+
return fixture.HasClusterCacheInfoSynced(fixture.AgentManagedName, clusterDetail)
265268
}, 90*time.Second, 5*time.Second)
266269
}

0 commit comments

Comments
 (0)