syft/internal/file/archive_aliases_test.go
Christopher Phillips 57ec3a6561
feat: apply HandleCompundArchiveAliases across syft
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
2025-12-01 11:05:59 -05:00

74 lines
1.5 KiB
Go

package file
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestHandleCompoundArchiveAliases(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "tgz to tar.gz",
input: "/path/to/archive.tgz",
expected: "/path/to/archive.tar.gz",
},
{
name: "tbz2 to tar.bz2",
input: "/path/to/archive.tbz2",
expected: "/path/to/archive.tar.bz2",
},
{
name: "txz to tar.xz",
input: "/path/to/archive.txz",
expected: "/path/to/archive.tar.xz",
},
{
name: "tlz to tar.lz",
input: "/path/to/archive.tlz",
expected: "/path/to/archive.tar.lz",
},
{
name: "tzst to tar.zst",
input: "/path/to/archive.tzst",
expected: "/path/to/archive.tar.zst",
},
{
name: "standard tar.gz unchanged",
input: "/path/to/archive.tar.gz",
expected: "/path/to/archive.tar.gz",
},
{
name: "zip unchanged",
input: "/path/to/archive.zip",
expected: "/path/to/archive.zip",
},
{
name: "no extension unchanged",
input: "/path/to/archive",
expected: "/path/to/archive",
},
{
name: "case sensitive - TGZ not matched",
input: "/path/to/archive.TGZ",
expected: "/path/to/archive.TGZ",
},
{
name: "just filename with tgz",
input: "archive.tgz",
expected: "archive.tar.gz",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := HandleCompoundArchiveAliases(tt.input)
assert.Equal(t, tt.expected, result)
})
}
}