forked from project-machine/disko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlvmdump_test.go
103 lines (92 loc) · 2.43 KB
/
lvmdump_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package linux
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
var size1 uint64 = 27514634240
var size2 uint64 = 55029268480
var size3 = size2 * 2
func asBS(b uint64) string {
return fmt.Sprintf("%dB", b)
}
func TestParseLvReport(t *testing.T) {
ast := assert.New(t)
rawStub := map[string]string{"ignore-key": "ignore-val"}
found, err := parseLvReport([]byte(
`{"report": [{"lv": [{
"lv_active": "active",
"lv_full_name": "atx_container/storage",
"lv_name": "storage",
"lv_path": "/dev/atx_container/storage",
"lv_size": "` + asBS(size1) + `",
"lv_uuid": "yY7AfO-dtWE-ROJR-f7G9-d70P-pjGF-lFfXgf",
"vg_name": "atx_container",
"pool_lv": ""
}]}]}`))
found[0].raw = rawStub
ast.Equal(nil, err)
ast.Equal(
[]lvmLVData{
{
Name: "storage",
VGName: "atx_container",
Path: "/dev/atx_container/storage",
Size: size1,
UUID: "yY7AfO-dtWE-ROJR-f7G9-d70P-pjGF-lFfXgf",
Active: true,
Pool: "",
raw: rawStub,
}}, found)
}
func TestParseVgReport(t *testing.T) {
ast := assert.New(t)
rawStub := map[string]string{"ignore-key": "ignore-val"}
found, err := parseVgReport([]byte(
`{"report": [{"vg": [{
"lv_count": "1",
"pv_count": "1",
"vg_free": "0B",
"vg_name": "atx_container",
"vg_size": "` + asBS(size2) + `",
"vg_uuid": "pB0WKT-WukN-IAjl-Q1Lr-bLmH-Xh5x-In0V5e"
}]}]}`))
found[0].raw = rawStub
ast.Equal(nil, err)
ast.Equal(
[]lvmVGData{
{
Name: "atx_container",
Size: size2,
UUID: "pB0WKT-WukN-IAjl-Q1Lr-bLmH-Xh5x-In0V5e",
Free: 0,
raw: rawStub,
}}, found)
}
func TestParsePvReport(t *testing.T) {
ast := assert.New(t)
rawStub := map[string]string{"ignore-key": "ignore-val"}
found, err := parsePvReport([]byte(
`{"report": [{"pv": [{
"dev_size": "` + asBS(size2) + `",
"pv_free": "` + asBS(size3) + `",
"pv_mda_size": "` + asBS(size1) + `",
"pv_name": "/dev/vda3",
"pv_size": "` + asBS(size2) + `",
"pv_uuid": "Gf0GD0-hH0M-7x8i-9LQt-AAZm-ke5b-VfWlGR",
"vg_name": "vg0"
}]}]}`))
found[0].raw = rawStub
ast.Equal(nil, err)
ast.Equal(
[]lvmPVData{
{
Path: "/dev/vda3",
VGName: "vg0",
Size: size2,
UUID: "Gf0GD0-hH0M-7x8i-9LQt-AAZm-ke5b-VfWlGR",
Free: size3,
MetadataSize: size1,
raw: rawStub,
}}, found)
}