Skip to content

Commit

Permalink
Add markFailedAfter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBaeumer committed Dec 17, 2021
1 parent 4e600f7 commit a48929e
Showing 1 changed file with 51 additions and 20 deletions.
71 changes: 51 additions & 20 deletions pkg/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ var _ = Describe("Reconciler", func() {
Expect(r.valueMapper.Map(chartutil.Values{})).To(Equal(chartutil.Values{"mapped": true}))
})
})
var _ = Describe("WithMarkedFailAfter", func() {
It("should set the reconciler mark failed after duration", func() {
Expect(WithMarkFailedAfter(1*time.Minute)(r)).To(Succeed())
Expect(r.markFailedAfter).To(Equal(1*time.Minute))
})
})
})

var _ = Describe("Reconcile", func() {
Expand Down Expand Up @@ -466,36 +472,61 @@ var _ = Describe("Reconciler", func() {
})

When("release is in pending state", func() {
It("should be marked as failed", func() {
fakeClient := helmfake.NewActionClient()
r.markFailedAfter = 5 * time.Minute
r.actionClientGetter = helmclient.ActionClientGetterFunc(func (object client.Object) (helmclient.ActionInterface, error) {
fakeClient := helmfake.NewActionClient()
deployTime := helmTime.Now().Add(-5 * time.Minute)
exampleRelease := &release.Release{
Name: "example-release",
Info: &release.Info{
Status: release.StatusPendingUpgrade,
LastDeployed: deployTime,
FirstDeployed: deployTime,
},
}

BeforeEach(func() {
r.actionClientGetter = helmclient.ActionClientGetterFunc(func(object client.Object) (helmclient.ActionInterface, error) {
fakeClient.HandleGet = func() (*release.Release, error) {
return &release.Release{
Name: "example-release",
Info: &release.Info{
Status: release.StatusPendingUpgrade,
LastDeployed: helmTime.Now(),
FirstDeployed: helmTime.Now(),
},
}, nil
return exampleRelease, nil
}
fakeClient.HandleMarkFailed = func() error {
return nil
}
return &fakeClient, nil
})
})
AfterEach(func() {
r.actionClientGetter = nil
})

_, 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"))
When("time elapsed since last deployment exceeds markFailedAfter duration", func() {
It("should be marked as failed", func() {
r.markFailedAfter = 1 * time.Minute
res, err := r.Reconcile(ctx, req)
Expect(res).To(Equal(reconcile.Result{}))
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))
})
})

r.markFailedAfter = 1
When("markFailedAfter is disabled", func() {
It("should require user intervention", func() {
r.markFailedAfter = 0
res, err := r.Reconcile(ctx, req)
Expect(res).To(Equal(reconcile.Result{}))
Expect(err).ToNot(BeNil())
Expect(err).To(MatchError("Release is in a pending (locked) state and cannot be modified. User intervention is required."))
})
})

_, 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))
When("time since last deployment is higher than markFiledAfter duration", func () {
It("should return duration until the release will be marked as failed", func () {
r.markFailedAfter = 10*time.Minute
res, err := r.Reconcile(ctx, req)
Expect(res).To(Equal(reconcile.Result{}))
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"))
})
})
})

Expand Down

0 comments on commit a48929e

Please sign in to comment.