github.com/anchore/syft@v1.38.2/internal/file/archive_aliases_test.go (about) 1 package file 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestHandleCompoundArchiveAliases(t *testing.T) { 10 tests := []struct { 11 name string 12 input string 13 expected string 14 }{ 15 { 16 name: "tgz to tar.gz", 17 input: "/path/to/archive.tgz", 18 expected: "/path/to/archive.tar.gz", 19 }, 20 { 21 name: "tbz2 to tar.bz2", 22 input: "/path/to/archive.tbz2", 23 expected: "/path/to/archive.tar.bz2", 24 }, 25 { 26 name: "txz to tar.xz", 27 input: "/path/to/archive.txz", 28 expected: "/path/to/archive.tar.xz", 29 }, 30 { 31 name: "tlz to tar.lz", 32 input: "/path/to/archive.tlz", 33 expected: "/path/to/archive.tar.lz", 34 }, 35 { 36 name: "tzst to tar.zst", 37 input: "/path/to/archive.tzst", 38 expected: "/path/to/archive.tar.zst", 39 }, 40 { 41 name: "standard tar.gz unchanged", 42 input: "/path/to/archive.tar.gz", 43 expected: "/path/to/archive.tar.gz", 44 }, 45 { 46 name: "zip unchanged", 47 input: "/path/to/archive.zip", 48 expected: "/path/to/archive.zip", 49 }, 50 { 51 name: "no extension unchanged", 52 input: "/path/to/archive", 53 expected: "/path/to/archive", 54 }, 55 { 56 name: "case sensitive - TGZ not matched", 57 input: "/path/to/archive.TGZ", 58 expected: "/path/to/archive.TGZ", 59 }, 60 { 61 name: "just filename with tgz", 62 input: "archive.tgz", 63 expected: "archive.tar.gz", 64 }, 65 } 66 67 for _, tt := range tests { 68 t.Run(tt.name, func(t *testing.T) { 69 result := handleCompoundArchiveAliases(tt.input) 70 assert.Equal(t, tt.expected, result) 71 }) 72 } 73 }