@@ -3,20 +3,20 @@ package winfsinjector_test
33import (
44 "errors"
55 "fmt"
6+ "io/ioutil"
7+ "os"
8+ "path/filepath"
9+
610 . "github.com/onsi/ginkgo"
711 . "github.com/onsi/gomega"
812 "github.com/pivotal-cf/winfs-injector/winfsinjector"
913 "github.com/pivotal-cf/winfs-injector/winfsinjector/fakes"
10- "io/ioutil"
11- "os"
12- "path/filepath"
1314)
1415
1516var _ = Describe ("application" , func () {
1617 Describe ("Run" , func () {
1718 var (
1819 fakeReleaseCreator * fakes.ReleaseCreator
19- fakeEmbeddedDirectory * fakes.FileInfo
2020 fakeInjector * fakes.Injector
2121 fakeZipper * fakes.Zipper
2222
@@ -39,7 +39,7 @@ var _ = Describe("application", func() {
3939 outputTile = "/path/to/output/tile"
4040 registry = "/path/to/docker/registry"
4141
42- workingDir , err = ioutil .TempDir ("" ,"" )
42+ workingDir , err = ioutil .TempDir ("" , "" )
4343 Expect (err ).ToNot (HaveOccurred ())
4444
4545 embedFilePath := fmt .Sprintf ("%s/extracted-tile/embed" , workingDir )
@@ -66,23 +66,15 @@ windows2019fs/windows2016fs-2019.0.43.tgz:
6666 }
6767 })
6868
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 ())
7871
7972 app = winfsinjector .NewApplication (fakeReleaseCreator , fakeInjector , fakeZipper )
8073 })
8174
8275 AfterEach (func () {
8376 winfsinjector .ResetReadFile ()
8477 winfsinjector .ResetRemoveAll ()
85- winfsinjector .ResetReadDir ()
8678 })
8779
8880 It ("unzips the tile" , func () {
@@ -93,7 +85,7 @@ windows2019fs/windows2016fs-2019.0.43.tgz:
9385
9486 inputTile , extractedTileDir := fakeZipper .UnzipArgsForCall (0 )
9587 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" ))))
9789 })
9890
9991 It ("creates the release" , func () {
@@ -143,7 +135,7 @@ windows2019fs/windows2016fs-2019.0.43.tgz:
143135 Expect (err ).NotTo (HaveOccurred ())
144136
145137 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" ))))
147139 })
148140
149141 It ("zips up the injected tile dir" , func () {
@@ -212,73 +204,42 @@ windows2019fs/windows2016fs-MISSING-IMAGE-TAG.tgz:
212204 })
213205 })
214206
215- Context ("when the embed directory is not a directory " , func () {
207+ Context ("when there is multiple directories embedded in the tile " , func () {
216208 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 () )
220212 })
221213
222- It ("returns the error " , func () {
214+ It ("creates a release with the windowsfs-release " , func () {
223215 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 ())
228217
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 ))
238219
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" ))
243228 })
244229 })
245230
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 () {
247232 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 () )
252237 })
253238
254239 It ("returns the error" , func () {
255240 err := app .Run (inputTile , outputTile , registry , workingDir )
256241 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" ))
282243 })
283244 })
284245
0 commit comments