github.com/leg100/ots@v0.0.7-0.20210919080622-034055ced4bd/unpack_test.go (about)

     1  package ots
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestUnpack(t *testing.T) {
    13  	dst := t.TempDir()
    14  
    15  	tarball, err := os.Open("testdata/unpack.tar.gz")
    16  	require.NoError(t, err)
    17  
    18  	require.NoError(t, Unpack(tarball, dst))
    19  
    20  	var got []string
    21  	filepath.Walk(dst, func(path string, info os.FileInfo, _ error) error {
    22  		path, err := filepath.Rel(dst, path)
    23  		require.NoError(t, err)
    24  		got = append(got, path)
    25  		return nil
    26  	})
    27  	assert.Equal(t, []string{
    28  		".",
    29  		"dir",
    30  		"dir/file",
    31  		"dir/symlink",
    32  		"file",
    33  	}, got)
    34  }