feat: implement parse debian kernel version
This commit is contained in:
parent
17356ac0e4
commit
7942bd22fa
@ -29,6 +29,35 @@ type DebianKernelVersion struct {
|
||||
ABI string
|
||||
}
|
||||
|
||||
func ParseKernelVersion(pkg string) (dkv DebianKernelVersion, err error) {
|
||||
// -> 4.11.0-trunk-amd64_4.11-1~exp2_amd64.deb
|
||||
pkg = strings.Replace(pkg, "linux-image-", "", -1)
|
||||
|
||||
// -> [4.11.0-trunk-amd64 4.11-1~exp2 amd64.deb]
|
||||
fields := strings.Split(pkg, "_")
|
||||
|
||||
if len(fields) != 3 {
|
||||
err = errors.New("incorrect input format")
|
||||
return
|
||||
}
|
||||
|
||||
// 4.11.0-trunk-amd64 -> 4.11.0-trunk
|
||||
// TODO other archs?
|
||||
dkv.ABI = strings.Split(fields[0], "-amd64")[0]
|
||||
if dkv.ABI == "" {
|
||||
err = errors.New("incorrect input format")
|
||||
return
|
||||
}
|
||||
|
||||
dkv.Package = fields[1]
|
||||
if dkv.Package == "" {
|
||||
err = errors.New("incorrect input format")
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type DebianKernel struct {
|
||||
Version DebianKernelVersion
|
||||
Image snapshot.Package
|
||||
|
@ -17,3 +17,23 @@ func TestGetDebianKernel(t *testing.T) {
|
||||
|
||||
t.Logf("%s", spew.Sdump(dk))
|
||||
}
|
||||
|
||||
func TestParseKernelVersion(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
kernels, err := GetKernels()
|
||||
assert.Nil(err)
|
||||
assert.NotEmpty(kernels)
|
||||
|
||||
versions := make(map[string]bool)
|
||||
|
||||
for _, dk := range kernels {
|
||||
dkv, err := ParseKernelVersion(dk.Image.Deb.Name)
|
||||
assert.Nil(err)
|
||||
|
||||
_, found := versions[dkv.Package]
|
||||
assert.True(!found)
|
||||
|
||||
versions[dkv.Package] = true
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user