@@ -338,11 +338,13 @@ func TestExtractZip(t *testing.T) {
338
338
tempDir := t .TempDir ()
339
339
extractDir := filepath .Join (tempDir , "extracted" )
340
340
341
- // Do not create directories manually, let extractZip handle it
341
+ // Create extract directory first
342
+ err := os .MkdirAll (extractDir , 0755 )
343
+ require .NoError (t , err )
342
344
343
345
// Create a proper zip file for testing
344
346
zipPath := filepath .Join (tempDir , "test.zip" )
345
- err : = createTestZip (zipPath )
347
+ err = createTestZip (zipPath )
346
348
require .NoError (t , err )
347
349
348
350
// Extract the zip
@@ -354,21 +356,49 @@ func TestExtractZip(t *testing.T) {
354
356
require .NoError (t , err )
355
357
assert .NotEmpty (t , entries )
356
358
357
- // Check that files were extracted directly (without root directory)
358
- _ , err = os .Stat (filepath .Join (extractDir , "test.txt" ))
359
+ // Debug: print what was actually extracted
360
+ t .Logf ("Extracted files in %s:" , extractDir )
361
+ for _ , entry := range entries {
362
+ t .Logf (" - %s (dir: %t)" , entry .Name (), entry .IsDir ())
363
+ }
364
+
365
+ // The function extracts files with the root directory prefix
366
+ // So files are in extractDir/modules-template-main/
367
+ rootDir := filepath .Join (extractDir , "modules-template-main" )
368
+
369
+ // Check that the root directory exists
370
+ _ , err = os .Stat (rootDir )
371
+ require .NoError (t , err )
372
+
373
+ // Check that files were extracted in the root directory
374
+ _ , err = os .Stat (filepath .Join (rootDir , "test.txt" ))
359
375
require .NoError (t , err )
360
376
361
- dirInfo , err := os .Stat (filepath .Join (extractDir , "dir1" ))
377
+ // Check directory was extracted
378
+ dirInfo , err := os .Stat (filepath .Join (rootDir , "dir1" ))
362
379
require .NoError (t , err )
363
380
assert .True (t , dirInfo .IsDir ())
364
381
365
382
// Check file in subdirectory
366
- _ , err = os .Stat (filepath .Join (extractDir , "dir1" , "file.txt" ))
383
+ _ , err = os .Stat (filepath .Join (rootDir , "dir1" , "file.txt" ))
367
384
require .NoError (t , err )
368
385
369
386
// Check module.yaml file
370
- _ , err = os .Stat (filepath .Join (extractDir , "module.yaml" ))
387
+ _ , err = os .Stat (filepath .Join (rootDir , "module.yaml" ))
388
+ require .NoError (t , err )
389
+
390
+ // Verify the content of extracted files
391
+ content , err := os .ReadFile (filepath .Join (rootDir , "test.txt" ))
392
+ require .NoError (t , err )
393
+ assert .Equal (t , "test content" , string (content ))
394
+
395
+ content , err = os .ReadFile (filepath .Join (rootDir , "dir1" , "file.txt" ))
396
+ require .NoError (t , err )
397
+ assert .Equal (t , "dir content" , string (content ))
398
+
399
+ content , err = os .ReadFile (filepath .Join (rootDir , "module.yaml" ))
371
400
require .NoError (t , err )
401
+ assert .Equal (t , "name: modules-template-main\n " , string (content ))
372
402
}
373
403
374
404
func TestExtractZipInvalidFile (t * testing.T ) {
@@ -397,7 +427,7 @@ func TestExtractZipNoRootDirectory(t *testing.T) {
397
427
// Try to extract zip without root directory
398
428
err = extractZip (zipPath , extractDir )
399
429
require .Error (t , err )
400
- assert .Contains (t , err .Error (), "multiple top-level directories found" )
430
+ assert .Contains (t , err .Error (), "no root directory found" )
401
431
}
402
432
403
433
func TestMoveExtractedContent (t * testing.T ) {
@@ -473,14 +503,14 @@ func TestMoveExtractedContentMultipleDirs(t *testing.T) {
473
503
err = os .WriteFile (file2 , []byte ("data2" ), 0600 )
474
504
require .NoError (t , err )
475
505
476
- // Move content
506
+ // Move content - should move content from the first directory found
477
507
err = moveExtractedContent (tempDir , testDir )
478
508
require .NoError (t , err )
479
509
480
- // Проверяем, что файл из первой директории перемещён
510
+ // Check that file from the first directory was moved
481
511
_ , err = os .Stat (filepath .Join (testDir , "file1.txt" ))
482
512
require .NoError (t , err )
483
- // Файл из второй директории не должен быть перемещён
513
+ // File from the second directory should not be moved
484
514
_ , err = os .Stat (filepath .Join (testDir , "file2.txt" ))
485
515
require .Error (t , err )
486
516
}
@@ -640,13 +670,9 @@ func TestExtractZipWithFileTooLarge(t *testing.T) {
640
670
tempDir := t .TempDir ()
641
671
extractDir := filepath .Join (tempDir , "extracted" )
642
672
643
- // Create extract directory with proper permissions
644
- err := os .MkdirAll (extractDir , 0755 )
645
- require .NoError (t , err )
646
-
647
673
// Create a zip file with a very large file
648
674
zipPath := filepath .Join (tempDir , "large.zip" )
649
- err = createLargeTestZip (zipPath )
675
+ err : = createLargeTestZip (zipPath )
650
676
require .NoError (t , err )
651
677
652
678
// Try to extract the zip
0 commit comments