From c6dcd26cb0d8de11c593b2755ccf22ab7492d77d Mon Sep 17 00:00:00 2001 From: Dimitrios Liappis Date: Thu, 30 May 2024 16:28:45 +0300 Subject: [PATCH] linux: Fix bug NativeArchitecture ending in newline (#223) This commit fixes a bug where HostInfo.NativeArchitecture ends in a newline and adds a test. --- .changelog/223.txt | 3 +++ providers/linux/arch_linux.go | 2 +- providers/linux/arch_linux_test.go | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changelog/223.txt diff --git a/.changelog/223.txt b/.changelog/223.txt new file mode 100644 index 0000000..c146df4 --- /dev/null +++ b/.changelog/223.txt @@ -0,0 +1,3 @@ +```release-note:bug +linux: Remove newline from HostInfo.NativeArchitecture value. +``` diff --git a/providers/linux/arch_linux.go b/providers/linux/arch_linux.go index f1d807f..efb3010 100644 --- a/providers/linux/arch_linux.go +++ b/providers/linux/arch_linux.go @@ -81,5 +81,5 @@ func NativeArchitecture() (string, error) { nativeArch := string(data) nativeArch = strings.TrimRight(nativeArch, "\n") - return string(data), nil + return nativeArch, nil } diff --git a/providers/linux/arch_linux_test.go b/providers/linux/arch_linux_test.go index be46203..cae30a6 100644 --- a/providers/linux/arch_linux_test.go +++ b/providers/linux/arch_linux_test.go @@ -18,19 +18,24 @@ package linux import ( + "regexp" "testing" "github.com/stretchr/testify/assert" ) +var reNewline = regexp.MustCompile("^.*\n+$") + func TestArchitecture(t *testing.T) { a, err := Architecture() assert.NoError(t, err) assert.NotEmpty(t, a) + assert.NotRegexp(t, reNewline, a, "should not end in newlines") } func TestNativeArchitecture(t *testing.T) { a, err := NativeArchitecture() assert.NoError(t, err) assert.NotEmpty(t, a) + assert.NotRegexp(t, reNewline, a, "should not end in newlines") }