@@ -3,20 +3,20 @@ package winfsinjector_test
3
3
import (
4
4
"errors"
5
5
"fmt"
6
+ "io/ioutil"
7
+ "os"
8
+ "path/filepath"
9
+
6
10
. "github.com/onsi/ginkgo"
7
11
. "github.com/onsi/gomega"
8
12
"github.com/pivotal-cf/winfs-injector/winfsinjector"
9
13
"github.com/pivotal-cf/winfs-injector/winfsinjector/fakes"
10
- "io/ioutil"
11
- "os"
12
- "path/filepath"
13
14
)
14
15
15
16
var _ = Describe ("application" , func () {
16
17
Describe ("Run" , func () {
17
18
var (
18
19
fakeReleaseCreator * fakes.ReleaseCreator
19
- fakeEmbeddedDirectory * fakes.FileInfo
20
20
fakeInjector * fakes.Injector
21
21
fakeZipper * fakes.Zipper
22
22
@@ -39,7 +39,7 @@ var _ = Describe("application", func() {
39
39
outputTile = "/path/to/output/tile"
40
40
registry = "/path/to/docker/registry"
41
41
42
- workingDir , err = ioutil .TempDir ("" ,"" )
42
+ workingDir , err = ioutil .TempDir ("" , "" )
43
43
Expect (err ).ToNot (HaveOccurred ())
44
44
45
45
embedFilePath := fmt .Sprintf ("%s/extracted-tile/embed" , workingDir )
@@ -66,23 +66,15 @@ windows2019fs/windows2016fs-2019.0.43.tgz:
66
66
}
67
67
})
68
68
69
- fakeEmbeddedDirectory = new (fakes.FileInfo )
70
- fakeEmbeddedDirectory .IsDirReturns (true )
71
- fakeEmbeddedDirectory .NameReturns ("windowsfs-release" )
72
-
73
- winfsinjector .SetReadDir (func (string ) ([]os.FileInfo , error ) {
74
- return []os.FileInfo {
75
- fakeEmbeddedDirectory ,
76
- }, nil
77
- })
69
+ err = os .MkdirAll (embedFilePath + "/windowsfs-release" , os .ModePerm )
70
+ Expect (err ).ToNot (HaveOccurred ())
78
71
79
72
app = winfsinjector .NewApplication (fakeReleaseCreator , fakeInjector , fakeZipper )
80
73
})
81
74
82
75
AfterEach (func () {
83
76
winfsinjector .ResetReadFile ()
84
77
winfsinjector .ResetRemoveAll ()
85
- winfsinjector .ResetReadDir ()
86
78
})
87
79
88
80
It ("unzips the tile" , func () {
@@ -93,7 +85,7 @@ windows2019fs/windows2016fs-2019.0.43.tgz:
93
85
94
86
inputTile , extractedTileDir := fakeZipper .UnzipArgsForCall (0 )
95
87
Expect (inputTile ).To (Equal (filepath .Join ("/" , "path" , "to" , "input" , "tile" )))
96
- Expect (extractedTileDir ).To (Equal (fmt .Sprintf ("%s%s" , workingDir ,filepath .Join ("/" , "extracted-tile" ))))
88
+ Expect (extractedTileDir ).To (Equal (fmt .Sprintf ("%s%s" , workingDir , filepath .Join ("/" , "extracted-tile" ))))
97
89
})
98
90
99
91
It ("creates the release" , func () {
@@ -143,7 +135,7 @@ windows2019fs/windows2016fs-2019.0.43.tgz:
143
135
Expect (err ).NotTo (HaveOccurred ())
144
136
145
137
Expect (removeAllCallCount ).To (Equal (1 ))
146
- Expect (removeAllPath ).To (Equal (fmt .Sprintf ("%s%s" , workingDir ,filepath .Join ("/" , "extracted-tile" , "embed" , "windowsfs-release" ))))
138
+ Expect (removeAllPath ).To (Equal (fmt .Sprintf ("%s%s" , workingDir , filepath .Join ("/" , "extracted-tile" , "embed" , "windowsfs-release" ))))
147
139
})
148
140
149
141
It ("zips up the injected tile dir" , func () {
@@ -212,73 +204,42 @@ windows2019fs/windows2016fs-MISSING-IMAGE-TAG.tgz:
212
204
})
213
205
})
214
206
215
- Context ("when the embed directory is not a directory " , func () {
207
+ Context ("when there is multiple directories embedded in the tile " , func () {
216
208
BeforeEach (func () {
217
- fakeEmbeddedDirectory = new (fakes. FileInfo )
218
- fakeEmbeddedDirectory . IsDirReturns ( false )
219
- fakeEmbeddedDirectory . NameReturns ( "not a directory" )
209
+ embedFilePath := fmt . Sprintf ( "%s/extracted-tile/embed" , workingDir )
210
+ err = os . MkdirAll ( embedFilePath + "/this-is-another-folder" , os . ModePerm )
211
+ Expect ( err ). ToNot ( HaveOccurred () )
220
212
})
221
213
222
- It ("returns the error " , func () {
214
+ It ("creates a release with the windowsfs-release " , func () {
223
215
err := app .Run (inputTile , outputTile , registry , workingDir )
224
- Expect (err ).To (HaveOccurred ())
225
- Expect (err ).To (MatchError ("the embedded file system is not a directory; please contact the tile authors to fix" ))
226
- })
227
- })
216
+ Expect (err ).ToNot (HaveOccurred ())
228
217
229
- Context ("when more than one file system is embedded in the tile" , func () {
230
- BeforeEach (func () {
231
- winfsinjector .SetReadDir (func (string ) ([]os.FileInfo , error ) {
232
- return []os.FileInfo {
233
- fakeEmbeddedDirectory ,
234
- fakeEmbeddedDirectory ,
235
- }, nil
236
- })
237
- })
218
+ Expect (fakeReleaseCreator .CreateReleaseCallCount ()).To (Equal (1 ))
238
219
239
- It ("returns the error" , func () {
240
- err := app .Run (inputTile , outputTile , registry , workingDir )
241
- Expect (err ).To (HaveOccurred ())
242
- Expect (err ).To (MatchError ("there is more than one file system embedded in the tile; please contact the tile authors to fix" ))
220
+ releaseName , imageName , releaseDir , tarballPath , imageTag , registry , version := fakeReleaseCreator .CreateReleaseArgsForCall (0 )
221
+ Expect (releaseName ).To (Equal ("windows2019fs" ))
222
+ Expect (imageName ).To (Equal ("cloudfoundry/windows2016fs" ))
223
+ Expect (releaseDir ).To (Equal (fmt .Sprintf ("%s/extracted-tile/embed/windowsfs-release" , workingDir )))
224
+ Expect (tarballPath ).To (Equal (fmt .Sprintf ("%s/extracted-tile/releases/windows2019fs-9.3.6.tgz" , workingDir )))
225
+ Expect (imageTag ).To (Equal ("2019.0.43" ))
226
+ Expect (registry ).To (Equal ("/path/to/docker/registry" ))
227
+ Expect (version ).To (Equal ("9.3.6" ))
243
228
})
244
229
})
245
230
246
- Context ("when there are no file systems embedded in the tile" , func () {
231
+ Context ("when windowsfs-release is not embedded in the tile" , func () {
247
232
BeforeEach (func () {
248
- workingDir = "not/a/path/to/ tile"
249
- winfsinjector . SetReadDir ( func ( string ) ([]os. FileInfo , error ) {
250
- return [] os.FileInfo {}, nil
251
- } )
233
+ embedFilePath := fmt . Sprintf ( "%s/extracted- tile/embed" , workingDir )
234
+ os . RemoveAll ( embedFilePath + "/windowsfs-release" )
235
+ err = os .MkdirAll ( embedFilePath + "/this-is-another-folder" , os . ModePerm )
236
+ Expect ( err ). ToNot ( HaveOccurred () )
252
237
})
253
238
254
239
It ("returns the error" , func () {
255
240
err := app .Run (inputTile , outputTile , registry , workingDir )
256
241
Expect (err ).To (HaveOccurred ())
257
- Expect (err ).To (MatchError ("there is no file system embedded in the tile; please contact the tile authors to fix" ))
258
- })
259
- })
260
-
261
- Context ("when the file system has already been injected" , func () {
262
- BeforeEach (func () {
263
- winfsinjector .SetReadDir (func (string ) ([]os.FileInfo , error ) {
264
- return []os.FileInfo {}, nil
265
- })
266
- })
267
-
268
- It ("does not return an error and exits" , func () {
269
- var err error
270
- r , w , _ := os .Pipe ()
271
- tmp := os .Stdout
272
- defer func () {
273
- os .Stdout = tmp
274
- }()
275
- os .Stdout = w
276
- err = app .Run (inputTile , outputTile , registry , workingDir )
277
- w .Close ()
278
-
279
- Expect (err ).ToNot (HaveOccurred ())
280
- stdout , _ := ioutil .ReadAll (r )
281
- Expect (string (stdout )).To (ContainSubstring ("The file system has already been injected in the tile; skipping injection" ))
242
+ Expect (err ).To (MatchError ("the 'windowsfs-release' file system is not embedded in the tile; please contact the tile authors to fix" ))
282
243
})
283
244
})
284
245
0 commit comments