Skip to content

Commit a19042d

Browse files
committed
Add corner case object setup for full test coverage
1 parent 109f732 commit a19042d

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

pkg/resource-handler/controller/shard/shard_controller_internal_test.go

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ func TestUpdateStatus_MultiOrch(t *testing.T) {
399399
expectError bool
400400
expectOrchReady bool
401401
setupClient func(*testing.T, *runtime.Scheme, *multigresv1alpha1.Shard) client.Client
402+
customShard *multigresv1alpha1.Shard // Optional: override default shard
402403
}{
403404
"GetError": {
404405
expectError: true,
@@ -449,6 +450,28 @@ func TestUpdateStatus_MultiOrch(t *testing.T) {
449450
},
450451
},
451452
},
453+
"NotFound": {
454+
expectError: false,
455+
expectOrchReady: false,
456+
setupObjects: []client.Object{}, // No MultiOrch Deployment - will get NotFound
457+
},
458+
"NoCellsInMultiOrchOrPools": {
459+
expectError: false,
460+
expectOrchReady: false,
461+
setupObjects: []client.Object{},
462+
customShard: &multigresv1alpha1.Shard{
463+
ObjectMeta: metav1.ObjectMeta{
464+
Name: "test-shard",
465+
Namespace: "default",
466+
},
467+
Spec: multigresv1alpha1.ShardSpec{
468+
MultiOrch: multigresv1alpha1.MultiOrchSpec{
469+
Cells: []multigresv1alpha1.CellName{}, // Empty
470+
},
471+
Pools: map[string]multigresv1alpha1.PoolSpec{}, // Empty
472+
},
473+
},
474+
},
452475
}
453476

454477
for name, tc := range tests {
@@ -457,17 +480,21 @@ func TestUpdateStatus_MultiOrch(t *testing.T) {
457480
_ = multigresv1alpha1.AddToScheme(scheme)
458481
_ = appsv1.AddToScheme(scheme)
459482

460-
shard := &multigresv1alpha1.Shard{
461-
ObjectMeta: metav1.ObjectMeta{
462-
Name: "test-shard",
463-
Namespace: "default",
464-
},
465-
Spec: multigresv1alpha1.ShardSpec{
466-
MultiOrch: multigresv1alpha1.MultiOrchSpec{
467-
Cells: []multigresv1alpha1.CellName{"zone1"},
483+
// Use custom shard if provided, otherwise use default
484+
shard := tc.customShard
485+
if shard == nil {
486+
shard = &multigresv1alpha1.Shard{
487+
ObjectMeta: metav1.ObjectMeta{
488+
Name: "test-shard",
489+
Namespace: "default",
468490
},
469-
Pools: map[string]multigresv1alpha1.PoolSpec{},
470-
},
491+
Spec: multigresv1alpha1.ShardSpec{
492+
MultiOrch: multigresv1alpha1.MultiOrchSpec{
493+
Cells: []multigresv1alpha1.CellName{"zone1"},
494+
},
495+
Pools: map[string]multigresv1alpha1.PoolSpec{},
496+
},
497+
}
471498
}
472499

473500
var fakeClient client.Client

0 commit comments

Comments
 (0)