Repository: firecracker-microvm/firecracker-containerd
Pull request #718 (2022-11-30 16:54:02)

Don't reassign assert and require
I started this pattern to save few characters, but it isn't really working when you have subtests.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>

*Issue #, if available:*

*Description of changes:*


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.



Patch:
diff --git a/internal/fsutil.go b/internal/fsutil.go
index bd14f54..46cc4b5 100644
--- a/internal/fsutil.go
+++ b/internal/fsutil.go
@@ -73,7 +73,7 @@ func createTestExtImg(ctx context.Context, t *testing.T, extName string, testFil
 }
 
 // CreateBlockDevice creates a block device, or block special file for testing
-func CreateBlockDevice(ctx context.Context, t *testing.T) (string, func()) {
+func CreateBlockDevice(ctx context.Context, t testing.TB) (string, func()) {
 	t.Helper()
 
 	f, err := os.CreateTemp("", "")


Test patch:
diff --git a/runtime/jailer_integ_test.go b/runtime/jailer_integ_test.go
index c29850d..050d2e6 100644
--- a/runtime/jailer_integ_test.go
+++ b/runtime/jailer_integ_test.go
@@ -91,16 +91,14 @@ func fsSafeTestName(tb testing.TB) string {
 }
 
 func testJailer(t *testing.T, jailerConfig *proto.JailerConfig) {
-	require := require.New(t)
-
 	client, err := containerd.New(integtest.ContainerdSockPath, containerd.WithDefaultRuntime(firecrackerRuntime))
-	require.NoError(err, "unable to create client to containerd service at %s, is containerd running?", integtest.ContainerdSockPath)
+	require.NoError(t, err, "unable to create client to containerd service at %s, is containerd running?", integtest.ContainerdSockPath)
 	defer client.Close()
 
 	ctx := namespaces.WithNamespace(context.Background(), "default")
 
 	image, err := alpineImage(ctx, client, defaultSnapshotterName)
-	require.NoError(err, "failed to get alpine image")
+	require.NoError(t, err, "failed to get alpine image")
 
 	vmID := testNameToVMID(t.Name())
 
@@ -120,30 +118,30 @@ func testJailer(t *testing.T, jailerConfig *proto.JailerConfig) {
 	// If the drive files are bind-mounted, the files must be readable from the jailer's user.
 	if jailerConfig != nil && jailerConfig.DriveExposePolicy == proto.DriveExposePolicy_BIND {
 		f, err := os.CreateTemp("", fsSafeTestName(t)+"_rootfs")
-		require.NoError(err)
+		require.NoError(t, err)
 		defer f.Close()
 
 		dst := f.Name()
 
 		// Copy the root drive before chown, since the file is used by other tests.
 		err = copyFile(integtest.DefaultRuntimeConfig.RootDrive, dst, 0400)
-		require.NoErrorf(err, "failed to copy a rootfs as %q", dst)
+		require.NoErrorf(t, err, "failed to copy a rootfs as %q", dst)
 
 		err = os.Chown(dst, int(jailerConfig.UID), int(jailerConfig.GID))
-		require.NoError(err, "failed to chown %q", dst)
+		require.NoError(t, err, "failed to chown %q", dst)
 
 		request.RootDrive = &proto.FirecrackerRootDrive{HostPath: dst}
 
 		// The additional drive file is only used by this test.
 		err = os.Chown(additionalDrive, int(jailerConfig.UID), int(jailerConfig.GID))
-		require.NoError(err, "failed to chown %q", additionalDrive)
+		require.NoError(t, err, "failed to chown %q", additionalDrive)
 	}
 
 	fcClient, err := integtest.NewFCControlClient(integtest.ContainerdSockPath)
-	require.NoError(err)
+	require.NoError(t, err)
 
 	_, err = fcClient.CreateVM(ctx, &request)
-	require.NoError(err)
+	require.NoError(t, err)
 
 	c, err := client.NewContainer(ctx,
 		vmID+"-container",
@@ -161,27 +159,27 @@ func testJailer(t *testing.T, jailerConfig *proto.JailerConfig) {
 			}}),
 		),
 	)
-	require.NoError(err)
+	require.NoError(t, err)
 
 	stdout := startAndWaitTask(ctx, t, c)
-	require.Equal("hello\nadditional drive\n", stdout)
+	require.Equal(t, "hello\nadditional drive\n", stdout)
 
 	stat, err := os.Stat(filepath.Join(integtest.ShimBaseDir(), "default#"+vmID))
-	require.NoError(err)
+	require.NoError(t, err)
 	assert.True(t, stat.IsDir())
 
 	err = c.Delete(ctx, containerd.WithSnapshotCleanup)
-	require.NoError(err, "failed to delete a container")
+	require.NoError(t, err, "failed to delete a container")
 
 	_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: vmID})
