forked from elastic/gosigar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sigar_windows_test.go
72 lines (59 loc) · 1.42 KB
/
sigar_windows_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package sigar_test
import (
"math"
"os"
"os/user"
"strings"
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
sigar "github.com/elastic/gosigar"
)
var _ = Describe("SigarWindows", func() {
Describe("Memory", func() {
It("gets the total memory", func() {
mem := sigar.Mem{}
err := mem.Get()
Ω(err).ShouldNot(HaveOccurred())
Ω(mem.Total).Should(BeNumerically(">", 0))
})
})
Describe("Disk", func() {
It("gets the total disk space", func() {
usage := sigar.FileSystemUsage{}
err := usage.Get(os.TempDir())
Ω(err).ShouldNot(HaveOccurred())
Ω(usage.Total).Should(BeNumerically(">", 0))
})
})
Describe("Process", func() {
It("gets the current process user name", func() {
proc := sigar.ProcState{}
err := proc.Get(os.Getpid())
user, usererr := user.Current()
Ω(err).ShouldNot(HaveOccurred())
Ω(usererr).ShouldNot(HaveOccurred())
Ω(proc.Username).Should(Equal(user.Username))
})
})
})
func TestProcArgs(t *testing.T) {
args := sigar.ProcArgs{}
err := args.Get(os.Getpid())
if err != nil {
t.Fatal(err)
}
if len(args.List) == 0 {
t.Fatalf("Expected at least one arg")
}
}
func TestProcArgsUnknown(t *testing.T) {
args := sigar.ProcArgs{}
err := args.Get(math.MaxInt32)
if err == nil {
t.Fatal("Expected process not found")
}
if !strings.Contains(err.Error(), "Process not found") {
t.Fatal("Expected error containing 'Process not found'")
}
}