@@ -41,14 +41,17 @@ var _ = Describe("bake command", func() {
4141 someOtherInstanceGroupsDirectory = "fixtures/instance-groups2"
4242 someJobsDirectory = "fixtures/jobs"
4343 someOtherJobsDirectory = "fixtures/jobs2"
44+ multiStemcellDirectory = "fixtures/multiple-stemcells"
45+ singleStemcellDirectory = "fixtures/single-stemcell"
4446 variableFile = "fixtures/variables-file"
4547 someVarFile = "fixtures/var-dir/var-file.yml"
4648 someAssetsYMLPath = "fixtures/assets.yml"
4749 cfSHA1 = "b383f3177e4fc4f0386b7a06ddbc3f57e7dbf09f"
4850 diegoSHA1 = "ade2a81b4bfda4eb7062cb1a9314f8941ae11d06"
49- stemcellTarball = "fixtures/stemcell.tgz"
5051 metadata = "fixtures/metadata.yml"
5152 metadataWithStemcellCriteria = "fixtures/metadata-with-stemcell-criteria.yml"
53+ metadataWithMultipleStemcells = "fixtures/metadata-with-multiple-stemcells.yml"
54+ metadataWithStemcellTarball = "fixtures/metadata-with-stemcell-tarball.yml"
5255 )
5356
5457 BeforeEach (func () {
@@ -78,7 +81,6 @@ var _ = Describe("bake command", func() {
7881 "--releases-directory" , otherReleasesDirectory ,
7982 "--releases-directory" , someReleasesDirectory ,
8083 "--runtime-configs-directory" , someRuntimeConfigsDirectory ,
81- "--stemcell-tarball" , stemcellTarball ,
8284 "--variable" , "some-variable=some-variable-value" ,
8385 "--variables-file" , someVarFile ,
8486 "--version" , "1.2.3" ,
@@ -90,12 +92,12 @@ var _ = Describe("bake command", func() {
9092 })
9193
9294 It ("generates a tile with the correct metadata" , func () {
93- commandWithArgs = append (commandWithArgs , "--migrations-directory" ,
94- "fixtures/extra-migrations" ,
95- "--migrations-directory" ,
96- "fixtures/migrations" ,
97- "--variables-file" ,
98- variableFile )
95+ commandWithArgs = append (commandWithArgs ,
96+ "--migrations-directory" , " fixtures/extra-migrations" ,
97+ "--migrations-directory" , "fixtures/migrations" ,
98+ "--variables-file" , variableFile ,
99+ "--stemcells-directory" , singleStemcellDirectory ,
100+ )
99101
100102 command := exec .Command (pathToMain , commandWithArgs ... )
101103
@@ -174,7 +176,7 @@ var _ = Describe("bake command", func() {
174176 Expect (string (contents )).To (Equal ("some_migration\n " ))
175177
176178 Eventually (session .Err ).Should (gbytes .Say ("Reading release manifests" ))
177- Eventually (session .Err ).Should (gbytes .Say ("Reading stemcell manifest " ))
179+ Eventually (session .Err ).Should (gbytes .Say ("Reading stemcells from directories " ))
178180 Eventually (session .Err ).Should (gbytes .Say (fmt .Sprintf ("Building %s" , outputFile )))
179181 Eventually (session .Err ).Should (gbytes .Say (fmt .Sprintf ("Adding metadata/metadata.yml to %s..." , outputFile )))
180182 Eventually (session .Err ).Should (gbytes .Say (fmt .Sprintf ("Adding migrations/v1/201603041539_custom_buildpacks.js to %s..." , outputFile )))
@@ -184,9 +186,108 @@ var _ = Describe("bake command", func() {
184186 Eventually (session .Err ).ShouldNot (gbytes .Say (fmt .Sprintf ("Adding releases/not-a-tarball.txt to %s..." , outputFile )))
185187 })
186188
189+ Context ("when multiple stemcells are provided" , func () {
190+ BeforeEach (func () {
191+ commandWithArgs = []string {
192+ "bake" ,
193+ "--releases-directory" , someReleasesDirectory ,
194+ "--icon" , someIconPath ,
195+ "--metadata" , metadataWithMultipleStemcells ,
196+ "--stemcells-directory" , multiStemcellDirectory ,
197+ "--output-file" , outputFile ,
198+ "--version" , "1.2.3" ,
199+ }
200+ })
201+
202+ It ("interpolates metadata file using multiple stemcells" , func () {
203+ command := exec .Command (pathToMain , commandWithArgs ... )
204+
205+ session , err := gexec .Start (command , GinkgoWriter , GinkgoWriter )
206+ Expect (err ).NotTo (HaveOccurred ())
207+
208+ Eventually (session ).Should (gexec .Exit (0 ))
209+
210+ archive , err := os .Open (outputFile )
211+ Expect (err ).NotTo (HaveOccurred ())
212+
213+ archiveInfo , err := archive .Stat ()
214+ Expect (err ).NotTo (HaveOccurred ())
215+
216+ zr , err := zip .NewReader (archive , archiveInfo .Size ())
217+ Expect (err ).NotTo (HaveOccurred ())
218+
219+ var file io.ReadCloser
220+ for _ , f := range zr .File {
221+ if f .Name == "metadata/metadata.yml" {
222+ file , err = f .Open ()
223+ Expect (err ).NotTo (HaveOccurred ())
224+ break
225+ }
226+ }
227+
228+ Expect (file ).NotTo (BeNil (), "metadata was not found in built tile" )
229+ metadataContents , err := ioutil .ReadAll (file )
230+ Expect (err ).NotTo (HaveOccurred ())
231+
232+ renderedYAML := fmt .Sprintf (expectedMetadataWithMultipleStemcells , cfSHA1 )
233+ Expect (metadataContents ).To (HelpfullyMatchYAML (renderedYAML ))
234+ })
235+ })
236+
237+ Context ("when the --stemcell-tarball flag is provided" , func () {
238+ BeforeEach (func () {
239+ commandWithArgs = []string {
240+ "bake" ,
241+ "--releases-directory" , someReleasesDirectory ,
242+ "--icon" , someIconPath ,
243+ "--metadata" , metadataWithStemcellTarball ,
244+ "--stemcell-tarball" , singleStemcellDirectory + "/stemcell.tgz" ,
245+ "--output-file" , outputFile ,
246+ "--version" , "1.2.3" ,
247+ }
248+ })
249+
250+ It ("interpolates metadata file using a single stemcell" , func () {
251+ command := exec .Command (pathToMain , commandWithArgs ... )
252+
253+ session , err := gexec .Start (command , GinkgoWriter , GinkgoWriter )
254+ Expect (err ).NotTo (HaveOccurred ())
255+
256+ Eventually (session ).Should (gexec .Exit (0 ))
257+
258+ archive , err := os .Open (outputFile )
259+ Expect (err ).NotTo (HaveOccurred ())
260+
261+ archiveInfo , err := archive .Stat ()
262+ Expect (err ).NotTo (HaveOccurred ())
263+
264+ zr , err := zip .NewReader (archive , archiveInfo .Size ())
265+ Expect (err ).NotTo (HaveOccurred ())
266+
267+ var file io.ReadCloser
268+ for _ , f := range zr .File {
269+ if f .Name == "metadata/metadata.yml" {
270+ file , err = f .Open ()
271+ Expect (err ).NotTo (HaveOccurred ())
272+ break
273+ }
274+ }
275+
276+ Expect (file ).NotTo (BeNil (), "metadata was not found in built tile" )
277+ metadataContents , err := ioutil .ReadAll (file )
278+ Expect (err ).NotTo (HaveOccurred ())
279+
280+ renderedYAML := fmt .Sprintf (expectedMetadataWithStemcellTarball , cfSHA1 )
281+ Expect (metadataContents ).To (HelpfullyMatchYAML (renderedYAML ))
282+ })
283+ })
284+
187285 Context ("when the --sha256 flag is provided" , func () {
188286 BeforeEach (func () {
189- commandWithArgs = append (commandWithArgs , "--sha256" )
287+ commandWithArgs = append (commandWithArgs ,
288+ "--sha256" ,
289+ "--stemcells-directory" , singleStemcellDirectory ,
290+ )
190291 })
191292
192293 It ("outputs a sha256 checksum of the file to stderr" , func () {
@@ -234,12 +335,11 @@ var _ = Describe("bake command", func() {
234335 "--version" , "1.2.3" ,
235336 "--assets-file" , someAssetsYMLPath ,
236337 }
237- commandWithArgs = append (commandWithArgs , "--migrations-directory" ,
238- "fixtures/extra-migrations" ,
239- "--migrations-directory" ,
240- "fixtures/migrations" ,
241- "--variables-file" ,
242- variableFile )
338+ commandWithArgs = append (commandWithArgs ,
339+ "--migrations-directory" , "fixtures/extra-migrations" ,
340+ "--migrations-directory" , "fixtures/migrations" ,
341+ "--variables-file" , variableFile ,
342+ )
243343
244344 command := exec .Command (pathToMain , commandWithArgs ... )
245345
@@ -364,6 +464,7 @@ var _ = Describe("bake command", func() {
364464 Eventually (session .Err ).Should (gbytes .Say ("cannot unmarshal" ))
365465 })
366466 })
467+
367468 Context ("when the --metadata-only flag is specified" , func () {
368469 BeforeEach (func () {
369470 commandWithArgs = []string {
@@ -382,7 +483,7 @@ var _ = Describe("bake command", func() {
382483 "--releases-directory" , otherReleasesDirectory ,
383484 "--releases-directory" , someReleasesDirectory ,
384485 "--runtime-configs-directory" , someRuntimeConfigsDirectory ,
385- "--stemcell-tarball " , stemcellTarball ,
486+ "--stemcells-directory " , singleStemcellDirectory ,
386487 "--variable" , "some-variable=some-variable-value" ,
387488 "--variables-file" , someVarFile ,
388489 "--version" , "1.2.3" ,
@@ -404,7 +505,10 @@ var _ = Describe("bake command", func() {
404505
405506 Context ("when the --stub-releases flag is specified" , func () {
406507 It ("creates a tile with empty release tarballs" , func () {
407- commandWithArgs = append (commandWithArgs , "--stub-releases" )
508+ commandWithArgs = append (commandWithArgs ,
509+ "--stemcells-directory" , singleStemcellDirectory ,
510+ "--stub-releases" ,
511+ )
408512
409513 command := exec .Command (pathToMain , commandWithArgs ... )
410514
@@ -436,6 +540,10 @@ var _ = Describe("bake command", func() {
436540
437541 Context ("when no migrations are provided" , func () {
438542 It ("creates empty migrations folder" , func () {
543+ commandWithArgs = append (commandWithArgs ,
544+ "--stemcells-directory" , singleStemcellDirectory ,
545+ )
546+
439547 command := exec .Command (pathToMain , commandWithArgs ... )
440548
441549 session , err := gexec .Start (command , GinkgoWriter , GinkgoWriter )
@@ -484,7 +592,9 @@ var _ = Describe("bake command", func() {
484592 commandWithArgs = append (commandWithArgs ,
485593 "--embed" , otherFileToEmbed ,
486594 "--embed" , someFileToEmbed ,
487- "--stub-releases" )
595+ "--stub-releases" ,
596+ "--stemcells-directory" , singleStemcellDirectory ,
597+ )
488598
489599 command := exec .Command (pathToMain , commandWithArgs ... )
490600
@@ -552,7 +662,9 @@ var _ = Describe("bake command", func() {
552662
553663 commandWithArgs = append (commandWithArgs ,
554664 "--embed" , dirToAdd ,
555- "--stub-releases" )
665+ "--stub-releases" ,
666+ "--stemcells-directory" , singleStemcellDirectory ,
667+ )
556668 command := exec .Command (pathToMain , commandWithArgs ... )
557669
558670 session , err := gexec .Start (command , GinkgoWriter , GinkgoWriter )
@@ -588,7 +700,7 @@ var _ = Describe("bake command", func() {
588700 })
589701 })
590702
591- Context ("when neither --assets-file nor --stemcell-tarball are provided" , func () {
703+ Context ("when neither --assets-file nor --stemcells-directory are provided" , func () {
592704 It ("generates a tile with unchanged stemcell criteria" , func () {
593705 commandWithArgs = []string {
594706 "bake" ,
@@ -705,7 +817,7 @@ var _ = Describe("bake command", func() {
705817 "--jobs-directory" , someOtherJobsDirectory ,
706818 "--properties-directory" , somePropertiesDirectory ,
707819 "--runtime-configs-directory" , someRuntimeConfigsDirectory ,
708- "--stemcell-tarball " , stemcellTarball ,
820+ "--stemcells-directory " , singleStemcellDirectory ,
709821 "--bosh-variables-directory" , someBOSHVariablesDirectory ,
710822 "--variable" , "some-variable=some-variable-value" ,
711823 "--variables-file" , someVarFile ,
0 commit comments