mirror of
https://github.com/anchore/syft.git
synced 2026-11-03 16:06:36 +01:00
Add experimental cataloger capabilities command (#4317)
* add info command from generated capabilities Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * correct gentoo and arch ecosystems Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * rename os pkg types Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * better binary cataloger description Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * expose metadata and pacakge types in json Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * expose json schema types Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add completeness tests for metadata types Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * latest generation Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix linting Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * improve testing a docs Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix tests and linting Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * restore goreleaser config Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * tweak diagram Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix pdm Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * chore: java binary data Signed-off-by: Keith Zantow <kzantow@gmail.com> * new capability descriptions for gguf and python Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * correct poetry lock integrity hash claim Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix compile error Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix: remove purl version from overrides Signed-off-by: Keith Zantow <kzantow@gmail.com> * fix lua deps ref Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * keep gguf as ai ecosystem Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * split packages.yaml to multiple files by go package Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * ensure tests do not use go test cache Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * sort json output for info command Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * docs: fix ocaml, php, and portage capabilities yaml Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com> * chore: update erlang capabilities Signed-off-by: Keith Zantow <kzantow@gmail.com> * chore: update java capabilities Signed-off-by: Keith Zantow <kzantow@gmail.com> * chore: update javascript capabilities Signed-off-by: Keith Zantow <kzantow@gmail.com> * chore: update linux kernel capabilities Signed-off-by: Keith Zantow <kzantow@gmail.com> * remove missing tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix package.yaml references Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * revert license list change Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * check for drift in capability descriptions Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * regenerate capabilities Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * test cleanup Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * use fixture cache in static analysis Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * claim fixtures pre-req for cap generation Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * update documentation with correct regeneration procedure Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * chore: ruby-gemspec-cataloger finds no dependencies Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com> * chore: fix python docs and config comment Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com> * chore: commit re-generated java yaml Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com> * add cataloger selection to caps command Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * re-generate cap yamls Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix tests for cataloger selection Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix cli test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add missing tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix linting Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * rename cmd to `cataloger info` Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * [wip] change capability description locations Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * [wip] continued Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * [wip] adjust for import cycles Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * correct docs Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix linting Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> Signed-off-by: Keith Zantow <kzantow@gmail.com> Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com> Co-authored-by: Keith Zantow <kzantow@gmail.com> Co-authored-by: Will Murphy <willmurphyscode@users.noreply.github.com>
This commit is contained in:
co-authored by
Keith Zantow
Will Murphy
parent
ae1a247f3d
commit
b3c70da3ea
@@ -0,0 +1,185 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestFindFieldValue(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
yamlContent string
|
||||
fieldName string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "finds simple string field",
|
||||
yamlContent: `
|
||||
name: test-cataloger
|
||||
type: custom
|
||||
`,
|
||||
fieldName: "name",
|
||||
want: "test-cataloger",
|
||||
},
|
||||
{
|
||||
name: "finds type field",
|
||||
yamlContent: `
|
||||
name: test-cataloger
|
||||
type: generic
|
||||
`,
|
||||
fieldName: "type",
|
||||
want: "generic",
|
||||
},
|
||||
{
|
||||
name: "returns empty for non-existent field",
|
||||
yamlContent: `
|
||||
name: test-cataloger
|
||||
`,
|
||||
fieldName: "nonexistent",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "finds parser_function field",
|
||||
yamlContent: `
|
||||
parser_function: parseGoMod
|
||||
metadata_types: [GoModMetadata]
|
||||
`,
|
||||
fieldName: "parser_function",
|
||||
want: "parseGoMod",
|
||||
},
|
||||
{
|
||||
name: "handles empty mapping",
|
||||
yamlContent: `{}`,
|
||||
fieldName: "any",
|
||||
want: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var rootNode yaml.Node
|
||||
err := yaml.Unmarshal([]byte(tt.yamlContent), &rootNode)
|
||||
require.NoError(t, err)
|
||||
|
||||
// get the mapping node
|
||||
var mappingNode *yaml.Node
|
||||
if rootNode.Kind == yaml.DocumentNode && len(rootNode.Content) > 0 {
|
||||
mappingNode = rootNode.Content[0]
|
||||
} else {
|
||||
mappingNode = &rootNode
|
||||
}
|
||||
|
||||
got := findFieldValue(mappingNode, tt.fieldName)
|
||||
require.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddCatalogerFieldComment(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fieldName string
|
||||
fieldValue string
|
||||
catalogerName string
|
||||
wantLineComment string
|
||||
}{
|
||||
{
|
||||
name: "ecosystem is MANUAL",
|
||||
fieldName: "ecosystem",
|
||||
catalogerName: "test-cataloger",
|
||||
wantLineComment: "MANUAL",
|
||||
},
|
||||
{
|
||||
name: "name is AUTO-GENERATED",
|
||||
fieldName: "name",
|
||||
catalogerName: "test-cataloger",
|
||||
wantLineComment: autoGeneratedComment,
|
||||
},
|
||||
{
|
||||
name: "type is AUTO-GENERATED",
|
||||
fieldName: "type",
|
||||
catalogerName: "test-cataloger",
|
||||
wantLineComment: autoGeneratedComment,
|
||||
},
|
||||
{
|
||||
name: "source is AUTO-GENERATED",
|
||||
fieldName: "source",
|
||||
catalogerName: "test-cataloger",
|
||||
wantLineComment: autoGeneratedComment,
|
||||
},
|
||||
{
|
||||
name: "config is AUTO-GENERATED",
|
||||
fieldName: "config",
|
||||
catalogerName: "test-cataloger",
|
||||
wantLineComment: autoGeneratedComment,
|
||||
},
|
||||
{
|
||||
name: "selectors is AUTO-GENERATED",
|
||||
fieldName: "selectors",
|
||||
catalogerName: "test-cataloger",
|
||||
wantLineComment: autoGeneratedComment,
|
||||
},
|
||||
{
|
||||
name: "parsers is AUTO-GENERATED structure",
|
||||
fieldName: "parsers",
|
||||
catalogerName: "test-cataloger",
|
||||
wantLineComment: "AUTO-GENERATED structure",
|
||||
},
|
||||
{
|
||||
name: "detectors for binary-classifier-cataloger is AUTO-GENERATED",
|
||||
fieldName: "detectors",
|
||||
catalogerName: "binary-classifier-cataloger",
|
||||
wantLineComment: autoGeneratedComment,
|
||||
},
|
||||
{
|
||||
name: "detectors for other catalogers is MANUAL",
|
||||
fieldName: "detectors",
|
||||
catalogerName: "java-archive-cataloger",
|
||||
wantLineComment: "MANUAL - edit detectors here",
|
||||
},
|
||||
{
|
||||
name: "metadata_types is AUTO-GENERATED",
|
||||
fieldName: "metadata_types",
|
||||
catalogerName: "test-cataloger",
|
||||
wantLineComment: autoGeneratedComment,
|
||||
},
|
||||
{
|
||||
name: "package_types is AUTO-GENERATED",
|
||||
fieldName: "package_types",
|
||||
catalogerName: "test-cataloger",
|
||||
wantLineComment: autoGeneratedComment,
|
||||
},
|
||||
{
|
||||
name: "json_schema_types is AUTO-GENERATED",
|
||||
fieldName: "json_schema_types",
|
||||
catalogerName: "test-cataloger",
|
||||
wantLineComment: autoGeneratedComment,
|
||||
},
|
||||
{
|
||||
name: "capabilities is MANUAL",
|
||||
fieldName: "capabilities",
|
||||
catalogerName: "test-cataloger",
|
||||
wantLineComment: "MANUAL - edit capabilities here",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// create key and value nodes
|
||||
keyNode := &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: tt.fieldName,
|
||||
}
|
||||
valueNode := &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: tt.fieldValue,
|
||||
}
|
||||
|
||||
addCatalogerFieldComment(keyNode, valueNode, tt.catalogerName)
|
||||
|
||||
require.Equal(t, tt.wantLineComment, keyNode.LineComment)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user