Skip to content

Commit

Permalink
add mark failed test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBaeumer committed Dec 17, 2021
1 parent a15f81f commit 4e600f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pkg/reconciler/internal/fake/actionclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ func NewActionClient() ActionClient {
Upgrades: make([]UpgradeCall, 0),
Uninstalls: make([]UninstallCall, 0),
Reconciles: make([]ReconcileCall, 0),
MarkFaileds: make([]MarkFailedCall, 0),

HandleGet: relFunc(errors.New("get not implemented")),
HandleInstall: relFunc(errors.New("install not implemented")),
HandleUpgrade: relFunc(errors.New("upgrade not implemented")),
HandleUninstall: uninstFunc(errors.New("uninstall not implemented")),
HandleReconcile: recFunc(errors.New("reconcile not implemented")),
HandleMarkFailed: recFunc(errors.New("mark failed not implemented")),
}
}

Expand Down
20 changes: 15 additions & 5 deletions pkg/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ var _ = Describe("Reconciler", func() {

When("release is in pending state", func() {
It("should be marked as failed", func() {
r.markFailedAfter = 5 * time.Second
fakeClient := helmfake.NewActionClient()
r.markFailedAfter = 5 * time.Minute
r.actionClientGetter = helmclient.ActionClientGetterFunc(func (object client.Object) (helmclient.ActionInterface, error) {
fakeClient := helmfake.NewActionClient()
fakeClient.HandleGet = func() (*release.Release, error) {
return &release.Release{
Name: "example-release",
Expand All @@ -480,12 +480,22 @@ var _ = Describe("Reconciler", func() {
},
}, nil
}
fakeClient.HandleMarkFailed = func() error {
return nil
}
return &fakeClient, nil
})

result, err := r.Reconcile(ctx, req)
Expect(err).To(MatchRegexp("adsfsadf"))
Expect(result).To(Equal(reconcile.Result{}))
_, err := r.Reconcile(ctx, req)
Expect(err).ToNot(BeNil())
Expect(err.Error()).Should(ContainSubstring("Release is in a pending (locked) state and cannot currently be modified. Release will be marked failed to allow a roll-forward in"))

r.markFailedAfter = 1

_, err = r.Reconcile(ctx, req)
Expect(err).ToNot(BeNil())
Expect(err).To(MatchError("marked release example-release as failed to allow upgrade to succeed in next reconcile attempt"))
Expect(len(fakeClient.MarkFaileds)).Should(Equal(1))
})
})

Expand Down

0 comments on commit 4e600f7

Please sign in to comment.