mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 09:41:57 +00:00
Simplify Utsname string conversion
Use Utsname from golang.org/x/sys/unix which contains byte array instead of int8/uint8 array members. This allows to simplify the string conversions of these members and the marshal.FromUtsname functions are no longer needed.
This commit is contained in:
@@ -2,10 +2,11 @@ package host_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/weaveworks/scope/probe/host"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func TestUname(t *testing.T) {
|
||||
@@ -16,9 +17,9 @@ func TestUname(t *testing.T) {
|
||||
release = "rls"
|
||||
version = "ver"
|
||||
)
|
||||
host.Uname = func(uts *syscall.Utsname) error {
|
||||
uts.Release = string2c(release)
|
||||
uts.Version = string2c(version)
|
||||
host.Uname = func(uts *unix.Utsname) error {
|
||||
copy(uts.Release[:], []byte(release))
|
||||
copy(uts.Version[:], []byte(version))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -31,11 +32,3 @@ func TestUname(t *testing.T) {
|
||||
t.Errorf("want %q, have %q", want, have)
|
||||
}
|
||||
}
|
||||
|
||||
func string2c(s string) [65]int8 {
|
||||
var result [65]int8
|
||||
for i, c := range s {
|
||||
result[i] = int8(c)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user