@@ -298,10 +298,7 @@ func TestDyconfInitErrors(t *testing.T) {
298
298
299
299
func TestDyconfWriteInitNewFile (t * testing.T ) {
300
300
// Create the file first.
301
- tmpFile , err := ioutil .TempFile ("" , "TestDyconfWriteInitNewFile" )
302
- ensure .Nil (t , err )
303
- tmpFileName := tmpFile .Name ()
304
- tmpFile .Close ()
301
+ tmpFileName := setupTempFile (t , "TestDyconfWriteInitNewFile-" )
305
302
os .Remove (tmpFileName )
306
303
307
304
// Initialize the writer.
@@ -315,6 +312,26 @@ func TestDyconfWriteInitNewFile(t *testing.T) {
315
312
ensure .Nil (t , os .Remove (tmpFileName ))
316
313
}
317
314
315
+ // TestDyconfWriteInitExistingFile tests the initialization of existing config file for writing.
316
+ func TestDyconfWriteInitExistingFile (t * testing.T ) {
317
+ // Create the file first.
318
+ tmpFileName := setupTempFile (t , "TestDyconfWriteInitExistingFile-" )
319
+ os .Remove (tmpFileName )
320
+
321
+ // Initialize the writer and create a new config file.
322
+ m , err := NewManager (tmpFileName )
323
+ ensure .Nil (t , err )
324
+ ensure .Nil (t , m .Close ())
325
+ // Make sure the file is created.
326
+ _ , err = os .Stat (tmpFileName )
327
+ ensure .Nil (t , err )
328
+
329
+ // Initialize the writer with the existing config file.
330
+ m , err = NewManager (tmpFileName )
331
+ ensure .Nil (t , err )
332
+ ensure .Nil (t , m .Close ())
333
+ }
334
+
318
335
func setupTempFile (t * testing.T , prefix string ) string {
319
336
tmpFile , err := ioutil .TempFile ("" , prefix )
320
337
ensure .Nil (t , err )
0 commit comments