Skip to content

Commit c62b364

Browse files
committed
Add testing for ConditionWithContextFunc
1 parent 936ca4c commit c62b364

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

internal/framework/status/conditionWithContextFunc_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func TestConditionWithContextFunc_GetFails(t *testing.T) {
2222
g := NewWithT(t)
2323
fakeStatusUpdater := &statusfakes.FakeStatusUpdater{}
2424
fakeGetter := &controllerfakes.FakeGetter{}
25+
2526
fakeGetter.GetReturns(errors.New("failed to get resource"))
2627
f := status.ConditionWithContextFunc(
2728
fakeGetter,
@@ -31,6 +32,7 @@ func TestConditionWithContextFunc_GetFails(t *testing.T) {
3132
logr.New(nil),
3233
func(client.Object) {})
3334
boolean, err := f(context.Background())
35+
3436
g.Expect(err).ToNot(HaveOccurred())
3537
g.Expect(boolean).To(BeFalse())
3638
}
@@ -39,6 +41,7 @@ func TestConditionWithContextFunc_GetFailsIsNotFound(t *testing.T) {
3941
g := NewWithT(t)
4042
fakeStatusUpdater := &statusfakes.FakeStatusUpdater{}
4143
fakeGetter := &controllerfakes.FakeGetter{}
44+
4245
fakeGetter.GetReturns(apierrors.NewNotFound(schema.GroupResource{}, "not found"))
4346
f := status.ConditionWithContextFunc(
4447
fakeGetter,
@@ -48,6 +51,7 @@ func TestConditionWithContextFunc_GetFailsIsNotFound(t *testing.T) {
4851
logr.New(nil),
4952
func(client.Object) {})
5053
boolean, err := f(context.Background())
54+
5155
g.Expect(err).ToNot(HaveOccurred())
5256
g.Expect(boolean).To(BeTrue())
5357
}
@@ -56,6 +60,7 @@ func TestConditionWithContextFunc_UpdateFails(t *testing.T) {
5660
g := NewWithT(t)
5761
fakeStatusUpdater := &statusfakes.FakeStatusUpdater{}
5862
fakeGetter := &controllerfakes.FakeGetter{}
63+
5964
fakeStatusUpdater.UpdateReturns(errors.New("failed to update resource"))
6065
f := status.ConditionWithContextFunc(
6166
fakeGetter,
@@ -65,6 +70,7 @@ func TestConditionWithContextFunc_UpdateFails(t *testing.T) {
6570
logr.New(nil),
6671
func(client.Object) {})
6772
boolean, err := f(context.Background())
73+
6874
g.Expect(err).ToNot(HaveOccurred())
6975
g.Expect(boolean).To(BeFalse())
7076
}
@@ -73,6 +79,7 @@ func TestConditionWithContextFunc_NothingFails(t *testing.T) {
7379
g := NewWithT(t)
7480
fakeStatusUpdater := &statusfakes.FakeStatusUpdater{}
7581
fakeGetter := &controllerfakes.FakeGetter{}
82+
7683
f := status.ConditionWithContextFunc(
7784
fakeGetter,
7885
fakeStatusUpdater,
@@ -81,6 +88,7 @@ func TestConditionWithContextFunc_NothingFails(t *testing.T) {
8188
logr.New(nil),
8289
func(client.Object) {})
8390
boolean, err := f(context.Background())
91+
8492
g.Expect(err).ToNot(HaveOccurred())
8593
g.Expect(boolean).To(BeTrue())
8694
}

internal/framework/status/status_updater.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import (
1111
// StatusUpdater updates a resource from the k8s API.
1212
// It allows us to mock the client.Reader.Status.Update method.
1313
//
14+
// There already is an interface in updater.go that is named "Updater"
15+
// so naming this StatusUpdater works, but the linter does not like
16+
// the interface name starting with the package name.
1417
// nolint:revive
1518
type StatusUpdater interface {
1619
// Update is from client.StatusClient.SubResourceWriter.

internal/framework/status/updater.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,6 @@ func (upd *UpdaterImpl) updateGatewayAPI(ctx context.Context, statuses GatewayAP
222222
}
223223
}
224224

225-
// The function in wait.ExponentialBackoffWithContext will retry if it returns nil as its error,
226-
// which is what we want if we encounter an error from the functions we call. However,
227-
// the linter will complain if we return nil if an error was found.
228-
//
229-
//nolint:nilerr
230225
func (upd *UpdaterImpl) writeStatuses(
231226
ctx context.Context,
232227
nsname types.NamespacedName,
@@ -256,7 +251,14 @@ func (upd *UpdaterImpl) writeStatuses(
256251
}
257252

258253
// ConditionWithContextFunc returns a function which will be used in wait.ExponentialBackoffWithContext.
259-
// Exported for testing purposes.
254+
// The function will attempt to Update a kubernetes resource and will be retried in
255+
// wait.ExponentialBackoffWithContext if an error occurs. Exported for testing purposes.
256+
//
257+
// wait.ExponentialBackoffWithContext will retry if this function returns nil as its error,
258+
// which is what we want if we encounter an error from the functions we call. However,
259+
// the linter will complain if we return nil if an error was found.
260+
//
261+
//nolint:nilerr
260262
func ConditionWithContextFunc(
261263
getter controller.Getter,
262264
updater StatusUpdater,

0 commit comments

Comments
 (0)