forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_test.go
75 lines (64 loc) · 1.68 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
//
// Use and distribution licensed under the Apache license version 2.
//
// See the COPYING file in the root project directory for full text.
//
package ghw
import (
"os"
"strings"
"testing"
)
// nolint: gocyclo
func TestBlock(t *testing.T) {
if _, ok := os.LookupEnv("GHW_TESTING_SKIP_BLOCK"); ok {
t.Skip("Skipping block tests.")
}
ctx := contextFromEnv()
info := &BlockInfo{}
if err := ctx.blockFillInfo(info); 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.PhysicalBlockSizeBytes <= 0 {
t.Fatalf("Expected >0 sector size, but got %d", d0.PhysicalBlockSizeBytes)
}
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 {
if p.SizeBytes <= 0 {
t.Fatalf("Expected >0 partition size, but got %d", p.SizeBytes)
}
if p.Disk != d0 {
t.Fatalf("Expected disk to be the same as d0 but got %v", p.Disk)
}
}
}