6
6
"io"
7
7
"io/ioutil"
8
8
"os"
9
+ "path/filepath"
9
10
"strings"
10
11
"testing"
11
12
@@ -23,6 +24,7 @@ func (s *FilesystemSuite) TestCreate(c *C) {
23
24
f , err := s .FS .Create ("foo" )
24
25
c .Assert (err , IsNil )
25
26
c .Assert (f .Filename (), Equals , "foo" )
27
+ c .Assert (f .Close (), IsNil )
26
28
}
27
29
28
30
func (s * FilesystemSuite ) TestOpen (c * C ) {
@@ -34,6 +36,7 @@ func (s *FilesystemSuite) TestOpen(c *C) {
34
36
f , err = s .FS .Open ("foo" )
35
37
c .Assert (err , IsNil )
36
38
c .Assert (f .Filename (), Equals , "foo" )
39
+ c .Assert (f .Close (), IsNil )
37
40
}
38
41
39
42
func (s * FilesystemSuite ) TestOpenNotExists (c * C ) {
@@ -54,13 +57,15 @@ func (s *FilesystemSuite) TestCreateDir(c *C) {
54
57
func (s * FilesystemSuite ) TestCreateDepth (c * C ) {
55
58
f , err := s .FS .Create ("bar/foo" )
56
59
c .Assert (err , IsNil )
57
- c .Assert (f .Filename (), Equals , "bar/foo" )
60
+ c .Assert (f .Filename (), Equals , s .FS .Join ("bar" , "foo" ))
61
+ c .Assert (f .Close (), IsNil )
58
62
}
59
63
60
64
func (s * FilesystemSuite ) TestCreateDepthAbsolute (c * C ) {
61
65
f , err := s .FS .Create ("/bar/foo" )
62
66
c .Assert (err , IsNil )
63
- c .Assert (f .Filename (), Equals , "bar/foo" )
67
+ c .Assert (f .Filename (), Equals , s .FS .Join ("bar" , "foo" ))
68
+ c .Assert (f .Close (), IsNil )
64
69
}
65
70
66
71
func (s * FilesystemSuite ) TestCreateOverwrite (c * C ) {
@@ -82,6 +87,7 @@ func (s *FilesystemSuite) TestCreateOverwrite(c *C) {
82
87
wrote , err := ioutil .ReadAll (f )
83
88
c .Assert (err , IsNil )
84
89
c .Assert (string (wrote ), DeepEquals , "foo2" )
90
+ c .Assert (f .Close (), IsNil )
85
91
}
86
92
87
93
func (s * FilesystemSuite ) TestCreateClose (c * C ) {
@@ -199,13 +205,13 @@ func (s *FilesystemSuite) TestOpenFileReadWrite(c *C) {
199
205
}
200
206
201
207
func (s * FilesystemSuite ) TestOpenFileWithModes (c * C ) {
202
- f , err := s .FS .OpenFile ("foo" , os .O_CREATE | os .O_WRONLY | os .O_TRUNC , 0755 )
208
+ f , err := s .FS .OpenFile ("foo" , os .O_CREATE | os .O_WRONLY | os .O_TRUNC , customMode )
203
209
c .Assert (err , IsNil )
204
210
c .Assert (f .Close (), IsNil )
205
211
206
212
fi , err := s .FS .Stat ("foo" )
207
213
c .Assert (err , IsNil )
208
- c .Assert (fi .Mode (), Equals , os .FileMode (0755 ))
214
+ c .Assert (fi .Mode (), Equals , os .FileMode (customMode ))
209
215
}
210
216
211
217
func (s * FilesystemSuite ) testWriteClose (c * C , f File , content string ) {
@@ -281,6 +287,8 @@ func (s *FilesystemSuite) TestFileNonRead(c *C) {
281
287
282
288
_ , err = ioutil .ReadAll (f )
283
289
c .Assert (err , NotNil )
290
+
291
+ c .Assert (f .Close (), IsNil )
284
292
}
285
293
286
294
func (s * FilesystemSuite ) TestFileSeekstart (c * C ) {
@@ -478,11 +486,14 @@ func (s *FilesystemSuite) TestDirStat(c *C) {
478
486
}
479
487
480
488
func (s * FilesystemSuite ) TestCreateInDir (c * C ) {
481
- dir := s .FS .Dir ("foo" )
482
- f , err := dir .Create ("bar" )
489
+ f , err := s .FS .Dir ("foo" ).Create ("bar" )
483
490
c .Assert (err , IsNil )
484
491
c .Assert (f .Close (), IsNil )
485
492
c .Assert (f .Filename (), Equals , "bar" )
493
+
494
+ f , err = s .FS .Open ("foo/bar" )
495
+ c .Assert (f .Filename (), Equals , s .FS .Join ("foo" , "bar" ))
496
+ c .Assert (f .Close (), IsNil )
486
497
}
487
498
488
499
func (s * FilesystemSuite ) TestRename (c * C ) {
@@ -531,19 +542,24 @@ func (s *FilesystemSuite) TestRenameDir(c *C) {
531
542
func (s * FilesystemSuite ) TestTempFile (c * C ) {
532
543
f , err := s .FS .TempFile ("" , "bar" )
533
544
c .Assert (err , IsNil )
545
+ c .Assert (f .Close (), IsNil )
534
546
535
547
c .Assert (strings .HasPrefix (f .Filename (), "bar" ), Equals , true )
536
548
}
537
549
538
550
func (s * FilesystemSuite ) TestTempFileWithPath (c * C ) {
539
551
f , err := s .FS .TempFile ("foo" , "bar" )
540
552
c .Assert (err , IsNil )
553
+ c .Assert (f .Close (), IsNil )
554
+
541
555
c .Assert (strings .HasPrefix (f .Filename (), s .FS .Join ("foo" , "bar" )), Equals , true )
542
556
}
543
557
544
558
func (s * FilesystemSuite ) TestTempFileFullWithPath (c * C ) {
545
559
f , err := s .FS .TempFile ("/foo" , "bar" )
546
560
c .Assert (err , IsNil )
561
+ c .Assert (f .Close (), IsNil )
562
+
547
563
c .Assert (strings .HasPrefix (f .Filename (), s .FS .Join ("foo" , "bar" )), Equals , true )
548
564
}
549
565
@@ -558,6 +574,8 @@ func (s *FilesystemSuite) TestOpenAndWrite(c *C) {
558
574
n , err := foo .Write ([]byte ("foo" ))
559
575
c .Assert (err , NotNil )
560
576
c .Assert (n , Equals , 0 )
577
+
578
+ c .Assert (foo .Close (), IsNil )
561
579
}
562
580
563
581
func (s * FilesystemSuite ) TestOpenAndStat (c * C ) {
@@ -568,6 +586,7 @@ func (s *FilesystemSuite) TestOpenAndStat(c *C) {
568
586
c .Assert (foo , NotNil )
569
587
c .Assert (foo .Filename (), Equals , "foo" )
570
588
c .Assert (err , IsNil )
589
+ c .Assert (foo .Close (), IsNil )
571
590
572
591
stat , err := s .FS .Stat ("foo" )
573
592
c .Assert (stat , NotNil )
@@ -611,7 +630,7 @@ func (s *FilesystemSuite) TestRemoveTempFile(c *C) {
611
630
}
612
631
613
632
func (s * FilesystemSuite ) TestJoin (c * C ) {
614
- c .Assert (s .FS .Join ("foo" , "bar" ), Equals , "foo/bar" )
633
+ c .Assert (s .FS .Join ("foo" , "bar" ), Equals , fmt . Sprintf ( "foo%cbar" , filepath . Separator ) )
615
634
}
616
635
617
636
func (s * FilesystemSuite ) TestBase (c * C ) {
@@ -663,14 +682,14 @@ func (s *FilesystemSuite) TestReadWriteLargeFile(c *C) {
663
682
c .Assert (err , IsNil )
664
683
c .Assert (n , Equals , size )
665
684
666
- err = f .Close ()
667
- c .Assert (err , IsNil )
685
+ c .Assert (f .Close (), IsNil )
668
686
669
687
f , err = s .FS .Open ("foo" )
670
688
c .Assert (err , IsNil )
671
689
b , err := ioutil .ReadAll (f )
672
690
c .Assert (err , IsNil )
673
691
c .Assert (len (b ), Equals , size )
692
+ c .Assert (f .Close (), IsNil )
674
693
}
675
694
676
695
func (s * FilesystemSuite ) TestRemoveAllNonExistent (c * C ) {
@@ -806,4 +825,6 @@ func (s *FilesystemSuite) TestWriteFile(c *C) {
806
825
wrote , err := ioutil .ReadAll (f )
807
826
c .Assert (err , IsNil )
808
827
c .Assert (string (wrote ), DeepEquals , "bar" )
828
+
829
+ c .Assert (f .Close (), IsNil )
809
830
}
0 commit comments