-	require.NoError(err)
+	require.NoError(t, err)
 
 	_, err = os.Stat(filepath.Join(integtest.ShimBaseDir(), "default#"+vmID))
 	assert.Error(t, err)
 	assert.True(t, os.IsNotExist(err))
 
 	shimContents, err := os.ReadDir(integtest.ShimBaseDir())
-	require.NoError(err)
+	require.NoError(t, err)
 	assert.Len(t, shimContents, 0)
 }
 
@@ -199,28 +197,27 @@ func TestJailerCPUSet_Isolated(t *testing.T) {
 	testJailer(t, config)
 }
 
-func testAttachBlockDevice(t *testing.T, jailerConfig *proto.JailerConfig) {
-	require := require.New(t)
+func testAttachBlockDevice(tb testing.TB, jailerConfig *proto.JailerConfig) {
 	client, err := containerd.New(integtest.ContainerdSockPath, containerd.WithDefaultRuntime(firecrackerRuntime))
-	require.NoError(err, "unable to create client to containerd service at %s, is containerd running?", integtest.ContainerdSockPath)
+	require.NoError(tb, err, "unable to create client to containerd service at %s, is containerd running?", integtest.ContainerdSockPath)
 	defer client.Close()
 
 	ctx := namespaces.WithNamespace(context.Background(), "default")
 
 	image, err := alpineImage(ctx, client, defaultSnapshotterName)
-	require.NoError(err, "failed to get alpine image")
+	require.NoError(tb, err, "failed to get alpine image")
 
 	fcClient, err := integtest.NewFCControlClient(integtest.ContainerdSockPath)
-	require.NoError(err)
+	require.NoError(tb, err)
 
-	vmID := testNameToVMID(t.Name())
+	vmID := testNameToVMID(tb.Name())
 
-	device, cleanup := internal.CreateBlockDevice(ctx, t)
+	device, cleanup := internal.CreateBlockDevice(ctx, tb)
 	defer cleanup()
 
 	if jailerConfig != nil {
 		err := os.Chown(device, int(jailerConfig.UID), int(jailerConfig.GID))
-		require.NoError(err)
+		require.NoError(tb, err)
 	}
 
 	request := proto.CreateVMRequest{
@@ -233,27 +230,27 @@ func testAttachBlockDevice(t *testing.T, jailerConfig *proto.JailerConfig) {
 
 	// If the drive files are bind-mounted, the files must be readable from the jailer's user.
 	if jailerConfig != nil && jailerConfig.DriveExposePolicy == proto.DriveExposePolicy_BIND {
-		f, err := os.CreateTemp("", fsSafeTestName(t)+"_rootfs")
-		require.NoError(err)
+		f, err := os.CreateTemp("", fsSafeTestName(tb)+"_rootfs")
+		require.NoError(tb, err)
 		defer f.Close()
 
 		dst := f.Name()
 
 		// Copy the root drive before chown, since the file is used by other tests.
 		err = copyFile(integtest.DefaultRuntimeConfig.RootDrive, dst, 0400)
-		require.NoErrorf(err, "failed to copy a rootfs as %q", dst)
+		require.NoErrorf(tb, err, "failed to copy a rootfs as %q", dst)
 
 		err = os.Chown(dst, int(jailerConfig.UID), int(jailerConfig.GID))
-		require.NoError(err, "failed to chown %q", dst)
+		require.NoError(tb, err, "failed to chown %q", dst)
 
 		request.RootDrive = &proto.FirecrackerRootDrive{HostPath: dst}
 
 		err = os.Chown(device, int(jailerConfig.UID), int(jailerConfig.GID))
-		require.NoError(err, "failed to chown %q", device)
+		require.NoError(tb, err, "failed to chown %q", device)
 	}
 
 	_, err = fcClient.CreateVM(ctx, &request)
-	require.NoError(err)
+	require.NoError(tb, err)
 
 	// create a container to test bind mount block device into the container
 	c, err := client.NewContainer(ctx,
@@ -272,26 +269,26 @@ func testAttachBlockDevice(t *testing.T, jailerConfig *proto.JailerConfig) {
 			}}),
 		),
 	)
-	require.NoError(err)
+	require.NoError(tb, err)
 
-	stdout := startAndWaitTask(ctx, t, c)
-	require.Equal("heyhey\n", stdout)
+	stdout := startAndWaitTask(ctx, tb, c)
+	require.Equal(tb, "heyhey\n", stdout)
 
 	stat, err := os.Stat(filepath.Join(integtest.ShimBaseDir(), "default#"+vmID))
-	require.NoError(err)
-	assert.True(t, stat.IsDir())
+	require.NoError(tb, err)
+	assert.True(tb, stat.IsDir())
 
 	err = c.Delete(ctx, containerd.WithSnapshotCleanup)
-	require.NoError(err, "failed to delete a container-block-device")
+	require.NoError(tb, err, "failed to delete a container-block-device")
 
 	_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: vmID})
