mirror of
https://github.com/anchore/grype
synced 2024-11-14 00:07:08 +00:00
a869480f89
Co-authored-by: Christopher Angelo Phillips <32073428+spiffcs@users.noreply.github.com> Co-authored-by: Christopher Phillips <christopher.phillips@anchore.com>
42 lines
1,022 B
Go
42 lines
1,022 B
Go
package cmd
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/anchore/grype/grype/pkg"
|
|
"github.com/anchore/grype/internal/config"
|
|
)
|
|
|
|
func Test_applyDistroHint(t *testing.T) {
|
|
ctx := pkg.Context{}
|
|
cfg := config.Application{}
|
|
|
|
applyDistroHint([]pkg.Package{}, &ctx, &cfg)
|
|
assert.Nil(t, ctx.Distro)
|
|
|
|
// works when distro is nil
|
|
cfg.Distro = "alpine:3.10"
|
|
applyDistroHint([]pkg.Package{}, &ctx, &cfg)
|
|
assert.NotNil(t, ctx.Distro)
|
|
|
|
assert.Equal(t, "alpine", ctx.Distro.Name)
|
|
assert.Equal(t, "3.10", ctx.Distro.Version)
|
|
|
|
// does override an existing distro
|
|
cfg.Distro = "ubuntu:latest"
|
|
applyDistroHint([]pkg.Package{}, &ctx, &cfg)
|
|
assert.NotNil(t, ctx.Distro)
|
|
|
|
assert.Equal(t, "ubuntu", ctx.Distro.Name)
|
|
assert.Equal(t, "latest", ctx.Distro.Version)
|
|
|
|
// doesn't remove an existing distro when empty
|
|
cfg.Distro = ""
|
|
applyDistroHint([]pkg.Package{}, &ctx, &cfg)
|
|
assert.NotNil(t, ctx.Distro)
|
|
|
|
assert.Equal(t, "ubuntu", ctx.Distro.Name)
|
|
assert.Equal(t, "latest", ctx.Distro.Version)
|
|
}
|