syft/internal/file/glob_match_test.go
Patrick Pichler 65e58ba33d feat: add support for detecting packages in JARs
Support for detection of packages present in a JAR has been added. It
can be enabeld via the `DetectContainedPackages` config flag.

Signed-off-by: Patrick Pichler <git@patrickpichler.dev>
2025-11-24 08:01:28 +01:00

43 lines
1021 B
Go

package file
import (
"strings"
"testing"
)
func TestGlobMatch(t *testing.T) {
var tests = []struct {
pattern string
data string
ok bool
}{
{"", "", true},
{"x", "", false},
{"", "x", false},
{"abc", "abc", true},
{"*", "abc", true},
{"*c", "abc", true},
{"*b", "abc", false},
{"a*", "abc", true},
{"b*", "abc", false},
{"a*", "a", true},
{"*a", "a", true},
{"a*b*c*d*e*", "axbxcxdxe", true},
{"a*b*c*d*e*", "axbxcxdxexxx", true},
{"a*b?c*x", "abxbbxdbxebxczzx", true},
{"a*b?c*x", "abxbbxdbxebxczzy", false},
{"a*a*a*a*b", strings.Repeat("a", 100), false},
{"*x", "xxx", true},
{"/home/place/**", "/home/place/a/thing", true},
{"/org/test/**/*.class", "/org/test/system/files/Hello.class", true},
{"**/*.class", "/org/test/system/files/Hello.class", true},
{"**/*.class", "Hello.class", false},
}
for _, test := range tests {
if GlobMatch(test.pattern, test.data) != test.ok {
t.Errorf("failed glob='%s' data='%s'", test.pattern, test.data)
}
}
}