alpine: truncate namespace to "vMAJOR.MINOR"

This commit is contained in:
Jimmy Zelinskie 2016-12-14 18:00:05 -05:00
parent f8457b98e7
commit 9be305d19f
2 changed files with 16 additions and 7 deletions

View File

@ -18,6 +18,7 @@ import (
"bufio"
"bytes"
"regexp"
"strings"
"github.com/coreos/clair/database"
"github.com/coreos/clair/worker/detectors"
@ -25,7 +26,7 @@ import (
const (
osName = "alpine"
alpineReleasePath = "/etc/alpine-release"
alpineReleasePath = "etc/alpine-release"
)
var versionRegexp = regexp.MustCompile(`^(\d)+\.(\d)+\.(\d)+$`)
@ -46,8 +47,8 @@ func (d *detector) Detect(data map[string][]byte) *database.Namespace {
line := scanner.Text()
match := versionRegexp.FindStringSubmatch(line)
if len(match) > 0 {
version := match[0]
return &database.Namespace{Name: osName + ":" + version}
versionNumbers := strings.Split(match[0], ".")
return &database.Namespace{Name: osName + ":" + "v" + versionNumbers[0] + "." + versionNumbers[1]}
}
}
}

View File

@ -24,12 +24,20 @@ import (
func TestAlpineReleaseNamespaceDetection(t *testing.T) {
testData := []namespace.TestData{
{
ExpectedNamespace: &database.Namespace{Name: "alpine:0.3.4"},
Data: map[string][]byte{"/etc/alpine-release": []byte(`0.3.4`)},
ExpectedNamespace: &database.Namespace{Name: "alpine:v3.3"},
Data: map[string][]byte{"etc/alpine-release": []byte(`3.3.4`)},
},
{
ExpectedNamespace: &database.Namespace{Name: "alpine:0.3.4"},
Data: map[string][]byte{"/etc/alpine-release": []byte(`
ExpectedNamespace: &database.Namespace{Name: "alpine:v3.4"},
Data: map[string][]byte{"etc/alpine-release": []byte(`3.4.0`)},
},
{
ExpectedNamespace: &database.Namespace{Name: "alpine:v0.3"},
Data: map[string][]byte{"etc/alpine-release": []byte(`0.3.4`)},
},
{
ExpectedNamespace: &database.Namespace{Name: "alpine:v0.3"},
Data: map[string][]byte{"etc/alpine-release": []byte(`
0.3.4
`)},
},