github.com/secman-team/gh-api@v1.8.2/pkg/cmd/run/download/zip_test.go (about)

     1  package download
     2  
     3  import (
     4  	"archive/zip"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func Test_extractZip(t *testing.T) {
    13  	tmpDir := t.TempDir()
    14  	wd, err := os.Getwd()
    15  	require.NoError(t, err)
    16  	t.Cleanup(func() { _ = os.Chdir(wd) })
    17  
    18  	zipFile, err := zip.OpenReader("./fixtures/myproject.zip")
    19  	require.NoError(t, err)
    20  	defer zipFile.Close()
    21  
    22  	extractPath := filepath.Join(tmpDir, "artifact")
    23  	err = os.MkdirAll(extractPath, 0700)
    24  	require.NoError(t, err)
    25  	require.NoError(t, os.Chdir(extractPath))
    26  
    27  	err = extractZip(&zipFile.Reader, ".")
    28  	require.NoError(t, err)
    29  
    30  	_, err = os.Stat(filepath.Join("src", "main.go"))
    31  	require.NoError(t, err)
    32  }