@@ -215,16 +215,10 @@ func (s *FilesystemSuite) TestFileCreateReadSeek(c *C) {
215
215
}
216
216
217
217
func (s * FilesystemSuite ) TestFileOpenReadSeek (c * C ) {
218
- f , err := s .FS .Create ("foo" )
219
- c .Assert (err , IsNil )
220
-
221
- n , err := f .Write ([]byte ("0123456789abcdefghijklmnopqrstuvwxyz" ))
218
+ err := WriteFile (s .FS , "foo" , []byte ("0123456789abcdefghijklmnopqrstuvwxyz" ), 0644 )
222
219
c .Assert (err , IsNil )
223
- c .Assert (n , Equals , 36 )
224
-
225
- c .Assert (f .Close (), IsNil )
226
220
227
- f , err = s .FS .Open ("foo" )
221
+ f , err : = s .FS .Open ("foo" )
228
222
c .Assert (err , IsNil )
229
223
230
224
p , err := f .Seek (10 , io .SeekStart )
@@ -248,9 +242,8 @@ func (s *FilesystemSuite) TestFileCloseTwice(c *C) {
248
242
func (s * FilesystemSuite ) TestReadDirAndDir (c * C ) {
249
243
files := []string {"foo" , "bar" , "qux/baz" , "qux/qux" }
250
244
for _ , name := range files {
251
- f , err := s .FS . Create ( name )
245
+ err := WriteFile ( s .FS , name , nil , 0644 )
252
246
c .Assert (err , IsNil )
253
- c .Assert (f .Close (), IsNil )
254
247
}
255
248
256
249
info , err := s .FS .ReadDir ("/" )
@@ -268,12 +261,8 @@ func (s *FilesystemSuite) TestReadDirAndDir(c *C) {
268
261
}
269
262
270
263
func (s * FilesystemSuite ) TestReadDirFileInfo (c * C ) {
271
- f , err := s .FS .Create ("foo" )
272
- c .Assert (err , IsNil )
273
- n , err := f .Write ([]byte {'F' , 'O' , 'O' })
274
- c .Assert (n , Equals , 3 )
264
+ err := WriteFile (s .FS , "foo" , []byte {'F' , 'O' , 'O' }, 0644 )
275
265
c .Assert (err , IsNil )
276
- c .Assert (f .Close (), IsNil )
277
266
278
267
info , err := s .FS .ReadDir ("/" )
279
268
c .Assert (err , IsNil )
@@ -287,12 +276,8 @@ func (s *FilesystemSuite) TestReadDirFileInfo(c *C) {
287
276
func (s * FilesystemSuite ) TestReadDirFileInfoDirs (c * C ) {
288
277
files := []string {"qux/baz/foo" }
289
278
for _ , name := range files {
290
- f , err := s .FS .Create (name )
291
- c .Assert (err , IsNil )
292
- n , err := f .Write ([]byte {'F' , 'O' , 'O' })
293
- c .Assert (n , Equals , 3 )
279
+ err := WriteFile (s .FS , name , []byte {'F' , 'O' , 'O' }, 0644 )
294
280
c .Assert (err , IsNil )
295
- c .Assert (f .Close (), IsNil )
296
281
}
297
282
298
283
info , err := s .FS .ReadDir ("qux" )
@@ -320,9 +305,8 @@ func (s *FilesystemSuite) TestStatNonExistent(c *C) {
320
305
func (s * FilesystemSuite ) TestDirStat (c * C ) {
321
306
files := []string {"foo" , "bar" , "qux/baz" , "qux/qux" }
322
307
for _ , name := range files {
323
- f , err := s .FS . Create ( name )
308
+ err := WriteFile ( s .FS , name , nil , 0644 )
324
309
c .Assert (err , IsNil )
325
- c .Assert (f .Close (), IsNil )
326
310
}
327
311
328
312
// Some implementations detect directories based on a prefix
@@ -358,9 +342,8 @@ func (s *FilesystemSuite) TestCreateInDir(c *C) {
358
342
}
359
343
360
344
func (s * FilesystemSuite ) TestRename (c * C ) {
361
- f , err := s .FS . Create ( "foo" )
345
+ err := WriteFile ( s .FS , "foo" , nil , 0644 )
362
346
c .Assert (err , IsNil )
363
- c .Assert (f .Close (), IsNil )
364
347
365
348
err = s .FS .Rename ("foo" , "bar" )
366
349
c .Assert (err , IsNil )
@@ -394,9 +377,8 @@ func (s *FilesystemSuite) TestTempFileFullWithPath(c *C) {
394
377
}
395
378
396
379
func (s * FilesystemSuite ) TestOpenAndWrite (c * C ) {
397
- f , err := s .FS . Create ( "foo" )
380
+ err := WriteFile ( s .FS , "foo" , nil , 0644 )
398
381
c .Assert (err , IsNil )
399
- c .Assert (f .Close (), IsNil )
400
382
401
383
foo , err := s .FS .Open ("foo" )
402
384
c .Assert (foo , NotNil )
@@ -408,11 +390,8 @@ func (s *FilesystemSuite) TestOpenAndWrite(c *C) {
408
390
}
409
391
410
392
func (s * FilesystemSuite ) TestOpenAndStat (c * C ) {
411
- f , err := s .FS .Create ("foo" )
412
- c .Assert (err , IsNil )
413
- _ , err = f .Write ([]byte ("foo" ))
393
+ err := WriteFile (s .FS , "foo" , []byte ("foo" ), 0644 )
414
394
c .Assert (err , IsNil )
415
- c .Assert (f .Close (), IsNil )
416
395
417
396
foo , err := s .FS .Open ("foo" )
418
397
c .Assert (foo , NotNil )
@@ -442,11 +421,10 @@ func (s *FilesystemSuite) TestRemoveNonExisting(c *C) {
442
421
}
443
422
444
423
func (s * FilesystemSuite ) TestRemoveNotEmptyDir (c * C ) {
445
- f , err := s .FS . Create ( "foo/bar" )
424
+ err := WriteFile ( s .FS , "foo" , nil , 0644 )
446
425
c .Assert (err , IsNil )
447
- c .Assert (f .Close (), IsNil )
448
426
449
- err = s .FS .Remove ("foo " )
427
+ err = s .FS .Remove ("no-exists " )
450
428
c .Assert (err , NotNil )
451
429
}
452
430
@@ -474,8 +452,10 @@ func (s *FilesystemSuite) TestReadAtOnReadWrite(c *C) {
474
452
c .Assert (err , IsNil )
475
453
_ , err = f .Write ([]byte ("abcdefg" ))
476
454
c .Assert (err , IsNil )
455
+
477
456
rf , ok := f .(io.ReaderAt )
478
457
c .Assert (ok , Equals , true )
458
+
479
459
b := make ([]byte , 3 )
480
460
n , err := rf .ReadAt (b , 2 )
481
461
c .Assert (err , IsNil )
@@ -485,16 +465,15 @@ func (s *FilesystemSuite) TestReadAtOnReadWrite(c *C) {
485
465
}
486
466
487
467
func (s * FilesystemSuite ) TestReadAtOnReadOnly (c * C ) {
488
- f , err := s .FS .Create ("foo" )
489
- c .Assert (err , IsNil )
490
- _ , err = f .Write ([]byte ("abcdefg" ))
468
+ err := WriteFile (s .FS , "foo" , []byte ("abcdefg" ), 0644 )
491
469
c .Assert (err , IsNil )
492
- c .Assert (f .Close (), IsNil )
493
470
494
- f , err = s .FS .Open ("foo" )
471
+ f , err : = s .FS .Open ("foo" )
495
472
c .Assert (err , IsNil )
473
+
496
474
rf , ok := f .(io.ReaderAt )
497
475
c .Assert (ok , Equals , true )
476
+
498
477
b := make ([]byte , 3 )
499
478
n , err := rf .ReadAt (b , 2 )
500
479
c .Assert (err , IsNil )
@@ -548,9 +527,8 @@ func (s *FilesystemSuite) TestRemoveAll(c *C) {
548
527
}
549
528
550
529
for _ , fname := range fnames {
551
- f , err := s .FS . Create ( fname )
530
+ err := WriteFile ( s .FS , fname , nil , 0644 )
552
531
c .Assert (err , IsNil )
553
- c .Assert (f .Close (), IsNil )
554
532
}
555
533
556
534
c .Assert (RemoveAll (s .FS , "foo" ), IsNil )
@@ -575,9 +553,8 @@ func (s *FilesystemSuite) TestRemoveAllRelative(c *C) {
575
553
}
576
554
577
555
for _ , fname := range fnames {
578
- f , err := s .FS . Create ( fname )
556
+ err := WriteFile ( s .FS , fname , nil , 0644 )
579
557
c .Assert (err , IsNil )
580
- c .Assert (f .Close (), IsNil )
581
558
}
582
559
583
560
c .Assert (RemoveAll (s .FS , "foo/bar/.." ), IsNil )
@@ -592,6 +569,7 @@ func (s *FilesystemSuite) TestRemoveAllRelative(c *C) {
592
569
func (s * FilesystemSuite ) TestMkdirAll (c * C ) {
593
570
err := s .FS .MkdirAll ("empty" , os .FileMode (0755 ))
594
571
c .Assert (err , IsNil )
572
+
595
573
fi , err := s .FS .Stat ("empty" )
596
574
c .Assert (err , IsNil )
597
575
c .Assert (fi .IsDir (), Equals , true )
@@ -600,6 +578,7 @@ func (s *FilesystemSuite) TestMkdirAll(c *C) {
600
578
func (s * FilesystemSuite ) TestMkdirAllNested (c * C ) {
601
579
err := s .FS .MkdirAll ("foo/bar/baz" , os .FileMode (0755 ))
602
580
c .Assert (err , IsNil )
581
+
603
582
fi , err := s .FS .Stat ("foo/bar/baz" )
604
583
c .Assert (err , IsNil )
605
584
c .Assert (fi .IsDir (), Equals , true )
@@ -645,3 +624,15 @@ func (s *FilesystemSuite) TestMkdirAllWithExistingFile(c *C) {
645
624
c .Assert (err , IsNil )
646
625
c .Assert (fi .IsDir (), Equals , false )
647
626
}
627
+
628
+ func (s * FilesystemSuite ) TestWriteFile (c * C ) {
629
+ err := WriteFile (s .FS , "foo" , []byte ("bar" ), 0777 )
630
+ c .Assert (err , IsNil )
631
+
632
+ f , err := s .FS .Open ("foo" )
633
+ c .Assert (err , IsNil )
634
+
635
+ wrote , err := ioutil .ReadAll (f )
636
+ c .Assert (err , IsNil )
637
+ c .Assert (string (wrote ), DeepEquals , "bar" )
638
+ }
0 commit comments