Skip to content

Commit aacf6f1

Browse files
committed
test(agent): use WithStatusSubresource in snapshot boot test
1 parent 70e88c0 commit aacf6f1

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

internal/agent/firecracker_driver_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ func TestFirecrackerDriver_applySnapshotBoot_noPath(t *testing.T) {
469469
snap.Namespace = "default"
470470
snap.Name = "snap-nopath"
471471
// snap.Status.SnapshotPath is empty — snapshot not yet written to disk.
472+
// WithStatusSubresource is intentionally omitted: the zero-value status
473+
// needs no separate status write and the empty path is what we are testing.
472474

473475
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(snap).Build()
474476

@@ -497,9 +499,20 @@ func TestFirecrackerDriver_applySnapshotBoot_withPath(t *testing.T) {
497499
snap := &impdevv1alpha1.ImpVMSnapshot{}
498500
snap.Namespace = "default"
499501
snap.Name = "snap-ready"
500-
snap.Status.SnapshotPath = "/mnt/snaps/default/p/c"
501502

502-
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(snap).Build()
503+
// Register snap with WithStatusSubresource so that the fake client enforces
504+
// the status subresource boundary (mirrors real API server semantics).
505+
fakeClient := fake.NewClientBuilder().
506+
WithScheme(scheme).
507+
WithObjects(snap).
508+
WithStatusSubresource(snap).
509+
Build()
510+
511+
// Write status through the status subresource, as a real controller would.
512+
snap.Status.SnapshotPath = "/mnt/snaps/default/p/c"
513+
if err := fakeClient.Status().Update(context.Background(), snap); err != nil {
514+
t.Fatalf("status update: %v", err)
515+
}
503516

504517
d := &FirecrackerDriver{Client: fakeClient}
505518

0 commit comments

Comments
 (0)