-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #289 from weaveworks/fix-host-on-darwin
Fix host on darwin
- Loading branch information
Showing
7 changed files
with
180 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package host_test | ||
|
||
import ( | ||
"fmt" | ||
"syscall" | ||
"testing" | ||
|
||
"github.com/weaveworks/scope/probe/host" | ||
) | ||
|
||
func TestUname(t *testing.T) { | ||
oldUname := host.Uname | ||
defer func() { host.Uname = oldUname }() | ||
|
||
const ( | ||
release = "rls" | ||
version = "ver" | ||
) | ||
host.Uname = func(uts *syscall.Utsname) error { | ||
uts.Release = string2c(release) | ||
uts.Version = string2c(version) | ||
return nil | ||
} | ||
|
||
have, err := host.GetKernelVersion() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if want := fmt.Sprintf("%s %s", release, version); want != have { | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package host_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/weaveworks/scope/probe/host" | ||
) | ||
|
||
func TestGetKernelVersion(t *testing.T) { | ||
have, err := host.GetKernelVersion() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if strings.Contains(have, "unknown") { | ||
t.Fatal(have) | ||
} | ||
t.Log(have) | ||
} | ||
|
||
func TestGetLoad(t *testing.T) { | ||
have := host.GetLoad() | ||
if strings.Contains(have, "unknown") { | ||
t.Fatal(have) | ||
} | ||
t.Log(have) | ||
} | ||
|
||
func TestGetUptime(t *testing.T) { | ||
have, err := host.GetUptime() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if have == 0 { | ||
t.Fatal(have) | ||
} | ||
t.Log(have.String()) | ||
} |