github.com/remind101/go-getter@v0.0.0-20180809191950-4bda8fa99001/decompress_tgz_test.go (about) 1 package getter 2 3 import ( 4 "path/filepath" 5 "testing" 6 ) 7 8 func TestTarGzipDecompressor(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.gz", 16 false, 17 true, 18 nil, 19 "", 20 nil, 21 }, 22 23 { 24 "single.tar.gz", 25 false, 26 false, 27 nil, 28 "d3b07384d113edec49eaa6238ad5ff00", 29 nil, 30 }, 31 32 { 33 "single.tar.gz", 34 true, 35 false, 36 []string{"file"}, 37 "", 38 nil, 39 }, 40 41 { 42 "multiple.tar.gz", 43 true, 44 false, 45 []string{"file1", "file2"}, 46 "", 47 nil, 48 }, 49 50 { 51 "multiple.tar.gz", 52 false, 53 true, 54 nil, 55 "", 56 nil, 57 }, 58 59 { 60 "multiple_dir.tar.gz", 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.gz", 71 true, 72 false, 73 orderingPaths, 74 "", 75 nil, 76 }, 77 78 // Tests that a tar.gz can't contain references with "..". 79 // GNU `tar` also disallows this. 80 { 81 "outside_parent.tar.gz", 82 true, 83 true, 84 nil, 85 "", 86 nil, 87 }, 88 } 89 90 for i, tc := range cases { 91 cases[i].Input = filepath.Join("./test-fixtures", "decompress-tgz", tc.Input) 92 } 93 94 TestDecompressor(t, new(TarGzipDecompressor), cases) 95 }