This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ type Filesystem interface {
22
22
ReadDir (path string ) ([]FileInfo , error )
23
23
TempFile (dir , prefix string ) (File , error )
24
24
Rename (from , to string ) error
25
+ Remove (filename string ) error
25
26
Join (elem ... string ) string
26
27
Dir (path string ) Filesystem
27
28
Base () string
Original file line number Diff line number Diff line change @@ -100,6 +100,11 @@ func (fs *OS) Stat(filename string) (FileInfo, error) {
100
100
return os .Stat (fullpath )
101
101
}
102
102
103
+ func (fs * OS ) Remove (filename string ) error {
104
+ fullpath := fs .Join (fs .base , filename )
105
+ return os .Remove (fullpath )
106
+ }
107
+
103
108
func (fs * OS ) TempFile (dir , prefix string ) (File , error ) {
104
109
fullpath := fs .Join (fs .base , dir )
105
110
if err := fs .createDir (fullpath + string (os .PathSeparator )); err != nil {
Original file line number Diff line number Diff line change @@ -149,6 +149,28 @@ func (s *FilesystemSuite) TestOpenAndStat(c *C) {
149
149
c .Assert (stat .Name (), Equals , "foo" )
150
150
}
151
151
152
+ func (s * FilesystemSuite ) TestRemove (c * C ) {
153
+ f , err := s .Fs .Create ("foo" )
154
+ c .Assert (err , IsNil )
155
+ c .Assert (f .Close (), IsNil )
156
+
157
+ err = s .Fs .Remove ("foo" )
158
+ c .Assert (err , IsNil )
159
+ }
160
+
161
+ func (s * FilesystemSuite ) TestRemoveNonExisting (c * C ) {
162
+ c .Assert (s .Fs .Remove ("NON-EXISTING" ), NotNil )
163
+ }
164
+
165
+ func (s * FilesystemSuite ) TestRemoveTempFile (c * C ) {
166
+ f , err := s .Fs .TempFile ("test-dir" , "test-prefix" )
167
+ fn := f .Filename ()
168
+ c .Assert (err , IsNil )
169
+ c .Assert (f .Close (), IsNil )
170
+
171
+ c .Assert (s .Fs .Remove (fn ), IsNil )
172
+ }
173
+
152
174
func (s * FilesystemSuite ) TestJoin (c * C ) {
153
175
c .Assert (s .Fs .Join ("foo" , "bar" ), Equals , "foo/bar" )
154
176
}
You can’t perform that action at this time.
0 commit comments