@@ -83,46 +83,6 @@ func TestPIDFileBackwardCompatibility(t *testing.T) {
8383 assert .Equal (t , newPID , pid , "Should read from new location when both exist" )
8484 })
8585
86- t .Run ("WritePIDFile_WritesBothLocations" , func (t * testing.T ) {
87- //nolint:paralleltest // File system operations require sequential execution
88-
89- containerName := "test-container-write-both"
90- testPID := 33333
91-
92- // Clean up any existing files
93- t .Cleanup (func () {
94- // Clean up new location
95- if newPath , err := getPIDFilePath (containerName ); err == nil {
96- require .NoError (t , os .Remove (newPath ))
97- }
98- // Clean up old location
99- oldPath := getOldPIDFilePath (containerName )
100- require .NoError (t , os .Remove (oldPath ))
101- })
102-
103- // Write PID file
104- require .NoError (t , WritePIDFile (containerName , testPID ), "Failed to write PID file" )
105-
106- // Verify it was written to new location
107- newPath , err := getPIDFilePath (containerName )
108- require .NoError (t , err , "Failed to get new PID file path" )
109-
110- _ , err = os .Stat (newPath )
111- assert .NoError (t , err , "PID file should exist in new location" )
112-
113- // Verify it was also written to old location for compatibility
114- oldPath := getOldPIDFilePath (containerName )
115- _ , err = os .Stat (oldPath )
116- assert .NoError (t , err , "PID file should also exist in old location for version compatibility" )
117-
118- // Verify both files contain the same PID
119- newPidBytes , err := os .ReadFile (newPath )
120- require .NoError (t , err , "Should read new location file" )
121- oldPidBytes , err := os .ReadFile (oldPath )
122- require .NoError (t , err , "Should read old location file" )
123- assert .Equal (t , newPidBytes , oldPidBytes , "Both files should contain the same PID" )
124- })
125-
12686 //nolint:paralleltest // File system operations require sequential execution
12787 t .Run ("RemovePIDFile_RemovesBothLocations" , func (t * testing.T ) {
12888 //nolint:paralleltest // File system operations require sequential execution
@@ -199,37 +159,6 @@ func TestPIDFileBackwardCompatibility(t *testing.T) {
199159 assert .True (t , os .IsNotExist (err ), "Old PID file should be removed" )
200160 })
201161
202- //nolint:paralleltest // File system operations require sequential execution
203- t .Run ("RemovePIDFile_NewFileOnly" , func (t * testing.T ) {
204- //nolint:paralleltest // File system operations require sequential execution
205-
206- containerName := "test-container-new-only"
207- testPID := 66666
208-
209- // Clean up any existing files
210- t .Cleanup (func () {
211- // Clean up new location
212- if newPath , err := getPIDFilePath (containerName ); err == nil {
213- // Error expected here - ignore.
214- _ = os .Remove (newPath )
215- }
216- // Clean up old location
217- oldPath := getOldPIDFilePath (containerName )
218- // Error expected here - ignore.
219- _ = os .Remove (oldPath )
220- })
221-
222- // Test removing when only new file exists
223- require .NoError (t , WritePIDFile (containerName , testPID ), "Failed to write PID file" )
224-
225- err := RemovePIDFile (containerName )
226- assert .NoError (t , err , "Should handle removing only new file" )
227-
228- newPath , _ := getPIDFilePath (containerName )
229- _ , err = os .Stat (newPath )
230- assert .True (t , os .IsNotExist (err ), "New PID file should be removed" )
231- })
232-
233162 t .Run ("getPIDFilePathWithFallback" , func (t * testing.T ) {
234163 //nolint:paralleltest // File system operations require sequential execution
235164
@@ -278,45 +207,6 @@ func TestPIDFileBackwardCompatibility(t *testing.T) {
278207//nolint:paralleltest // File system operations require sequential execution
279208func TestPIDFileOperations (t * testing.T ) {
280209
281- t .Run ("WriteAndReadPIDFile" , func (t * testing.T ) {
282- //nolint:paralleltest // File system operations require sequential execution
283-
284- containerName := "test-basic-write-read"
285- testPID := 54321
286-
287- // Clean up before and after
288- t .Cleanup (func () {
289- require .NoError (t , RemovePIDFile (containerName ))
290- })
291-
292- // Write PID
293- require .NoError (t , WritePIDFile (containerName , testPID ), "Failed to write PID file" )
294-
295- // Read PID
296- pid , err := ReadPIDFile (containerName )
297- require .NoError (t , err , "Failed to read PID file" )
298- assert .Equal (t , testPID , pid , "PID mismatch" )
299- })
300-
301- t .Run ("WriteCurrentPIDFile" , func (t * testing.T ) {
302- //nolint:paralleltest // File system operations require sequential execution
303-
304- containerName := "test-current-pid"
305-
306- // Clean up before and after
307- t .Cleanup (func () {
308- require .NoError (t , RemovePIDFile (containerName ))
309- })
310-
311- // Write current process PID
312- require .NoError (t , WriteCurrentPIDFile (containerName ), "Failed to write current PID file" )
313-
314- // Read and verify
315- pid , err := ReadPIDFile (containerName )
316- require .NoError (t , err , "Failed to read PID file" )
317- assert .Equal (t , os .Getpid (), pid , "Should match current process PID" )
318- })
319-
320210 t .Run ("ReadNonExistentPIDFile" , func (t * testing.T ) {
321211 //nolint:paralleltest // File system operations require sequential execution
322212
@@ -390,49 +280,3 @@ func TestGetPIDFilePath(t *testing.T) {
390280 "Old PID file should have correct filename format" )
391281 })
392282}
393-
394- //nolint:paralleltest // File system operations require sequential execution
395- func TestPIDFileMigration (t * testing.T ) {
396-
397- //nolint:paralleltest // File system operations require sequential execution
398- t .Run ("MigrationScenario" , func (t * testing.T ) {
399- //nolint:paralleltest // File system operations require sequential execution
400-
401- containerName := "test-migration"
402- oldPID := 99999
403-
404- // Clean up
405- t .Cleanup (func () {
406- require .NoError (t , RemovePIDFile (containerName ))
407- })
408-
409- // Simulate existing deployment with PID file in old location
410- oldPath := getOldPIDFilePath (containerName )
411- require .NoError (t , os .WriteFile (oldPath , []byte (fmt .Sprintf ("%d" , oldPID )), 0600 ),
412- "Failed to create old PID file" )
413-
414- // New code should still be able to read the old PID
415- pid , err := ReadPIDFile (containerName )
416- require .NoError (t , err , "Should read PID from old location" )
417- assert .Equal (t , oldPID , pid , "Should read correct PID from old location" )
418-
419- // When writing a new PID, it should go to the new location
420- newPID := 88888
421- require .NoError (t , WritePIDFile (containerName , newPID ), "Failed to write new PID" )
422-
423- // Now reading should get the new PID from the new location
424- pid , err = ReadPIDFile (containerName )
425- require .NoError (t , err , "Should read PID from new location" )
426- assert .Equal (t , newPID , pid , "Should read new PID from new location" )
427-
428- // Cleanup should remove both files
429- require .NoError (t , RemovePIDFile (containerName ), "Failed to remove PID files" )
430-
431- _ , err = os .Stat (oldPath )
432- assert .True (t , os .IsNotExist (err ), "Old file should be removed" )
433-
434- newPath , _ := getPIDFilePath (containerName )
435- _ , err = os .Stat (newPath )
436- assert .True (t , os .IsNotExist (err ), "New file should be removed" )
437- })
438- }
0 commit comments