Skip to content

Commit

Permalink
linux: Fix bug NativeArchitecture ending in newline (#223)
Browse files Browse the repository at this point in the history
This commit fixes a bug where HostInfo.NativeArchitecture ends in a
newline and adds a test.
  • Loading branch information
dliappis authored May 30, 2024
1 parent df3b073 commit c6dcd26
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/223.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
linux: Remove newline from HostInfo.NativeArchitecture value.
```
2 changes: 1 addition & 1 deletion providers/linux/arch_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ func NativeArchitecture() (string, error) {
nativeArch := string(data)
nativeArch = strings.TrimRight(nativeArch, "\n")

return string(data), nil
return nativeArch, nil
}
5 changes: 5 additions & 0 deletions providers/linux/arch_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit c6dcd26

Please sign in to comment.