-	require.NoError(err)
+	require.NoError(tb, err)
 
 	_, err = os.Stat(filepath.Join(integtest.ShimBaseDir(), "default#"+vmID))
-	assert.Error(t, err)
-	assert.True(t, os.IsNotExist(err))
+	assert.Error(tb, err)
+	assert.True(tb, os.IsNotExist(err))
 
 	shimContents, err := os.ReadDir(integtest.ShimBaseDir())
-	require.NoError(err)
-	assert.Len(t, shimContents, 0)
+	require.NoError(tb, err)
+	assert.Len(tb, shimContents, 0)
 }
diff --git a/runtime/limits_integ_test.go b/runtime/limits_integ_test.go
index e93f476..9c1ebe5 100644
--- a/runtime/limits_integ_test.go
+++ b/runtime/limits_integ_test.go
@@ -27,17 +27,14 @@ import (
 func TestDiskLimit_Isolated(t *testing.T) {
 	integtest.Prepare(t)
 
-	assert := assert.New(t)
-	require := require.New(t)
-
 	ctx := namespaces.WithNamespace(context.Background(), "default")
 
 	client, err := containerd.New(integtest.ContainerdSockPath, containerd.WithDefaultRuntime(firecrackerRuntime))
-	require.NoError(err, "unable to create client to containerd service at %s, is containerd running?", integtest.ContainerdSockPath)
+	require.NoError(t, err, "unable to create client to containerd service at %s, is containerd running?", integtest.ContainerdSockPath)
 	defer client.Close()
 
 	image, err := alpineImage(ctx, client, defaultSnapshotterName)
-	require.NoError(err, "failed to get alpine image")
+	require.NoError(t, err, "failed to get alpine image")
 
 	// Right now, both naive snapshotter and devmapper snapshotter are configured to have 1024MB image size.
 	// The former is hard-coded since the snapshotter is not for production. The latter is configured in tools/docker/entrypoint.sh.
@@ -54,14 +51,14 @@ func TestDiskLimit_Isolated(t *testing.T) {
 	)
 	defer func() {
 		err = container.Delete(ctx, containerd.WithSnapshotCleanup)
-		require.NoError(err, "failed to delete a container")
+		require.NoError(t, err, "failed to delete a container")
 	}()
 
 	result, err := integtest.RunTask(ctx, container)
-	require.NoError(err, "failed to create a container")
+	require.NoError(t, err, "failed to create a container")
 
-	assert.Equal(uint32(1), result.ExitCode, "writing 2GB must fail")
-	assert.Equal(`952+0 records in
+	assert.Equal(t, uint32(1), result.ExitCode, "writing 2GB must fail")
+	assert.Equal(t, `952+0 records in
 951+0 records out
 `, result.Stderr, "but it must be able to write ~1024MB")
 }
diff --git a/runtime/service_integ_test.go b/runtime/service_integ_test.go
index 324bd24..f1fb12a 100644
--- a/runtime/service_integ_test.go
+++ b/runtime/service_integ_test.go
@@ -926,7 +926,7 @@ vdf  254:80   0        512B  0 |  214 244 216 245 215 177 177 177`
 	}
 }
 
-func startAndWaitTask(ctx context.Context, t *testing.T, c containerd.Container) string {
+func startAndWaitTask(ctx context.Context, t testing.TB, c containerd.Container) string {
 	var stdout bytes.Buffer
 	var stderr bytes.Buffer
 
@@ -1051,8 +1051,6 @@ func TestCreateContainerWithSameName_Isolated(t *testing.T) {
 func TestStubDriveReserveAndReleaseByContainers_Isolated(t *testing.T) {
 	integtest.Prepare(t)
 
-	assert := assert.New(t)
-
 	ctx := namespaces.WithNamespace(context.Background(), "default")
 
 	client, err := containerd.New(integtest.ContainerdSockPath, containerd.WithDefaultRuntime(firecrackerRuntime))
@@ -1070,7 +1068,7 @@ func TestStubDriveReserveAndReleaseByContainers_Isolated(t *testing.T) {
 		containerd.WithNewSnapshot("c1", image),
 		runEchoHello,
 	)
-	assert.Equal("hello", startAndWaitTask(ctx, t, c1))
+	assert.Equal(t, "hello", startAndWaitTask(ctx, t, c1))
 	require.NoError(t, err, "failed to create a container")
 
 	defer func() {
@@ -1093,7 +1091,7 @@ func TestStubDriveReserveAndReleaseByContainers_Isolated(t *testing.T) {
 
 	// With the new behaviour, on previous task deletion, stub drive will be released
 	// and now can be reused by new container and task.
-	assert.Equal("hello", startAndWaitTask(ctx, t, c2))
+	assert.Equal(t, "hello", startAndWaitTask(ctx, t, c2))
 }
 
 func TestDriveMount_Isolated(t *testing.T) {
@@ -1677,24 +1675,22 @@ func pidExists(pid int) bool {
 
 func TestStopVM_Isolated(t *testing.T) {
 	integtest.Prepare(t)
-	require := require.New(t)
-	assert := assert.New(t)
 
 	client, err := containerd.New(integtest.ContainerdSockPath, containerd.WithDefaultRuntime(firecrackerRuntime))
-	require.NoError(err, "unable to create client to containerd service at %s, is containerd running?", integtest.ContainerdSockPath)
+	require.NoError(t, err, "unable to create client to containerd service at %s, is containerd running?", integtest.ContainerdSockPath)
 	defer client.Close()
 
 	ctx := namespaces.WithNamespace(context.Background(), "default")
 
 	image, err := alpineImage(ctx, client, defaultSnapshotterName)
-	require.NoError(err, "failed to get alpine image")
+	require.NoError(t, err, "failed to get alpine image")
 
 	kernelArgs := integtest.DefaultRuntimeConfig.KernelArgs
 
 	tests := []struct {
 		name            string
 		createVMRequest proto.CreateVMRequest
-		stopFunc        func(ctx context.Context, fcClient fccontrol.FirecrackerService, req proto.CreateVMRequest)
+		stopFunc        func(ctx context.Context, tb testing.TB, fcClient fccontrol.FirecrackerService, req proto.CreateVMRequest)
 		withStopVM      bool
 	}{
 
@@ -1703,9 +1699,9 @@ func TestStopVM_Isolated(t *testing.T) {
 			withStopVM: true,
 
 			createVMRequest: proto.CreateVMRequest{},
-			stopFunc: func(ctx context.Context, fcClient fccontrol.FirecrackerService, req proto.CreateVMRequest) {
+			stopFunc: func(ctx context.Context, tb testing.TB, fcClient fccontrol.FirecrackerService, req proto.CreateVMRequest) {
 				_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: req.VMID})
-				require.Equal(status.Code(err), codes.OK)
+				require.Equal(tb, status.Code(err), codes.OK)
 			},
 		},
 
@@ -1721,11 +1717,11 @@ func TestStopVM_Isolated(t *testing.T) {
 					HostPath: "/var/lib/firecracker-containerd/runtime/rootfs-debug.img",
 				},
 			},
-			stopFunc: func(ctx context.Context, fcClient fccontrol.FirecrackerService, req proto.CreateVMRequest) {
+			stopFunc: func(ctx context.Context, tb testing.TB, fcClient fccontrol.FirecrackerService, req proto.CreateVMRequest) {
 				_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: req.VMID})
-				require.Error(err)
-				assert.Equal(codes.Internal, status.Code(err))
-				assert.Contains(err.Error(), "forcefully terminated")
+				require.Error(tb, err)
+				assert.Equal(tb, codes.Internal, status.Code(err))
+				assert.Contains(tb, err.Error(), "forcefully terminated")
 			},
 		},
 
@@ -1735,14 +1731,14 @@ func TestStopVM_Isolated(t *testing.T) {
 			withStopVM: false,
 
 			createVMRequest: proto.CreateVMRequest{},
-			stopFunc: func(ctx context.Context, _ fccontrol.FirecrackerService, _ proto.CreateVMRequest) {
+			stopFunc: func(ctx context.Context, tb testing.TB, _ fccontrol.FirecrackerService, _ proto.CreateVMRequest) {
 				firecrackerProcesses, err := findProcess(ctx, findFirecracker)
-				require.NoError(err, "failed waiting for expected firecracker process %q to come up", firecrackerProcessName)
-				require.Len(firecrackerProcesses, 1, "expected only one firecracker process to exist")
+				require.NoError(tb, err, "failed waiting for expected firecracker process %q to come up", firecrackerProcessName)
+				require.Len(tb, firecrackerProcesses, 1, "expected only one firecracker process to exist")
 				firecrackerProcess := firecrackerProcesses[0]
 
 				err = firecrackerProcess.KillWithContext(ctx)
-				require.NoError(err, "failed to kill firecracker process")
+				require.NoError(tb, err, "failed to kill firecracker process")
 			},
 		},
 
@@ -1758,16 +1754,16 @@ func TestStopVM_Isolated(t *testing.T) {
 					HostPath: "/var/lib/firecracker-containerd/runtime/rootfs-debug.img",
 				},
 			},
-			stopFunc: func(ctx context.Context, fcClient fccontrol.FirecrackerService, req proto.CreateVMRequest) {
+			stopFunc: func(ctx context.Context, tb testing.TB, fcClient fccontrol.FirecrackerService, req proto.CreateVMRequest) {
 				firecrackerProcesses, err := findProcess(ctx, findFirecracker)
-				require.NoError(err, "failed waiting for expected firecracker process %q to come up", firecrackerProcessName)
-				require.Len(firecrackerProcesses, 1, "expected only one firecracker process to exist")
+				require.NoError(tb, err, "failed waiting for expected firecracker process %q to come up", firecrackerProcessName)
+				require.Len(tb, firecrackerProcesses, 1, "expected only one firecracker process to exist")
 				firecrackerProcess := firecrackerProcesses[0]
 
 				go func() {
 					time.Sleep(5 * time.Second)
 					err := firecrackerProcess.KillWithContext(ctx)
-					require.NoError(err, "failed to kill firecracker process")
+					require.NoError(tb, err, "failed to kill firecracker process")
 				}()
 
 				_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{
@@ -1775,10 +1771,10 @@ func TestStopVM_Isolated(t *testing.T) {
 					TimeoutSeconds: 10,
 				})
 
-				require.Error(err)
-				assert.Equal(codes.Internal, status.Code(err))
+				require.Error(tb, err)
+				assert.Equal(tb, codes.Internal, status.Code(err))
 				// This is technically not accurate (the test is terminating the VM) though.
-				assert.Contains(err.Error(), "forcefully terminated")
+				assert.Contains(tb, err.Error(), "forcefully terminated")
 			},
 		},
 
@@ -1789,14 +1785,14 @@ func TestStopVM_Isolated(t *testing.T) {
 			withStopVM: true,
 
 			createVMRequest: proto.CreateVMRequest{},
-			stopFunc: func(ctx context.Context, fcClient fccontrol.FirecrackerService, req proto.CreateVMRequest) {
+			stopFunc: func(ctx context.Context, tb testing.TB, fcClient fccontrol.FirecrackerService, req proto.CreateVMRequest) {
 				_, err = fcClient.PauseVM(ctx, &proto.PauseVMRequest{VMID: req.VMID})
-				require.Equal(status.Code(err), codes.OK)
+				require.Equal(tb, status.Code(err), codes.OK)
 
 				_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: req.VMID})
-				require.Error(err)
-				assert.Equal(codes.Internal, status.Code(err))
-				assert.Contains(err.Error(), "forcefully terminated")
+				require.Error(tb, err)
+				assert.Equal(tb, codes.Internal, status.Code(err))
+				assert.Contains(tb, err.Error(), "forcefully terminated")
 			},
 		},
 
@@ -1805,37 +1801,37 @@ func TestStopVM_Isolated(t *testing.T) {
 			withStopVM: true,
 
 			createVMRequest: proto.CreateVMRequest{},
-			stopFunc: func(ctx context.Context, fcClient fccontrol.FirecrackerService, req proto.CreateVMRequest) {
+			stopFunc: func(ctx context.Context, tb testing.TB, fcClient fccontrol.FirecrackerService, req proto.CreateVMRequest) {
 				firecrackerProcesses, err := findProcess(ctx, findFirecracker)
-				require.NoError(err, "failed waiting for expected firecracker process %q to come up", firecrackerProcessName)
-				require.Len(firecrackerProcesses, 1, "expected only one firecracker process to exist")
+				require.NoError(tb, err, "failed waiting for expected firecracker process %q to come up", firecrackerProcessName)
+				require.Len(tb, firecrackerProcesses, 1, "expected only one firecracker process to exist")
 				firecrackerProcess := firecrackerProcesses[0]
 
 				err = firecrackerProcess.Suspend()
-				require.NoError(err, "failed to suspend Firecracker")
+				require.NoError(tb, err, "failed to suspend Firecracker")
 
 				_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: req.VMID})
-				require.Error(err)
-				assert.Equal(codes.Internal, status.Code(err))
-				assert.Contains(err.Error(), "forcefully terminated")
+				require.Error(tb, err)
+				assert.Equal(tb, codes.Internal, status.Code(err))
+				assert.Contains(tb, err.Error(), "forcefully terminated")
 			},
 		},
 	}
 
 	fcClient, err := integtest.NewFCControlClient(integtest.ContainerdSockPath)
-	require.NoError(err)
+	require.NoError(t, err)
 
 	for _, test := range tests {
 		test := test
 
-		testFunc := func(t *testing.T, createVMRequest proto.CreateVMRequest) {
+		testFunc := func(tb testing.TB, createVMRequest proto.CreateVMRequest) {
 			ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
 			defer cancel()
 
 			vmID := createVMRequest.VMID
 
 			_, err = fcClient.CreateVM(ctx, &createVMRequest)
-			require.NoError(err)
+			require.NoError(tb, err)
 
 			c, err := client.NewContainer(ctx,
 				"container-"+vmID,
@@ -1843,37 +1839,37 @@ func TestStopVM_Isolated(t *testing.T) {
 				containerd.WithNewSnapshot("snapshot-"+vmID, image),
 				containerd.WithNewSpec(oci.WithProcessArgs("/bin/echo", "-n", "hello"), firecrackeroci.WithVMID(vmID)),
 			)
-			require.NoError(err)
+			require.NoError(tb, err)
 
-			stdout := startAndWaitTask(ctx, t, c)
-			require.Equal("hello", stdout)
+			stdout := startAndWaitTask(ctx, tb, c)
+			require.Equal(tb, "hello", stdout)
 
 			shimProcesses, err := findProcess(ctx, findShim)
-			require.NoError(err, "failed to find shim process %q", shimProcessName)
-			require.Len(shimProcesses, 1, "expected only one shim process to exist")
+			require.NoError(tb, err, "failed to find shim process %q", shimProcessName)
+			require.Len(tb, shimProcesses, 1, "expected only one shim process to exist")
 			shimProcess := shimProcesses[0]
 
 			fcProcesses, err := findProcess(ctx, findFirecracker)
-			require.NoError(err, "failed to find firecracker")
-			require.Len(fcProcesses, 1, "expected only one firecracker process to exist")
+			require.NoError(tb, err, "failed to find firecracker")
+			require.Len(tb, fcProcesses, 1, "expected only one firecracker process to exist")
 			fcProcess := fcProcesses[0]
 
-			test.stopFunc(ctx, fcClient, createVMRequest)
+			test.stopFunc(ctx, tb, fcClient, createVMRequest)
 
 			// If the function above uses StopVMRequest, all underlying processes must be dead
 			// (either gracefully or forcibly) at the end of the request.
 			if test.withStopVM {
 				fcExists := pidExists(int(fcProcess.Pid))
-				assert.NoError(err, "failed to find firecracker")
-				assert.False(fcExists, "firecracker %s (pid=%d) is still there", vmID, fcProcess.Pid)
+				assert.NoError(tb, err, "failed to find firecracker")
+				assert.False(tb, fcExists, "firecracker %s (pid=%d) is still there", vmID, fcProcess.Pid)
 
 				shimExists := pidExists(int(shimProcess.Pid))
-				assert.NoError(err, "failed to find shim")
-				assert.False(shimExists, "shim %s (pid=%d) is still there", vmID, shimProcess.Pid)
+				assert.NoError(tb, err, "failed to find shim")
+				assert.False(tb, shimExists, "shim %s (pid=%d) is still there", vmID, shimProcess.Pid)
 			}
 
 			err = internal.WaitForPidToExit(ctx, time.Second, shimProcess.Pid)
-			require.NoError(err, "shim hasn't been terminated")
+			require.NoError(tb, err, "shim hasn't been terminated")
 		}
 
 		t.Run(test.name, func(t *testing.T) {
@@ -1893,8 +1889,8 @@ func TestStopVM_Isolated(t *testing.T) {
 
 			runcClient := &runc.Runc{}
 			containers, err := runcClient.List(ctx)
-			require.NoError(err, "failed to run 'runc list'")
-			assert.Equal(0, len(containers))
+			require.NoError(t, err, "failed to run 'runc list'")
+			assert.Equal(t, 0, len(containers))
 		})
 	}
 }
@@ -2068,10 +2064,9 @@ func TestExec_Isolated(t *testing.T) {
 
 func TestEvents_Isolated(t *testing.T) {
 	integtest.Prepare(t)
-	require := require.New(t)
 
 	client, err := containerd.New(integtest.ContainerdSockPath, containerd.WithDefaultRuntime(firecrackerRuntime))
-	require.NoError(err, "unable to create client to containerd service at %s, is containerd running?", integtest.ContainerdSockPath)
+	require.NoError(t, err, "unable to create client to containerd service at %s, is containerd running?", integtest.ContainerdSockPath)
 	defer client.Close()
 
 	ctx := namespaces.WithNamespace(context.Background(), "default")
@@ -2082,15 +2077,15 @@ func TestEvents_Isolated(t *testing.T) {
 	eventCh, errCh := client.Subscribe(subscribeCtx, "topic")
 
 	image, err := alpineImage(ctx, client, defaultSnapshotterName)
-	require.NoError(err, "failed to get alpine image")
+	require.NoError(t, err, "failed to get alpine image")
 
 	vmID := testNameToVMID(t.Name())
 
 	fcClient, err := integtest.NewFCControlClient(integtest.ContainerdSockPath)
-	require.NoError(err, "failed to create ttrpc client")
+	require.NoError(t, err, "failed to create ttrpc client")
 
 	_, err = fcClient.CreateVM(ctx, &proto.CreateVMRequest{VMID: vmID})
-	require.NoError(err)
+	require.NoError(t, err)
 
 	c, err := client.NewContainer(ctx,
 		"container-"+vmID,
@@ -2098,13 +2093,13 @@ func TestEvents_Isolated(t *testing.T) {
 		containerd.WithNewSnapshot("snapshot-"+vmID, image),
 		containerd.WithNewSpec(oci.WithProcessArgs("/bin/echo", "-n", "hello"), firecrackeroci.WithVMID(vmID)),
 	)
-	require.NoError(err)
+	require.NoError(t, err)
 
 	stdout := startAndWaitTask(ctx, t, c)
-	require.Equal("hello", stdout)
+	require.Equal(t, "hello", stdout)
 
 	_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: vmID})
-	require.Equal(status.Code(err), codes.OK)
+	require.Equal(t, status.Code(err), codes.OK)
 
 	expected := []string{
 		"/snapshot/prepare",
@@ -2130,7 +2125,7 @@ loop:
 			break loop
 		}
 	}
-	require.Equal(expected, actual)
+	require.Equal(t, expected, actual)
 }
 
 func findProcWithName(name string) func(context.Context, *process.Process) (bool, error) {