mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 23:16:30 +01:00
rename binary cataloger to be more unique (#2633)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -15,23 +15,23 @@ import (
|
||||
|
||||
const catalogerName = "binary-cataloger"
|
||||
|
||||
type CatalogerConfig struct {
|
||||
type ClassifierCatalogerConfig struct {
|
||||
Classifiers []Classifier `yaml:"classifiers" json:"classifiers" mapstructure:"classifiers"`
|
||||
}
|
||||
|
||||
func DefaultCatalogerConfig() CatalogerConfig {
|
||||
return CatalogerConfig{
|
||||
func DefaultClassifierCatalogerConfig() ClassifierCatalogerConfig {
|
||||
return ClassifierCatalogerConfig{
|
||||
Classifiers: DefaultClassifiers(),
|
||||
}
|
||||
}
|
||||
|
||||
func NewCataloger(cfg CatalogerConfig) pkg.Cataloger {
|
||||
func NewClassifierCataloger(cfg ClassifierCatalogerConfig) pkg.Cataloger {
|
||||
return &cataloger{
|
||||
classifiers: cfg.Classifiers,
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg CatalogerConfig) MarshalJSON() ([]byte, error) {
|
||||
func (cfg ClassifierCatalogerConfig) MarshalJSON() ([]byte, error) {
|
||||
// only keep the class names
|
||||
var names []string
|
||||
for _, cls := range cfg.Classifiers {
|
||||
|
||||
@@ -888,7 +888,7 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.logicalFixture, func(t *testing.T) {
|
||||
c := NewCataloger(DefaultCatalogerConfig())
|
||||
c := NewClassifierCataloger(DefaultClassifierCatalogerConfig())
|
||||
|
||||
// logicalFixture is the logical path to the full binary or snippet. This is relative to the test-fixtures/classifiers/snippets
|
||||
// or test-fixtures/classifiers/bin directory . Snippets are searched for first, and if not found, then existing binaries are
|
||||
@@ -933,7 +933,7 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases_Image(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
c := NewCataloger(DefaultCatalogerConfig())
|
||||
c := NewClassifierCataloger(DefaultClassifierCatalogerConfig())
|
||||
|
||||
img := imagetest.GetFixtureImage(t, "docker-archive", test.fixtureImage)
|
||||
src, err := source.NewFromStereoscopeImageObject(img, test.fixtureImage, nil)
|
||||
@@ -964,7 +964,7 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases_Image(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClassifierCataloger_DefaultClassifiers_NegativeCases(t *testing.T) {
|
||||
c := NewCataloger(DefaultCatalogerConfig())
|
||||
c := NewClassifierCataloger(DefaultClassifierCatalogerConfig())
|
||||
|
||||
src, err := source.NewFromDirectoryPath("test-fixtures/classifiers/negative")
|
||||
assert.NoError(t, err)
|
||||
@@ -1006,13 +1006,13 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
config CatalogerConfig
|
||||
config ClassifierCatalogerConfig
|
||||
fixtureDir string
|
||||
expected *pkg.Package
|
||||
}{
|
||||
{
|
||||
name: "empty-negative",
|
||||
config: CatalogerConfig{
|
||||
config: ClassifierCatalogerConfig{
|
||||
Classifiers: []Classifier{},
|
||||
},
|
||||
fixtureDir: "test-fixtures/custom/go-1.14",
|
||||
@@ -1020,7 +1020,7 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "default-positive",
|
||||
config: CatalogerConfig{
|
||||
config: ClassifierCatalogerConfig{
|
||||
Classifiers: defaultClassifers,
|
||||
},
|
||||
fixtureDir: "test-fixtures/custom/go-1.14",
|
||||
@@ -1028,7 +1028,7 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "nodefault-negative",
|
||||
config: CatalogerConfig{
|
||||
config: ClassifierCatalogerConfig{
|
||||
Classifiers: []Classifier{fooClassifier},
|
||||
},
|
||||
fixtureDir: "test-fixtures/custom/go-1.14",
|
||||
@@ -1036,7 +1036,7 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "default-extended-positive",
|
||||
config: CatalogerConfig{
|
||||
config: ClassifierCatalogerConfig{
|
||||
Classifiers: append(
|
||||
append([]Classifier{}, defaultClassifers...),
|
||||
fooClassifier,
|
||||
@@ -1047,7 +1047,7 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "default-custom-negative",
|
||||
config: CatalogerConfig{
|
||||
config: ClassifierCatalogerConfig{
|
||||
|
||||
Classifiers: append(
|
||||
append([]Classifier{}, defaultClassifers...),
|
||||
@@ -1066,7 +1066,7 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "default-cutsom-positive",
|
||||
config: CatalogerConfig{
|
||||
config: ClassifierCatalogerConfig{
|
||||
Classifiers: append(
|
||||
append([]Classifier{}, defaultClassifers...),
|
||||
fooClassifier,
|
||||
@@ -1078,7 +1078,7 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
c := NewCataloger(test.config)
|
||||
c := NewClassifierCataloger(test.config)
|
||||
|
||||
src, err := source.NewFromDirectoryPath(test.fixtureDir)
|
||||
require.NoError(t, err)
|
||||
@@ -1249,7 +1249,7 @@ func (p *panicyResolver) FileMetadataByLocation(_ file.Location) (file.Metadata,
|
||||
var _ file.Resolver = (*panicyResolver)(nil)
|
||||
|
||||
func Test_Cataloger_ResilientToErrors(t *testing.T) {
|
||||
c := NewCataloger(DefaultCatalogerConfig())
|
||||
c := NewClassifierCataloger(DefaultClassifierCatalogerConfig())
|
||||
|
||||
resolver := &panicyResolver{}
|
||||
_, _, err := c.Catalog(context.Background(), resolver)
|
||||
@@ -1261,13 +1261,13 @@ func TestCatalogerConfig_MarshalJSON(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
cfg CatalogerConfig
|
||||
cfg ClassifierCatalogerConfig
|
||||
want string
|
||||
wantErr assert.ErrorAssertionFunc
|
||||
}{
|
||||
{
|
||||
name: "only show names of classes",
|
||||
cfg: CatalogerConfig{
|
||||
cfg: ClassifierCatalogerConfig{
|
||||
Classifiers: []Classifier{
|
||||
{
|
||||
Class: "class",
|
||||
|
||||
Reference in New Issue
Block a user