Skip to content

Commit 43118a3

Browse files
committed
Keep test helper structs private.
1 parent 072ad4b commit 43118a3

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

pkg/internal/controller/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (c *Controller[request]) DidFinishWarmup(ctx context.Context) bool {
192192

193193
if !*didFinishSync {
194194
// event sources finished syncing with an error
195-
return true, errors.New("event sources did not finish syncing succesfully")
195+
return true, errors.New("event sources did not finish syncing successfully")
196196
}
197197

198198
return true, nil

pkg/manager/manager_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ var _ = Describe("manger.Manager", func() {
19521952

19531953
By("Creating a runnable that implements WarmupRunnable interface")
19541954
// Create a warmup runnable
1955-
warmupRunnable := WarmupRunnableFunc{
1955+
warmupRunnable := warmupRunnableFunc{
19561956
RunFunc: func(ctx context.Context) error {
19571957
// This is the main runnable that will be executed after leader election
19581958
<-ctx.Done()
@@ -1967,7 +1967,7 @@ var _ = Describe("manger.Manager", func() {
19671967
Expect(m.Add(warmupRunnable)).To(Succeed())
19681968

19691969
By("Creating a runnable that requires leader election")
1970-
leaderElectionRunnable := LeaderElectionRunnableFunc{
1970+
leaderElectionRunnable := leaderElectionRunnableFunc{
19711971
RunFunc: func(ctx context.Context) error {
19721972
// This will only be called after leader election is won
19731973
close(leaderElectionRunnableCalled)

pkg/manager/runnable_group_test.go

+30-18
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var _ = Describe("runnables", func() {
5555
})
5656

5757
It("should add WarmupRunnable to the Warmup and LeaderElection group", func() {
58-
warmupRunnable := WarmupRunnableFunc{
58+
warmupRunnable := warmupRunnableFunc{
5959
RunFunc: func(c context.Context) error {
6060
<-c.Done()
6161
return nil
@@ -72,7 +72,7 @@ var _ = Describe("runnables", func() {
7272
})
7373

7474
It("should add WarmupRunnable that doesn't needs leader election to warmup group only", func() {
75-
warmupRunnable := CombinedRunnable{
75+
warmupRunnable := combinedRunnable{
7676
RunFunc: func(c context.Context) error {
7777
<-c.Done()
7878
return nil
@@ -93,7 +93,7 @@ var _ = Describe("runnables", func() {
9393
})
9494

9595
It("should add WarmupRunnable that needs leader election to Warmup and LeaderElection group, not Others", func() {
96-
warmupRunnable := CombinedRunnable{
96+
warmupRunnable := combinedRunnable{
9797
RunFunc: func(c context.Context) error {
9898
<-c.Done()
9999
return nil
@@ -117,7 +117,7 @@ var _ = Describe("runnables", func() {
117117
It("should execute the Warmup function when Warmup group is started", func() {
118118
var warmupExecuted atomic.Bool
119119

120-
warmupRunnable := WarmupRunnableFunc{
120+
warmupRunnable := warmupRunnableFunc{
121121
RunFunc: func(c context.Context) error {
122122
<-c.Done()
123123
return nil
@@ -144,7 +144,7 @@ var _ = Describe("runnables", func() {
144144
It("should propagate errors from Warmup function to error channel", func() {
145145
expectedErr := fmt.Errorf("expected warmup error")
146146

147-
warmupRunnable := WarmupRunnableFunc{
147+
warmupRunnable := warmupRunnableFunc{
148148
RunFunc: func(c context.Context) error {
149149
<-c.Done()
150150
return nil
@@ -349,51 +349,63 @@ var _ = Describe("runnableGroup", func() {
349349
})
350350
})
351351

352-
// LeaderElectionRunnableFunc is a helper struct that implements LeaderElectionRunnable
352+
var _ LeaderElectionRunnable = &leaderElectionRunnableFunc{}
353+
354+
// leaderElectionRunnableFunc is a helper struct that implements LeaderElectionRunnable
353355
// for testing purposes.
354-
type LeaderElectionRunnableFunc struct {
356+
type leaderElectionRunnableFunc struct {
355357
RunFunc func(context.Context) error
356358
NeedLeaderElectionFunc func() bool
357359
}
358360

359-
func (r LeaderElectionRunnableFunc) Start(ctx context.Context) error {
361+
func (r leaderElectionRunnableFunc) Start(ctx context.Context) error {
360362
return r.RunFunc(ctx)
361363
}
362364

363-
func (r LeaderElectionRunnableFunc) NeedLeaderElection() bool {
365+
func (r leaderElectionRunnableFunc) NeedLeaderElection() bool {
364366
return r.NeedLeaderElectionFunc()
365367
}
366368

367-
// WarmupRunnableFunc is a helper struct that implements WarmupRunnable
369+
var _ WarmupRunnable = &warmupRunnableFunc{}
370+
371+
// warmupRunnableFunc is a helper struct that implements WarmupRunnable
368372
// for testing purposes.
369-
type WarmupRunnableFunc struct {
373+
type warmupRunnableFunc struct {
370374
RunFunc func(context.Context) error
371375
WarmupFunc func(context.Context) error
372376
}
373377

374-
func (r WarmupRunnableFunc) Start(ctx context.Context) error {
378+
func (r warmupRunnableFunc) Start(ctx context.Context) error {
375379
return r.RunFunc(ctx)
376380
}
377381

378-
func (r WarmupRunnableFunc) Warmup(ctx context.Context) error {
382+
func (r warmupRunnableFunc) Warmup(ctx context.Context) error {
379383
return r.WarmupFunc(ctx)
380384
}
381385

382-
// CombinedRunnable implements both WarmupRunnable and LeaderElectionRunnable
383-
type CombinedRunnable struct {
386+
func (r warmupRunnableFunc) WaitForWarmupComplete(ctx context.Context) bool {
387+
return true
388+
}
389+
390+
// combinedRunnable implements both WarmupRunnable and LeaderElectionRunnable
391+
type combinedRunnable struct {
384392
RunFunc func(context.Context) error
385393
WarmupFunc func(context.Context) error
386394
NeedLeaderElectionFunc func() bool
387395
}
388396

389-
func (r CombinedRunnable) Start(ctx context.Context) error {
397+
func (r combinedRunnable) Start(ctx context.Context) error {
390398
return r.RunFunc(ctx)
391399
}
392400

393-
func (r CombinedRunnable) Warmup(ctx context.Context) error {
401+
func (r combinedRunnable) Warmup(ctx context.Context) error {
394402
return r.WarmupFunc(ctx)
395403
}
396404

397-
func (r CombinedRunnable) NeedLeaderElection() bool {
405+
func (r combinedRunnable) WaitForWarmupComplete(ctx context.Context) bool {
406+
return true
407+
}
408+
409+
func (r combinedRunnable) NeedLeaderElection() bool {
398410
return r.NeedLeaderElectionFunc()
399411
}

0 commit comments

Comments
 (0)