mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
* split up sbom.Format into encode and decode ops Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * update cmd pkg to inject format configs Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * bump cyclonedx schema to 1.5 Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * redact image metadata from github encoder tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add more testing around format decoder identify Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add test case for format version options Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix cli tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix CLI test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * [wip] - review comments Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * keep encoder creation out of post load function Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * keep decider and identify functions Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add a few more doc comments Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * remove format encoder default function helpers Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * address PR feedback Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * move back to streaming based decode functions Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * with common convention for encoder constructors Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix tests and allow for encoders to be created from cli options Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix cli tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix linting Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * buffer reads from stdin to support seeking Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
112 lines
2.0 KiB
Go
112 lines
2.0 KiB
Go
package format
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/anchore/syft/syft/sbom"
|
|
)
|
|
|
|
func Test_versionMatches(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
version string
|
|
match string
|
|
matches bool
|
|
}{
|
|
{
|
|
name: "any version matches number",
|
|
version: string(sbom.AnyVersion),
|
|
match: "6",
|
|
matches: true,
|
|
},
|
|
{
|
|
name: "number matches any version",
|
|
version: "6",
|
|
match: string(sbom.AnyVersion),
|
|
matches: true,
|
|
},
|
|
{
|
|
name: "same number matches",
|
|
version: "3",
|
|
match: "3",
|
|
matches: true,
|
|
},
|
|
{
|
|
name: "same major number matches",
|
|
version: "3.1",
|
|
match: "3",
|
|
matches: true,
|
|
},
|
|
{
|
|
name: "same minor number matches",
|
|
version: "3.1",
|
|
match: "3.1",
|
|
matches: true,
|
|
},
|
|
{
|
|
name: "wildcard-version matches minor",
|
|
version: "7.1.3",
|
|
match: "7.*",
|
|
matches: true,
|
|
},
|
|
{
|
|
name: "wildcard-version matches patch",
|
|
version: "7.4.8",
|
|
match: "7.4.*",
|
|
matches: true,
|
|
},
|
|
{
|
|
name: "sub-version matches major",
|
|
version: "7.19.11",
|
|
match: "7",
|
|
matches: true,
|
|
},
|
|
{
|
|
name: "sub-version matches minor",
|
|
version: "7.55.2",
|
|
match: "7.55",
|
|
matches: true,
|
|
},
|
|
{
|
|
name: "sub-version matches patch",
|
|
version: "7.32.6",
|
|
match: "7.32.6",
|
|
matches: true,
|
|
},
|
|
// negative tests
|
|
{
|
|
name: "different number does not match",
|
|
version: "3",
|
|
match: "4",
|
|
matches: false,
|
|
},
|
|
{
|
|
name: "sub-version doesn't match major",
|
|
version: "7.2.5",
|
|
match: "8.2.5",
|
|
matches: false,
|
|
},
|
|
{
|
|
name: "sub-version doesn't match minor",
|
|
version: "7.2.9",
|
|
match: "7.1",
|
|
matches: false,
|
|
},
|
|
{
|
|
name: "sub-version doesn't match patch",
|
|
version: "7.32.6",
|
|
match: "7.32.5",
|
|
matches: false,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
matches := versionMatches(test.version, test.match)
|
|
assert.Equal(t, test.matches, matches)
|
|
})
|
|
}
|
|
}
|