Files
weave-scope/probe/host/system_linux_test.go
Tobias Klauser 89f3ce2e64 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.
2017-11-02 08:45:54 +01:00

35 lines
681 B
Go

package host_test
import (
"fmt"
"testing"
"github.com/weaveworks/scope/probe/host"
"golang.org/x/sys/unix"
)
func TestUname(t *testing.T) {
oldUname := host.Uname
defer func() { host.Uname = oldUname }()
const (
release = "rls"
version = "ver"
)
host.Uname = func(uts *unix.Utsname) error {
copy(uts.Release[:], []byte(release))
copy(uts.Version[:], []byte(version))
return nil
}
haveRelease, haveVersion, err := host.GetKernelReleaseAndVersion()
if err != nil {
t.Fatal(err)
}
have := fmt.Sprintf("%s %s", haveRelease, haveVersion)
if want := fmt.Sprintf("%s %s", release, version); want != have {
t.Errorf("want %q, have %q", want, have)
}
}