@@ -59,7 +59,7 @@ func TestFileManagerService_ConfigApply_Add(t *testing.T) {
5959 agentConfig .AllowedDirectories = []string {tempDir }
6060
6161 fileManagerService := NewFileManagerService (fakeFileServiceClient , agentConfig , & sync.RWMutex {})
62- fileManagerService .configPath = filepath .Dir (filePath )
62+ fileManagerService .tempConfigPath = filepath .Dir (filePath )
6363 fileManagerService .agentConfig .LibDir = manifestDirPath
6464 fileManagerService .manifestFilePath = manifestFilePath
6565
@@ -109,7 +109,7 @@ func TestFileManagerService_ConfigApply_Add_LargeFile(t *testing.T) {
109109 agentConfig .AllowedDirectories = []string {tempDir }
110110 fileManagerService := NewFileManagerService (fakeFileServiceClient , agentConfig , & sync.RWMutex {})
111111 fileManagerService .agentConfig .LibDir = manifestDirPath
112- fileManagerService .configPath = filepath .Dir (filePath )
112+ fileManagerService .tempConfigPath = filepath .Dir (filePath )
113113 fileManagerService .manifestFilePath = manifestFilePath
114114
115115 request := protos .CreateConfigApplyRequest (overview )
@@ -170,7 +170,7 @@ func TestFileManagerService_ConfigApply_Update(t *testing.T) {
170170
171171 fileManagerService := NewFileManagerService (fakeFileServiceClient , agentConfig , & sync.RWMutex {})
172172 fileManagerService .agentConfig .LibDir = manifestDirPath
173- fileManagerService .configPath = filepath .Dir (tempFile .Name ())
173+ fileManagerService .tempConfigPath = filepath .Dir (tempFile .Name ())
174174 fileManagerService .manifestFilePath = manifestFilePath
175175 err := fileManagerService .UpdateCurrentFilesOnDisk (ctx , filesOnDisk , false )
176176 require .NoError (t , err )
@@ -226,7 +226,7 @@ func TestFileManagerService_ConfigApply_Delete(t *testing.T) {
226226 fileManagerService := NewFileManagerService (fakeFileServiceClient , agentConfig , & sync.RWMutex {})
227227 fileManagerService .agentConfig .LibDir = manifestDirPath
228228 fileManagerService .manifestFilePath = manifestFilePath
229- fileManagerService .configPath = filepath .Dir (tempFile .Name ())
229+ fileManagerService .tempConfigPath = filepath .Dir (tempFile .Name ())
230230 err := fileManagerService .UpdateCurrentFilesOnDisk (ctx , filesOnDisk , false )
231231 require .NoError (t , err )
232232
@@ -290,7 +290,7 @@ func TestFileManagerService_ConfigApply_Failed(t *testing.T) {
290290
291291 fileManagerService := NewFileManagerService (fakeFileServiceClient , agentConfig , & sync.RWMutex {})
292292 fileManagerService .agentConfig .LibDir = manifestDirPath
293- fileManagerService .configPath = filepath .Dir (filePath )
293+ fileManagerService .tempConfigPath = filepath .Dir (filePath )
294294 fileManagerService .manifestFilePath = manifestFilePath
295295
296296 request := protos .CreateConfigApplyRequest (overview )
@@ -332,7 +332,7 @@ func TestFileManagerService_ConfigApply_FileWithExecutePermissions(t *testing.T)
332332 agentConfig .AllowedDirectories = []string {tempDir }
333333
334334 fileManagerService := NewFileManagerService (fakeFileServiceClient , agentConfig , & sync.RWMutex {})
335- fileManagerService .configPath = filepath .Dir (filePath )
335+ fileManagerService .tempConfigPath = filepath .Dir (filePath )
336336 fileManagerService .agentConfig .LibDir = manifestDirPath
337337 fileManagerService .manifestFilePath = manifestFilePath
338338
@@ -512,15 +512,20 @@ func TestFileManagerService_removeExecuteFilePermissions(t *testing.T) {
512512//nolint:usetesting // need to use MkDirTemp instead of t.tempDir for rollback as t.tempDir does not accept a pattern
513513func TestFileManagerService_ClearCache (t * testing.T ) {
514514 tempDir := t .TempDir ()
515- rollbackDir , err := os .MkdirTemp (tempDir , "rollback" )
515+ agentConfig := types .AgentConfig ()
516+ tempPath := fmt .Sprintf ("%s.agent_%s" , tempDir , agentConfig .UUID )
517+ err := os .Mkdir (tempPath , dirPerm )
518+ require .NoError (t , err )
519+ rollbackDir , err := os .MkdirTemp (tempPath , "rollback" )
516520 require .NoError (t , err )
517- configDir , err := os .MkdirTemp (tempDir , "config" )
521+ configDir , err := os .MkdirTemp (tempPath , "config" )
518522 require .NoError (t , err )
519523
520524 fakeFileServiceClient := & v1fakes.FakeFileServiceClient {}
521- fileManagerService := NewFileManagerService (fakeFileServiceClient , types . AgentConfig () , & sync.RWMutex {})
525+ fileManagerService := NewFileManagerService (fakeFileServiceClient , agentConfig , & sync.RWMutex {})
522526 fileManagerService .tempConfigDir = configDir
523527 fileManagerService .tempRollbackDir = rollbackDir
528+ fileManagerService .tempConfigPath = tempPath
524529
525530 filesCache := map [string ]* model.FileCache {
526531 "file/path/test.conf" : {
@@ -654,7 +659,7 @@ func TestFileManagerService_Rollback(t *testing.T) {
654659 fileManagerService .fileActions = filesCache
655660 fileManagerService .agentConfig .LibDir = manifestDirPath
656661 fileManagerService .tempRollbackDir = rollbackDir
657- fileManagerService .configPath = filepath .Dir (updateFile .Name ())
662+ fileManagerService .tempConfigPath = filepath .Dir (updateFile .Name ())
658663 fileManagerService .manifestFilePath = manifestFilePath
659664
660665 err := fileManagerService .Rollback (ctx , instanceID )
@@ -841,7 +846,7 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
841846 fileManagerService .agentConfig .AllowedDirectories = test .allowedDirs
842847 fileManagerService .agentConfig .LibDir = manifestDirPath
843848 fileManagerService .manifestFilePath = manifestFilePath
844- fileManagerService .configPath = filepath .Dir (updateTestFile .Name ())
849+ fileManagerService .tempConfigPath = filepath .Dir (updateTestFile .Name ())
845850
846851 require .NoError (tt , err )
847852
@@ -1238,16 +1243,16 @@ func TestFileManagerService_createTempConfigDirectory(t *testing.T) {
12381243 configPath := tempDir
12391244
12401245 fileManagerService := FileManagerService {
1241- agentConfig : agentConfig ,
1242- configPath : configPath ,
1246+ agentConfig : agentConfig ,
1247+ tempConfigPath : configPath ,
12431248 }
12441249
12451250 dir , err := fileManagerService .createTempConfigDirectory ("config" )
12461251 assert .NotEmpty (t , dir )
12471252 require .NoError (t , err )
12481253
12491254 // Test for unknown directory path
1250- fileManagerService .configPath = "/unknown/"
1255+ fileManagerService .tempConfigPath = "/unknown/"
12511256
12521257 dir , err = fileManagerService .createTempConfigDirectory ("config" )
12531258 assert .Empty (t , dir )
0 commit comments