mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
Add ability to scan snaps (as a source) (#3929)
This commit is contained in:
@@ -145,6 +145,51 @@ func TestSource_UnmarshalJSON(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "snap",
|
||||
input: []byte(`{
|
||||
"id": "foobar",
|
||||
"name": "etcd",
|
||||
"version": "3.4.36",
|
||||
"type": "snap",
|
||||
"metadata": {
|
||||
"summary": "Distributed reliable key-value store",
|
||||
"base": "core18",
|
||||
"grade": "stable",
|
||||
"confinement": "strict",
|
||||
"architectures": [
|
||||
"amd64"
|
||||
],
|
||||
"digests": [
|
||||
{
|
||||
"algorithm": "sha256",
|
||||
"value": "6700d789d2c38b0f7513058ddcea8f9a275e2206b4621a772eb065e12069956e"
|
||||
}
|
||||
]
|
||||
}
|
||||
}`),
|
||||
expected: &Source{
|
||||
ID: "foobar",
|
||||
Name: "etcd",
|
||||
Version: "3.4.36",
|
||||
Type: "snap",
|
||||
Metadata: source.SnapMetadata{
|
||||
Summary: "Distributed reliable key-value store",
|
||||
Base: "core18",
|
||||
Grade: "stable",
|
||||
Confinement: "strict",
|
||||
Architectures: []string{
|
||||
"amd64",
|
||||
},
|
||||
Digests: []file.Digest{
|
||||
{
|
||||
Algorithm: "sha256",
|
||||
Value: "6700d789d2c38b0f7513058ddcea8f9a275e2206b4621a772eb065e12069956e",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "unknown source type",
|
||||
input: []byte(`{
|
||||
|
||||
@@ -127,6 +127,36 @@ func Test_toSourceModel(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "snap",
|
||||
src: source.Description{
|
||||
ID: "test-id",
|
||||
Name: "some-name",
|
||||
Version: "some-version",
|
||||
Metadata: source.SnapMetadata{
|
||||
Summary: "some summary",
|
||||
Base: "some/base",
|
||||
Grade: "some grade",
|
||||
Confinement: "some confinement",
|
||||
Architectures: []string{"x86_64", "arm64"},
|
||||
Digests: []file.Digest{{Algorithm: "sha256", Value: "some-digest"}},
|
||||
},
|
||||
},
|
||||
expected: model.Source{
|
||||
ID: "test-id",
|
||||
Name: "some-name",
|
||||
Version: "some-version",
|
||||
Type: "snap",
|
||||
Metadata: source.SnapMetadata{
|
||||
Summary: "some summary",
|
||||
Base: "some/base",
|
||||
Grade: "some grade",
|
||||
Confinement: "some confinement",
|
||||
Architectures: []string{"x86_64", "arm64"},
|
||||
Digests: []file.Digest{{Algorithm: "sha256", Value: "some-digest"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
// below are regression tests for when the name/version are not provided
|
||||
// historically we've hoisted up the name/version from the metadata, now it is a simple pass-through
|
||||
{
|
||||
|
||||
@@ -100,6 +100,36 @@ func Test_toSyftSourceData(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "snap",
|
||||
src: model.Source{
|
||||
ID: "the-id",
|
||||
Name: "some-name",
|
||||
Version: "some-version",
|
||||
Type: "snap",
|
||||
Metadata: source.SnapMetadata{
|
||||
Summary: "something!",
|
||||
Base: "base!",
|
||||
Grade: "grade!",
|
||||
Confinement: "confined!",
|
||||
Architectures: []string{"arch!"},
|
||||
Digests: []file.Digest{{Algorithm: "sha256", Value: "some-digest!"}},
|
||||
},
|
||||
},
|
||||
expected: &source.Description{
|
||||
ID: "the-id",
|
||||
Name: "some-name",
|
||||
Version: "some-version",
|
||||
Metadata: source.SnapMetadata{
|
||||
Summary: "something!",
|
||||
Base: "base!",
|
||||
Grade: "grade!",
|
||||
Confinement: "confined!",
|
||||
Architectures: []string{"arch!"},
|
||||
Digests: []file.Digest{{Algorithm: "sha256", Value: "some-digest!"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
// below are regression tests for when the name/version are not provided
|
||||
// historically we've hoisted up the name/version from the metadata, now it is a simple pass-through
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user