1package iostat
2
3import (
4	"testing"
5)
6
7func TestReadDriveStats(t *testing.T) {
8	a, err := ReadDriveStats()
9	if err != nil {
10		t.Fatal(err)
11	}
12	if len(a) == 0 {
13		t.Errorf("ReadDriveStats() = 0; want >1")
14		return
15	}
16	for _, stat := range a {
17		t.Run(stat.Name, func(t *testing.T) {
18			if stat.Size <= 0 {
19				t.Errorf("Size = %d; want >0", stat.Size)
20			}
21			if stat.BlockSize <= 0 {
22				t.Errorf("BlockSize = %d; want >0", stat.BlockSize)
23			}
24			if stat.BytesRead <= 0 {
25				t.Errorf("BytesRead = %d; want >0", stat.BytesRead)
26			}
27			t.Logf("Size = %d\n", stat.Size)
28			t.Logf("BlockSize = %d\n", stat.BlockSize)
29			t.Logf("BytesRead = %d\n", stat.BytesRead)
30			t.Logf("BytesWritten = %d\n", stat.BytesWritten)
31			t.Logf("NumRead = %d\n", stat.NumRead)
32			t.Logf("NumWrite = %d\n", stat.NumWrite)
33			t.Logf("TotalReadTime = %v\n", stat.TotalReadTime)
34			t.Logf("TotalWriteTime = %v\n", stat.TotalWriteTime)
35			t.Logf("ReadLatency = %v\n", stat.ReadLatency)
36			t.Logf("WriteLatency = %v\n", stat.WriteLatency)
37			t.Logf("ReadErrors = %v\n", stat.ReadErrors)
38			t.Logf("WriteErrors = %v\n", stat.WriteErrors)
39			t.Logf("ReadRetries = %v\n", stat.ReadRetries)
40			t.Logf("WriteRetries = %v\n", stat.WriteRetries)
41		})
42	}
43}
44
45func TestReadCPUStats(t *testing.T) {
46	cpu, err := ReadCPUStats()
47	if err != nil {
48		t.Fatal(err)
49	}
50	if cpu.User == 0 {
51		t.Errorf("User = %d; want >0", cpu.User)
52	}
53	if cpu.Sys == 0 {
54		t.Errorf("Sys = %d; want >0", cpu.Sys)
55	}
56	t.Logf("User = %d\n", cpu.User)
57	t.Logf("Nice = %d\n", cpu.Nice)
58	t.Logf("Sys = %d\n", cpu.Sys)
59	t.Logf("Idle = %d\n", cpu.Idle)
60}
61
62func TestReadLoadAvg(t *testing.T) {
63	load, err := ReadLoadAvg()
64	if err != nil {
65		t.Fatal(err)
66	}
67	if load.Load1 <= 0.0 {
68		t.Errorf("Load1 = %4.2f; want >0", load.Load1)
69	}
70	if load.Load5 <= 0.0 {
71		t.Errorf("Load5 = %4.2f; want >0", load.Load5)
72	}
73	if load.Load15 <= 0.0 {
74		t.Errorf("Load15 = %4.2f; want >0", load.Load15)
75	}
76	t.Logf("Load1 = %4.2f", load.Load1)
77	t.Logf("Load5 = %4.2f", load.Load5)
78	t.Logf("Load15 = %4.2f", load.Load15)
79}
80