From 822794c242b2de325000e52bbc893c40026c2617 Mon Sep 17 00:00:00 2001 From: Mayank Pal Date: Sat, 18 May 2024 09:39:44 +0530 Subject: [PATCH] ci: Use temporary directory for unit tests ensure a clean and isolated environment for testing purposes. Signed-off-by: Mayank Pal ci: Use temporary directory for unit tests remove err = os.Mkdir('/etc/ceph-csi-config', 0o600) Signed-off-by: Mayank Pal ci: Use temporary directory for unit tests remove err = os.Mkdir('/etc/ceph-csi-config', 0o600) Signed-off-by: Mayank Pal ci: Use temporary directory for unit tests remove if err Signed-off-by: Mayank Pal --- internal/rbd/nodeserver_test.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/internal/rbd/nodeserver_test.go b/internal/rbd/nodeserver_test.go index 9e6782ac881..bc4ea7d3b3c 100644 --- a/internal/rbd/nodeserver_test.go +++ b/internal/rbd/nodeserver_test.go @@ -243,11 +243,8 @@ func TestReadAffinity_GetReadAffinityMapOptions(t *testing.T) { if err != nil { t.Errorf("failed to marshal csi config info %v", err) } - tmpConfPath := util.CsiConfigFile - err = os.Mkdir("/etc/ceph-csi-config", 0o600) - if err != nil { - t.Errorf("failed to create directory %s: %v", "/etc/ceph-csi-config", err) - } + tmpConfPath := t.TempDir() + "/ceph-csi.json" + err = os.WriteFile(tmpConfPath, csiConfigFileContent, 0o600) if err != nil { t.Errorf("failed to write %s file content: %v", util.CsiConfigFile, err)