@@ -296,6 +296,7 @@ func TestExtractFiles(t *testing.T) {
296296 {publicGitHub , "test-fixtures/fetch-test-public-0.0.2.zip" , "/" , 2 , nil },
297297 {publicGitHub , "test-fixtures/fetch-test-public-0.0.3.zip" , "/" , 4 , []string {"/README.md" } },
298298 {publicGitHub , "test-fixtures/fetch-test-public-0.0.3.zip" , "/folder" , 2 , nil },
299+ {publicGitHub , "test-fixtures/fetch-test-public-0.0.4.zip" , "/aaa" , 2 , []string {"/hello.txt" , "/subaaa/subhello.txt" } },
299300 }
300301
301302 for _ , tc := range cases {
@@ -339,6 +340,35 @@ func TestExtractFiles(t *testing.T) {
339340 }
340341}
341342
343+ func TestExtractFilesExtractFile (t * testing.T ) {
344+ // Create a temp directory
345+ tempDir , err := ioutil .TempDir ("" , "" )
346+ if err != nil {
347+ t .Fatalf ("Failed to create temp directory: %s" , err )
348+ }
349+ defer os .RemoveAll (tempDir )
350+
351+ zipFilePath := "test-fixtures/fetch-test-public-0.0.4.zip"
352+ filePathToExtract := "zzz.txt"
353+ localFileName := "/localzzz.txt"
354+ localPathName := filepath .Join (tempDir , localFileName )
355+ err = extractFiles (zipFilePath , filePathToExtract , localPathName )
356+ if err != nil {
357+ t .Fatalf ("Failed to extract files: %s" , err )
358+ }
359+
360+ filepath .Walk (tempDir , func (path string , info os.FileInfo , err error ) error {
361+ relativeFilename := strings .TrimPrefix (path , tempDir )
362+
363+ if ! info .IsDir () {
364+ if relativeFilename != localFileName {
365+ t .Fatalf ("Expected local file %s to be created, but not found.\n " , localFileName )
366+ }
367+ }
368+ return nil
369+ })
370+ }
371+
342372// Return ture if the given slice contains the given string
343373func stringInSlice (s string , slice []string ) bool {
344374 for _ , val := range slice {
0 commit comments