From 507785f89ea55a5e1bc42514ea3fd105d743b546 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Mon, 4 Dec 2023 11:36:37 +0100 Subject: [PATCH] chore(pkg/driver): address some review concerns. Signed-off-by: Federico Di Pierro Co-authored-by: Aldo Lacuku --- pkg/driver/distro/debian_test.go | 24 +++++++++++++++++++----- pkg/driver/distro/generic.go | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/pkg/driver/distro/debian_test.go b/pkg/driver/distro/debian_test.go index bb4a7ff4..14afd528 100644 --- a/pkg/driver/distro/debian_test.go +++ b/pkg/driver/distro/debian_test.go @@ -92,6 +92,7 @@ func TestDistroDebianFixup(t *testing.T) { krInput string kvInput string krExpected string + kvExpected string } testCases := []testCase{ { @@ -99,30 +100,42 @@ func TestDistroDebianFixup(t *testing.T) { krInput: "5.10.0-0.deb10.22-rt-amd64", kvInput: "#1 SMP PREEMPT_DYNAMIC Debian 5.10.178-3", krExpected: "5.10.178-3-rt-amd64", + kvExpected: "1", }, { - // Substitution needed since kernelversion contains the real kernelrelease (-cloud) - krInput: "6.1.0-13-cloud-amd64", + // Substitution needed since kernelversion contains the real kernelrelease (generic flavor) + krInput: "6.1.0-13-amd64", kvInput: "#1 SMP PREEMPT_DYNAMIC Debian 6.1.55-1 (2023-09-29)", - krExpected: "6.1.55-1-cloud-amd64", + krExpected: "6.1.55-1-amd64", + kvExpected: "1", }, { // Substitution NOT needed krInput: "5.10.0-0.deb10.22-amd64", kvInput: "#1 SMP PREEMPT_DYNAMIC", krExpected: "5.10.0-0.deb10.22-amd64", + kvExpected: "1", }, { - // Substitution NOT needed + // Substitution NOT needed; kernelversion is 39 krInput: "5.10.0-0", - kvInput: "#1 SMP PREEMPT_DYNAMIC", + kvInput: "#39 SMP PREEMPT_DYNAMIC", krExpected: "5.10.0-0", + kvExpected: "39", }, { // Substitution NOT needed krInput: "6.5.3-1~bpo12+1-rt-amd64", kvInput: "#1 SMP PREEMPT_DYNAMIC", krExpected: "6.5.3-1~bpo12+1-rt-amd64", + kvExpected: "1", + }, + { + // Substitution NOT needed + krInput: "6.5.3-1~bpo12+1-rt-amd64", + kvInput: "malformed", + krExpected: "6.5.3-1~bpo12+1-rt-amd64", + kvExpected: "malformed", }, } for _, tCase := range testCases { @@ -131,5 +144,6 @@ func TestDistroDebianFixup(t *testing.T) { kr.KernelVersion = tCase.kvInput fixedKr := deb.FixupKernel(kr) assert.Equal(t, tCase.krExpected, fixedKr.String()) + assert.Equal(t, tCase.kvExpected, fixedKr.KernelVersion) } } diff --git a/pkg/driver/distro/generic.go b/pkg/driver/distro/generic.go index bfcab3f4..43f24e8c 100644 --- a/pkg/driver/distro/generic.go +++ b/pkg/driver/distro/generic.go @@ -44,7 +44,7 @@ func (g *generic) String() string { //nolint:gocritic // the method shall not be able to modify kr func (g *generic) FixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease { // Take eg: "#1 SMP PREEMPT_DYNAMIC Tue, 10 Oct 2023 21:10:21 +0000" and return "1". - kv := strings.Trim(kr.KernelVersion, "#") + kv := strings.TrimLeft(kr.KernelVersion, "#") kv = strings.Split(kv, " ")[0] kr.KernelVersion = kv return kr