Skip to content

Commit 5d45d80

Browse files
SimonBaeumerporridge
authored andcommitted
Fix updater test to use existing fields from deployment's status field
1 parent 991117d commit 5d45d80

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

pkg/reconciler/internal/updater/updater.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
"k8s.io/client-go/util/retry"
2929
"sigs.k8s.io/controller-runtime/pkg/client"
3030

31-
"github.com/operator-framework/helm-operator/pkg/extensions"
3231
"github.com/operator-framework/helm-operator-plugins/internal/sdk/controllerutil"
32+
"github.com/operator-framework/helm-operator-plugins/pkg/extensions"
3333
"github.com/operator-framework/helm-operator-plugins/pkg/internal/status"
3434
)
3535

pkg/reconciler/internal/updater/updater_test.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ import (
3535
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/conditions"
3636
)
3737

38-
const testFinalizer = "testFinalizer"
38+
const (
39+
testFinalizer = "testFinalizer"
40+
availableReplicasStatus = int64(3)
41+
replicasStatus = int64(5)
42+
)
3943

4044
var _ = Describe("Updater", func() {
4145
var (
@@ -112,12 +116,12 @@ var _ = Describe("Updater", func() {
112116
It("should support a mix of standard and custom status updates", func() {
113117
u.UpdateStatus(EnsureCondition(conditions.Deployed(corev1.ConditionTrue, "", "")))
114118
u.UpdateStatusCustom(func(uSt *unstructured.Unstructured) bool {
115-
Expect(unstructured.SetNestedMap(uSt.Object, map[string]interface{}{"bar": "baz"}, "foo")).To(Succeed())
119+
Expect(unstructured.SetNestedField(uSt.Object, replicasStatus, "replicas")).To(Succeed())
116120
return true
117121
})
118122
u.UpdateStatus(EnsureCondition(conditions.Irreconcilable(corev1.ConditionFalse, "", "")))
119123
u.UpdateStatusCustom(func(uSt *unstructured.Unstructured) bool {
120-
Expect(unstructured.SetNestedField(uSt.Object, "quux", "foo", "qux")).To(Succeed())
124+
Expect(unstructured.SetNestedField(uSt.Object, availableReplicasStatus, "availableReplicas")).To(Succeed())
121125
return true
122126
})
123127
u.UpdateStatus(EnsureCondition(conditions.Initialized(corev1.ConditionTrue, "", "")))
@@ -129,20 +133,20 @@ var _ = Describe("Updater", func() {
129133
Expect(found).To(BeFalse())
130134
Expect(err).To(Not(HaveOccurred()))
131135

132-
val, found, err := unstructured.NestedString(obj.Object, "status", "foo", "bar")
133-
Expect(val).To(Equal("baz"))
136+
val, found, err := unstructured.NestedInt64(obj.Object, "status", "replicas")
137+
Expect(val).To(Equal(replicasStatus))
134138
Expect(found).To(BeTrue())
135139
Expect(err).To(Not(HaveOccurred()))
136140

137-
val, found, err = unstructured.NestedString(obj.Object, "status", "foo", "qux")
138-
Expect(val).To(Equal("quux"))
141+
val, found, err = unstructured.NestedInt64(obj.Object, "status", "availableReplicas")
142+
Expect(val).To(Equal(availableReplicasStatus))
139143
Expect(found).To(BeTrue())
140144
Expect(err).To(Not(HaveOccurred()))
141145
})
142146

143147
It("should preserve any custom status across multiple apply calls", func() {
144148
u.UpdateStatusCustom(func(uSt *unstructured.Unstructured) bool {
145-
Expect(unstructured.SetNestedMap(uSt.Object, map[string]interface{}{"bar": "baz"}, "foo")).To(Succeed())
149+
Expect(unstructured.SetNestedField(uSt.Object, int64(5), "replicas")).To(Succeed())
146150
return true
147151
})
148152
Expect(u.Apply(context.TODO(), obj)).To(Succeed())
@@ -153,8 +157,8 @@ var _ = Describe("Updater", func() {
153157
Expect(found).To(BeFalse())
154158
Expect(err).To(Not(HaveOccurred()))
155159

156-
val, found, err := unstructured.NestedString(obj.Object, "status", "foo", "bar")
157-
Expect(val).To(Equal("baz"))
160+
val, found, err := unstructured.NestedInt64(obj.Object, "status", "replicas")
161+
Expect(val).To(Equal(replicasStatus))
158162
Expect(found).To(BeTrue())
159163
Expect(err).To(Succeed())
160164

@@ -168,8 +172,8 @@ var _ = Describe("Updater", func() {
168172
Expect(found).To(BeFalse())
169173
Expect(err).To(Not(HaveOccurred()))
170174

171-
val, found, err = unstructured.NestedString(obj.Object, "status", "foo", "bar")
172-
Expect(val).To(Equal("baz"))
175+
val, found, err = unstructured.NestedInt64(obj.Object, "status", "replicas")
176+
Expect(val).To(Equal(replicasStatus))
173177
Expect(found).To(BeTrue())
174178
Expect(err).To(Succeed())
175179
})

pkg/reconciler/reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ import (
5050
"github.com/operator-framework/helm-operator-plugins/internal/sdk/controllerutil"
5151
"github.com/operator-framework/helm-operator-plugins/pkg/annotation"
5252
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
53+
"github.com/operator-framework/helm-operator-plugins/pkg/extensions"
5354
"github.com/operator-framework/helm-operator-plugins/pkg/hook"
5455
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/conditions"
5556
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/diff"
5657
internalhook "github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/hook"
5758
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/updater"
5859
internalvalues "github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/values"
5960
"github.com/operator-framework/helm-operator-plugins/pkg/values"
60-
"github.com/joelanford/helm-operator/pkg/extensions"
6161
)
6262

6363
const uninstallFinalizer = "uninstall-helm-release"

0 commit comments

Comments
 (0)