-
Notifications
You must be signed in to change notification settings - Fork 1
/
fs_test.go
131 lines (118 loc) · 3.05 KB
/
fs_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)
func TestParseOndatVolumes(t *testing.T) {
tests := []struct {
name string
// example of commands's output
lsOutput string
// list of pointers. Gets updated directly
volumes []*Volume
expectedVolumes []*Volume
expectedErr error
}{
{
name: "success",
lsOutput: `total 262144
-rw-rw---- 1 root disk 2147483648 Feb 25 15:18 d.d613df45-a162-4166-acf2-717a647e1150
brw-rw---- 1 root disk 8, 32 Feb 25 16:07 v.c3561d79-459f-4e5d-b5bb-f71ae7b38672
brw-rw---- 1 root disk 8, 48 Feb 25 15:18 v.78e88095-e690-49be-b0f3-3f735ef084a5
`,
volumes: []*Volume{
{
Master: Master{
VolumeID: "c3561d79-459f-4e5d-b5bb-f71ae7b38672",
},
Labels: Labels{
PVC: "my-pvc",
PVCNamespace: "my-namespace",
},
},
{
Master: Master{
VolumeID: "78e88095-e690-49be-b0f3-3f735ef084a5",
},
Labels: Labels{
PVC: "my-pvc",
PVCNamespace: "my-namespace",
},
},
},
expectedVolumes: []*Volume{
{
Major: 8,
Minor: 32,
Master: Master{
VolumeID: "c3561d79-459f-4e5d-b5bb-f71ae7b38672",
},
Labels: Labels{
PVC: "my-pvc",
PVCNamespace: "my-namespace",
},
},
{
Major: 8,
Minor: 48,
Master: Master{
VolumeID: "78e88095-e690-49be-b0f3-3f735ef084a5",
},
Labels: Labels{
PVC: "my-pvc",
PVCNamespace: "my-namespace",
},
},
},
expectedErr: nil,
},
{
name: "no volumes",
lsOutput: `total 5767168
-rw-rw---- 1 root disk 2147483648 Feb 25 15:18 d.d613df45-a162-4166-acf2-717a647e1150
-rw-rw---- 1 root disk 2147483648 Feb 25 16:07 d.5a1efbf6-2d7a-4f2a-a04e-14fbb4e8894f
-rw-rw---- 1 root disk 10737418240 Feb 25 16:07 d.5fd17ece-93e1-455a-96cf-7150b3eef651
-rw-rw---- 1 root disk 10737418240 Feb 25 16:07 d.804b4a98-4497-48b1-a25f-9312c18c017f
`,
volumes: []*Volume{},
expectedVolumes: []*Volume{},
expectedErr: nil,
},
{
name: "no volumes or deployments",
lsOutput: `total 0
`,
volumes: []*Volume{},
expectedVolumes: []*Volume{},
expectedErr: nil,
},
{
name: "unexpected value in input, invalid minor number",
lsOutput: `total 262144
-rw-rw---- 1 root disk 2147483648 Feb 25 15:18 d.d613df45-a162-4166-acf2-717a647e1150
brw-rw---- 1 root disk 8, ops Feb 25 16:07 v.c3561d79-459f-4e5d-b5bb-f71ae7b38672
`,
volumes: []*Volume{},
expectedVolumes: []*Volume{},
expectedErr: nil,
},
}
for _, tt := range tests {
var tt = tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
loggerConfig := zap.NewProductionConfig()
logger, _ := loggerConfig.Build()
log := logger.Sugar()
err := parseOndatVolumes(log, tt.volumes, strings.Split(tt.lsOutput, "\n"))
if err != nil {
require.EqualError(t, tt.expectedErr, err.Error())
} else {
require.Nil(t, tt.expectedErr)
}
require.EqualValues(t, tt.expectedVolumes, tt.volumes, "unexpected volumes returned")
})
}
}