Skip to content

Commit 9b9fe73

Browse files
committed
chore: Use data driven test
Signed-off-by: Oliver Gondža <[email protected]>
1 parent ccc0095 commit 9b9fe73

File tree

1 file changed

+55
-53
lines changed

1 file changed

+55
-53
lines changed

test/e2e/app_autosync_test.go

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -94,59 +94,61 @@ func TestAutoSyncSelfHealEnabled(t *testing.T) {
9494
}
9595

9696
func TestAutoSyncSelfHealRetryAndRefreshEnabled(t *testing.T) {
97-
autoSyncSelfHealRetryAndRefreshEnabled(t, 100)
98-
autoSyncSelfHealRetryAndRefreshEnabled(t, -1)
99-
}
97+
limits := []int64{
98+
100, // Repeat enough times to see we move on to 3rd commit without reaching the limit
99+
-1, // Repeat forever
100+
}
100101

101-
func autoSyncSelfHealRetryAndRefreshEnabled(t *testing.T, limit int64) {
102-
Given(t).
103-
Path(guestbookPath).
104-
When().
105-
// Correctly configured app should be auto-synced once created
106-
CreateFromFile(func(app *Application) {
107-
app.Spec.SyncPolicy = &SyncPolicy{
108-
Automated: &SyncPolicyAutomated{
109-
SelfHeal: true,
110-
},
111-
Retry: &RetryStrategy{
112-
Limit: limit,
113-
Refresh: true,
114-
},
115-
}
116-
}).
117-
Then().
118-
Expect(OperationPhaseIs(OperationSucceeded)).
119-
Expect(SyncStatusIs(SyncStatusCodeSynced)).
120-
Expect(NoConditions()).
121-
// Broken commit should make the app stuck retrying indefinitely
122-
When().
123-
PatchFile("guestbook-ui-deployment.yaml", `[{"op": "replace", "path": "/spec/revisionHistoryLimit", "value": "badValue"}]`).
124-
Refresh(RefreshTypeNormal).
125-
Then().
126-
Expect(OperationPhaseIs(OperationRunning)).
127-
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
128-
Expect(OperationMessageContains("one or more objects failed to apply")).
129-
Expect(OperationMessageContains("Retrying attempt #1")).
130-
// Wait to make sure the condition is consistent
131-
And(func(_ *Application) {
132-
time.Sleep(10 * time.Second)
133-
}).
134-
Expect(OperationPhaseIs(OperationRunning)).
135-
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
136-
Expect(OperationMessageContains("one or more objects failed to apply")).
137-
Expect(OperationMessageContains("Retrying attempt #2")).
102+
for _, limit := range limits {
103+
Given(t).
104+
Path(guestbookPath).
105+
When().
106+
// Correctly configured app should be auto-synced once created
107+
CreateFromFile(func(app *Application) {
108+
app.Spec.SyncPolicy = &SyncPolicy{
109+
Automated: &SyncPolicyAutomated{
110+
SelfHeal: true,
111+
},
112+
Retry: &RetryStrategy{
113+
Limit: limit,
114+
Refresh: true,
115+
},
116+
}
117+
}).
118+
Then().
119+
Expect(OperationPhaseIs(OperationSucceeded)).
120+
Expect(SyncStatusIs(SyncStatusCodeSynced)).
121+
Expect(NoConditions()).
122+
// Broken commit should make the app stuck retrying indefinitely
123+
When().
124+
PatchFile("guestbook-ui-deployment.yaml", `[{"op": "replace", "path": "/spec/revisionHistoryLimit", "value": "badValue"}]`).
125+
Refresh(RefreshTypeNormal).
126+
Then().
127+
Expect(OperationPhaseIs(OperationRunning)).
128+
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
129+
Expect(OperationMessageContains("one or more objects failed to apply")).
130+
Expect(OperationMessageContains("Retrying attempt #1")).
131+
// Wait to make sure the condition is consistent
132+
And(func(_ *Application) {
133+
time.Sleep(10 * time.Second)
134+
}).
135+
Expect(OperationPhaseIs(OperationRunning)).
136+
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
137+
Expect(OperationMessageContains("one or more objects failed to apply")).
138+
Expect(OperationMessageContains("Retrying attempt #2")).
138139

139-
// Push fix commit and see the app pick it up
140-
When().
141-
// Fix declaration
142-
PatchFile("guestbook-ui-deployment.yaml", `[{"op": "replace", "path": "/spec/revisionHistoryLimit", "value": 42}]`).
143-
Refresh(RefreshTypeNormal).
144-
Then().
145-
// Wait for the sync retry to pick up new commit
146-
And(func(_ *Application) {
147-
time.Sleep(10 * time.Second)
148-
}).
149-
Expect(NoConditions()).
150-
Expect(SyncStatusIs(SyncStatusCodeSynced)).
151-
Expect(OperationPhaseIs(OperationSucceeded))
140+
// Push fix commit and see the app pick it up
141+
When().
142+
// Fix declaration
143+
PatchFile("guestbook-ui-deployment.yaml", `[{"op": "replace", "path": "/spec/revisionHistoryLimit", "value": 42}]`).
144+
Refresh(RefreshTypeNormal).
145+
Then().
146+
// Wait for the sync retry to pick up new commit
147+
And(func(_ *Application) {
148+
time.Sleep(10 * time.Second)
149+
}).
150+
Expect(NoConditions()).
151+
Expect(SyncStatusIs(SyncStatusCodeSynced)).
152+
Expect(OperationPhaseIs(OperationSucceeded))
153+
}
152154
}

0 commit comments

Comments
 (0)