github.com/hashicorp/go-getter/v2@v2.2.2/decompress_tzst_test.go (about)

     1  package getter
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  )
     7  
     8  func TestTarZstdDecompressor(t *testing.T) {
     9  
    10  	multiplePaths := []string{"dir/", "dir/test2", "test1"}
    11  	orderingPaths := []string{"workers/", "workers/mq/", "workers/mq/__init__.py"}
    12  
    13  	cases := []TestDecompressCase{
    14  		{
    15  			"empty.tar.zst",
    16  			false,
    17  			true,
    18  			nil,
    19  			"",
    20  			nil,
    21  		},
    22  
    23  		{
    24  			"single.tar.zst",
    25  			false,
    26  			false,
    27  			nil,
    28  			"d3b07384d113edec49eaa6238ad5ff00",
    29  			nil,
    30  		},
    31  
    32  		{
    33  			"single.tar.zst",
    34  			true,
    35  			false,
    36  			[]string{"file"},
    37  			"",
    38  			nil,
    39  		},
    40  
    41  		{
    42  			"multiple.tar.zst",
    43  			true,
    44  			false,
    45  			[]string{"file1", "file2"},
    46  			"",
    47  			nil,
    48  		},
    49  
    50  		{
    51  			"multiple.tar.zst",
    52  			false,
    53  			true,
    54  			nil,
    55  			"",
    56  			nil,
    57  		},
    58  
    59  		{
    60  			"multiple_dir.tar.zst",
    61  			true,
    62  			false,
    63  			multiplePaths,
    64  			"",
    65  			nil,
    66  		},
    67  
    68  		// Tests when the file is listed before the parent folder
    69  		{
    70  			"ordering.tar.zst",
    71  			true,
    72  			false,
    73  			orderingPaths,
    74  			"",
    75  			nil,
    76  		},
    77  
    78  		// Tests that a tar.zst can't contain references with "..".
    79  		// GNU `tar` also disallows this.
    80  		{
    81  			"outside_parent.tar.zst",
    82  			true,
    83  			true,
    84  			nil,
    85  			"",
    86  			nil,
    87  		},
    88  	}
    89  
    90  	for i, tc := range cases {
    91  		cases[i].Input = filepath.Join("./testdata", "decompress-tzst", tc.Input)
    92  	}
    93  
    94  	TestDecompressor(t, new(TarZstdDecompressor), cases)
    95  }