Skip to content

Commit

Permalink
fix: use testing.TempDir
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmyagkov committed Sep 29, 2024
1 parent 2f0397e commit ffe1f00
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions cloud/blockstore/tools/csi_driver/internal/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
////////////////////////////////////////////////////////////////////////////////

func doTestPublishUnpublishVolumeForKubevirt(t *testing.T, backend string, deviceNameOpt *string) {
tempDir, err := os.MkdirTemp(os.TempDir(), "test_")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()

nbsClient := mocks.NewNbsClientMock()
nfsClient := mocks.NewNfsEndpointClientMock()
Expand All @@ -44,7 +42,6 @@ func doTestPublishUnpublishVolumeForKubevirt(t *testing.T, backend string, devic
socketsDir := filepath.Join(tempDir, "sockets")
sourcePath := filepath.Join(socketsDir, podID, diskID)
targetPath := filepath.Join(tempDir, "pods", podID, "volumes", diskID, "mount")

targetFsPathPattern := filepath.Join(tempDir, "pods/([a-z0-9-]+)/volumes/([a-z0-9-]+)/mount")
nbsSocketPath := filepath.Join(sourcePath, "nbs.sock")
nfsSocketPath := filepath.Join(sourcePath, "nfs.sock")
Expand All @@ -61,7 +58,7 @@ func doTestPublishUnpublishVolumeForKubevirt(t *testing.T, backend string, devic
mounter,
)

_, err = nodeService.NodeStageVolume(ctx, &csi.NodeStageVolumeRequest{
_, err := nodeService.NodeStageVolume(ctx, &csi.NodeStageVolumeRequest{
VolumeId: diskID,
StagingTargetPath: "testStagingTargetPath",
VolumeCapability: &csi.VolumeCapability{},
Expand Down Expand Up @@ -189,9 +186,7 @@ func TestPublishUnpublishFilestoreForKubevirt(t *testing.T) {
}

func TestPublishUnpublishDiskForInfrakuber(t *testing.T) {
tempDir, err := os.MkdirTemp(os.TempDir(), "test_")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()

groupId := ""
currentUser, err := user.Current()
Expand Down Expand Up @@ -330,16 +325,14 @@ func TestPublishUnpublishDiskForInfrakuber(t *testing.T) {
}

func TestPublishUnpublishDeviceForInfrakuber(t *testing.T) {
tempDir, err := os.MkdirTemp(os.TempDir(), "test_")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()

nbsClient := mocks.NewNbsClientMock()
mounter := mounter.NewMock()

ipcType := nbs.EClientIpcType_IPC_NBD
nbdDeviceFile := filepath.Join(tempDir, "dev", "nbd3")
err = os.MkdirAll(nbdDeviceFile, 0755)
err := os.MkdirAll(nbdDeviceFile, 0755)
require.NoError(t, err)

ctx := context.Background()
Expand Down Expand Up @@ -452,9 +445,7 @@ func TestPublishUnpublishDeviceForInfrakuber(t *testing.T) {
}

func TestGetVolumeStatCapabilitiesWithoutVmMode(t *testing.T) {
tempDir, err := os.MkdirTemp(os.TempDir(), "test_")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()

nbsClient := mocks.NewNbsClientMock()
mounter := mounter.NewMock()
Expand All @@ -466,7 +457,9 @@ func TestGetVolumeStatCapabilitiesWithoutVmMode(t *testing.T) {
targetFsPathPattern := filepath.Join(tempDir,
"pods/([a-z0-9-]+)/volumes/([a-z0-9-]+)/mount")

err = os.MkdirAll(targetPath, 755)
info, err := os.Stat(tempDir)
require.NoError(t, err)
err = os.MkdirAll(targetPath, info.Mode())
require.NoError(t, err)

nodeService := newNodeService(
Expand Down Expand Up @@ -519,15 +512,13 @@ func TestGetVolumeStatCapabilitiesWithoutVmMode(t *testing.T) {
}

func TestGetVolumeStatCapabilitiesWithVmMode(t *testing.T) {
tempDir, err := os.MkdirTemp(os.TempDir(), "test_")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()

nbsClient := mocks.NewNbsClientMock()
mounter := mounter.NewMock()

nbdDeviceFile := filepath.Join(tempDir, "dev", "nbd3")
err = os.MkdirAll(nbdDeviceFile, 0755)
err := os.MkdirAll(nbdDeviceFile, 0755)
require.NoError(t, err)

clientID := "testClientId"
Expand Down Expand Up @@ -575,15 +566,13 @@ func TestGetVolumeStatCapabilitiesWithVmMode(t *testing.T) {
}

func TestPublishDeviceWithReadWriteManyModeIsNotSupportedWithNBS(t *testing.T) {
tempDir, err := os.MkdirTemp(os.TempDir(), "test_")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()

nbsClient := mocks.NewNbsClientMock()
mounter := mounter.NewMock()

nbdDeviceFile := filepath.Join(tempDir, "dev", "nbd3")
err = os.MkdirAll(nbdDeviceFile, 0755)
err := os.MkdirAll(nbdDeviceFile, 0755)
require.NoError(t, err)

ctx := context.Background()
Expand Down

0 comments on commit ffe1f00

Please sign in to comment.