[host]: add not implemented methods.

This commit is contained in:
WAKAYAMA Shirou 2017-08-03 11:08:35 +09:00
parent 9c5b318e0d
commit 114c78c777
9 changed files with 69 additions and 15 deletions

View File

@ -20,7 +20,7 @@ build_test: ## test only buildable
CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN)
GOOS=windows go test ./... | $(BUILD_FAIL_PATTERN)
# Operating systems supported for building only (not implemented error if used)
GOOS=dragonfly go test ./... | $(BUILD_FAIL_PATTERN)
GOOS=netbsd go test ./... | $(BUILD_FAIL_PATTERN)
GOOS=solaris go test ./... | $(BUILD_FAIL_PATTERN)
# GOOS=dragonfly go test ./... | $(BUILD_FAIL_PATTERN)
GOOS=netbsd go test ./... | $(BUILD_FAIL_PATTERN)
@echo 'Successfully built on all known operating systems'

View File

@ -1,4 +1,4 @@
// +build !darwin,!linux,!freebsd,!openbsd,!windows
// +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris
package disk

View File

@ -181,8 +181,10 @@ func PlatformInformation() (string, string, string, error) {
}
func Virtualization() (string, string, error) {
system := ""
role := ""
return system, role, nil
return "", "", common.ErrNotImplementedError
}
func KernelVersion() (string, error) {
_, _, version, err := PlatformInformation()
return version, err
}

View File

@ -19,3 +19,11 @@ func Uptime() (uint64, error) {
func Users() ([]UserStat, error) {
return []UserStat{}, common.ErrNotImplementedError
}
func Virtualization() (string, string, error) {
return "", "", common.ErrNotImplementedError
}
func KernelVersion() (string, error) {
return "", common.ErrNotImplementedError
}

View File

@ -174,10 +174,7 @@ func PlatformInformation() (string, string, string, error) {
}
func Virtualization() (string, string, error) {
system := ""
role := ""
return system, role, nil
return "", "", common.ErrNotImplementedError
}
// before 9.0
@ -222,3 +219,8 @@ func getUsersFromUtmp(utmpfile string) ([]UserStat, error) {
func SensorsTemperatures() ([]TemperatureStat, error) {
return []TemperatureStat{}, common.ErrNotImplementedError
}
func KernelVersion() (string, error) {
_, _, version, err := PlatformInformation()
return version, err
}

View File

@ -110,10 +110,7 @@ func PlatformInformation() (string, string, string, error) {
}
func Virtualization() (string, string, error) {
system := ""
role := ""
return system, role, nil
return "", "", common.ErrNotImplementedError
}
func Users() ([]UserStat, error) {
@ -158,3 +155,8 @@ func Users() ([]UserStat, error) {
func SensorsTemperatures() ([]TemperatureStat, error) {
return []TemperatureStat{}, common.ErrNotImplementedError
}
func KernelVersion() (string, error) {
_, _, version, err := PlatformInformation()
return version, err
}

View File

@ -179,3 +179,26 @@ func Users() ([]UserStat, error) {
func SensorsTemperatures() ([]TemperatureStat, error) {
return []TemperatureStat{}, common.ErrNotImplementedError
}
func Virtualization() (string, string, error) {
return "", "", common.ErrNotImplementedError
}
func KernelVersion() (string, error) {
// Parse versions from output of `uname(1)`
uname, err := exec.LookPath("/usr/bin/uname")
if err != nil {
return "", err
}
out, err := invoke.Command(uname, "-srv")
if err != nil {
return "", err
}
fields := strings.Fields(string(out))
if len(fields) >= 2 {
return fields[1], nil
}
return "", fmt.Errorf("could not get kernel version")
}

View File

@ -126,3 +126,15 @@ func TestVirtualization(t *testing.T) {
t.Logf("Virtualization(): %s, %s", system, role)
}
func TestKernelVersion(t *testing.T) {
version, err := KernelVersion()
if err != nil {
t.Errorf("KernelVersion() failed, %v", err)
}
if version == "" {
t.Errorf("KernelVersion() retuns empty: %s", version)
}
t.Logf("KernelVersion(): %s", version)
}

View File

@ -192,3 +192,8 @@ func SensorsTemperatures() ([]TemperatureStat, error) {
func Virtualization() (string, string, error) {
return "", "", common.ErrNotImplementedError
}
func KernelVersion() (string, error) {
_, _, version, err := PlatformInformation()
return version, err
}