@@ -79,8 +79,8 @@ func TestSafeFormatAndMount(t *testing.T) {
79
79
description : "Test a normal mount of an already formatted device" ,
80
80
fstype : "ext4" ,
81
81
execScripts : []ExecArgs {
82
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
83
82
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "DEVNAME=/dev/foo\n TYPE=ext4\n " , nil },
83
+ {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
84
84
},
85
85
},
86
86
{
@@ -96,7 +96,6 @@ func TestSafeFormatAndMount(t *testing.T) {
96
96
description : "Test a normal mount of unformatted device" ,
97
97
fstype : "ext4" ,
98
98
execScripts : []ExecArgs {
99
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
100
99
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 2 }},
101
100
{"mkfs.ext4" , []string {"-F" , "-m0" , "/dev/foo" }, "" , nil },
102
101
},
@@ -105,34 +104,34 @@ func TestSafeFormatAndMount(t *testing.T) {
105
104
description : "Test 'fsck' fails with exit status 4" ,
106
105
fstype : "ext4" ,
107
106
execScripts : []ExecArgs {
108
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 4 }},
109
107
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "DEVNAME=/dev/foo\n TYPE=ext4\n " , nil },
108
+ {"fsck" , []string {"-a" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 4 }},
110
109
},
111
110
expectedError : fmt .Errorf ("'fsck' found errors on device /dev/foo but could not correct them" ),
112
111
},
113
112
{
114
113
description : "Test 'fsck' fails with exit status 1 (errors found and corrected)" ,
115
114
fstype : "ext4" ,
116
115
execScripts : []ExecArgs {
117
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 1 }},
118
116
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "DEVNAME=/dev/foo\n TYPE=ext4\n " , nil },
117
+ {"fsck" , []string {"-a" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 1 }},
119
118
},
120
119
},
121
120
{
122
121
description : "Test 'fsck' fails with exit status other than 1 and 4 (likely unformatted device)" ,
123
122
fstype : "ext4" ,
124
123
execScripts : []ExecArgs {
125
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 8 }},
126
124
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "DEVNAME=/dev/foo\n TYPE=ext4\n " , nil },
125
+ {"fsck" , []string {"-a" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 8 }},
127
126
},
128
127
},
129
128
{
130
129
description : "Test that 'blkid' is called and fails" ,
131
130
fstype : "ext4" ,
132
131
mountErrs : []error {fmt .Errorf ("unknown filesystem type '(null)'" )},
133
132
execScripts : []ExecArgs {
134
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
135
133
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "DEVNAME=/dev/foo\n PTTYPE=dos\n " , nil },
134
+ {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
136
135
},
137
136
expectedError : fmt .Errorf ("unknown filesystem type '(null)'" ),
138
137
},
@@ -141,7 +140,6 @@ func TestSafeFormatAndMount(t *testing.T) {
141
140
fstype : "ext4" ,
142
141
mountErrs : []error {fmt .Errorf ("unknown filesystem type '(null)'" )},
143
142
execScripts : []ExecArgs {
144
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
145
143
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 2 }},
146
144
{"mkfs.ext4" , []string {"-F" , "-m0" , "/dev/foo" }, "" , fmt .Errorf ("formatting failed" )},
147
145
},
@@ -152,7 +150,6 @@ func TestSafeFormatAndMount(t *testing.T) {
152
150
fstype : "ext4" ,
153
151
mountErrs : []error {fmt .Errorf ("unknown filesystem type '(null)'" )},
154
152
execScripts : []ExecArgs {
155
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
156
153
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 2 }},
157
154
{"mkfs.ext4" , []string {"-F" , "-m0" , "/dev/foo" }, "" , nil },
158
155
},
@@ -162,7 +159,6 @@ func TestSafeFormatAndMount(t *testing.T) {
162
159
description : "Test that 'blkid' is called and confirms unformatted disk, format passes, mount passes" ,
163
160
fstype : "ext4" ,
164
161
execScripts : []ExecArgs {
165
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
166
162
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 2 }},
167
163
{"mkfs.ext4" , []string {"-F" , "-m0" , "/dev/foo" }, "" , nil },
168
164
},
@@ -172,7 +168,6 @@ func TestSafeFormatAndMount(t *testing.T) {
172
168
description : "Test that 'blkid' is called and confirms unformatted disk, format passes, mount passes with ext3" ,
173
169
fstype : "ext3" ,
174
170
execScripts : []ExecArgs {
175
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
176
171
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 2 }},
177
172
{"mkfs.ext3" , []string {"-F" , "-m0" , "/dev/foo" }, "" , nil },
178
173
},
@@ -182,7 +177,6 @@ func TestSafeFormatAndMount(t *testing.T) {
182
177
description : "test that none ext4 fs does not get called with ext4 options." ,
183
178
fstype : "xfs" ,
184
179
execScripts : []ExecArgs {
185
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
186
180
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 2 }},
187
181
{"mkfs.xfs" , []string {"/dev/foo" }, "" , nil },
188
182
},
@@ -192,21 +186,60 @@ func TestSafeFormatAndMount(t *testing.T) {
192
186
description : "Test that 'blkid' is called and reports ext4 partition" ,
193
187
fstype : "ext4" ,
194
188
execScripts : []ExecArgs {
195
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
196
189
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "DEVNAME=/dev/foo\n TYPE=ext4\n " , nil },
190
+ {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
197
191
},
198
192
},
199
193
{
200
194
description : "Test that 'blkid' is called but has some usage or other errors (an exit code of 4 is returned)" ,
201
195
fstype : "xfs" ,
202
196
mountErrs : []error {fmt .Errorf ("unknown filesystem type '(null)'" ), nil },
203
197
execScripts : []ExecArgs {
204
- {"fsck" , []string {"-a" , "/dev/foo" }, "" , nil },
205
198
{"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 4 }},
206
199
{"mkfs.xfs" , []string {"/dev/foo" }, "" , nil },
207
200
},
208
201
expectedError : fmt .Errorf ("exit 4" ),
209
202
},
203
+ {
204
+ description : "Test that 'xfs_repair' is called only once, no need to repair the filesystem" ,
205
+ fstype : "xfs" ,
206
+ execScripts : []ExecArgs {
207
+ {"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "DEVNAME=/dev/foo\n TYPE=xfs\n " , nil },
208
+ {"xfs_repair" , []string {"-n" , "/dev/foo" }, "" , nil },
209
+ },
210
+ expectedError : nil ,
211
+ },
212
+ {
213
+ description : "Test that 'xfs_repair' is called twice and repair the filesystem" ,
214
+ fstype : "xfs" ,
215
+ execScripts : []ExecArgs {
216
+ {"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "DEVNAME=/dev/foo\n TYPE=xfs\n " , nil },
217
+ {"xfs_repair" , []string {"-n" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 1 }},
218
+ {"xfs_repair" , []string {"/dev/foo" }, "\n done\n " , nil },
219
+ },
220
+ expectedError : nil ,
221
+ },
222
+ {
223
+ description : "Test that 'xfs_repair' is called twice and repair the filesystem, but mount failed" ,
224
+ fstype : "xfs" ,
225
+ mountErrs : []error {fmt .Errorf ("unknown filesystem type '(null)'" )},
226
+ execScripts : []ExecArgs {
227
+ {"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "DEVNAME=/dev/foo\n TYPE=xfs\n " , nil },
228
+ {"xfs_repair" , []string {"-n" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 1 }},
229
+ {"xfs_repair" , []string {"/dev/foo" }, "\n done\n " , nil },
230
+ },
231
+ expectedError : fmt .Errorf ("unknown filesystem type '(null)'" ),
232
+ },
233
+ {
234
+ description : "Test that 'xfs_repair' is called twice but could not repair the filesystem" ,
235
+ fstype : "xfs" ,
236
+ execScripts : []ExecArgs {
237
+ {"blkid" , []string {"-p" , "-s" , "TYPE" , "-s" , "PTTYPE" , "-o" , "export" , "/dev/foo" }, "DEVNAME=/dev/foo\n TYPE=xfs\n " , nil },
238
+ {"xfs_repair" , []string {"-n" , "/dev/foo" }, "" , & testingexec.FakeExitError {Status : 1 }},
239
+ {"xfs_repair" , []string {"/dev/foo" }, "\n An error occurred\n " , & testingexec.FakeExitError {Status : 1 }},
240
+ },
241
+ expectedError : fmt .Errorf ("'xfs_repair' found errors on device %s but could not correct them: %v" , "/dev/foo" , "\n An error occurred\n " ),
242
+ },
210
243
}
211
244
212
245
for _ , test := range tests {
0 commit comments