forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_test.go
83 lines (76 loc) · 2.03 KB
/
block_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
73
74
75
76
77
78
79
80
81
82
83
package ghw
import (
"os"
"strings"
"testing"
)
func TestBlock(t *testing.T) {
if _, ok := os.LookupEnv("GHW_TESTING_SKIP_BLOCK"); ok {
t.Skip("Skipping block tests.")
}
info, err := Block()
if err != nil {
t.Fatalf("Expected no error creating BlockInfo, but got %v", err)
}
tpb := info.TotalPhysicalBytes
if tpb < 1 {
t.Fatalf("Expected >0 total physical bytes, got %d", tpb)
}
disks := info.Disks
if len(disks) == 0 {
t.Fatalf("Expected >0 disks. Got %d", len(disks))
}
d0 := disks[0]
if d0.Name == "" {
t.Fatalf("Expected disk name, but got \"\"")
}
if d0.SerialNumber == "unknown" {
t.Fatalf("Got unknown serial number.")
}
if d0.SizeBytes <= 0 {
t.Fatalf("Expected >0 disk size, but got %d", d0.SizeBytes)
}
if d0.Partitions == nil {
t.Fatalf("Expected non-nil partitions, but got nil.")
}
if d0.SectorSizeBytes <= 0 {
t.Fatalf("Expected >0 sector size, but got %d", d0.SectorSizeBytes)
}
if len(d0.Partitions) > 0 {
p0 := d0.Partitions[0]
if p0 == nil {
t.Fatalf("Expected non-nil partition, but got nil.")
}
if !strings.HasPrefix(p0.Name, d0.Name) {
t.Fatalf("Expected partition name to begin with disk name but "+
"got %s does not begin with %s", p0.Name, d0.Name)
}
}
for _, p := range d0.Partitions {
// Check that all the singular functions return the same information as
// the information constructed by ghw.Block()
ps := PartitionSizeBytes(p.Name)
if ps != p.SizeBytes {
t.Fatalf("Expected matching size, but got %d != %d",
ps, p.SizeBytes)
}
pmp := PartitionMountPoint(p.Name)
if pmp != p.MountPoint {
t.Fatalf("Expected matching mountpoints, but got %s != %s",
pmp, p.MountPoint)
}
pt := PartitionType(p.Name)
if pt != p.Type {
t.Fatalf("Expected matching types, but got %s != %s",
pt, p.Type)
}
pro := PartitionIsReadOnly(p.Name)
if pro != p.IsReadOnly {
t.Fatalf("Expected matching readonly, but got %v != %v",
pro, p.IsReadOnly)
}
if p.Disk != d0 {
t.Fatalf("Expected disk to be the same as d0 but got %v", p.Disk)
}
}
}