@@ -28,11 +28,12 @@ func TestRebaser(t *testing.T) {
2828
2929func testRebaser (t * testing.T , when spec.G , it spec.S ) {
3030 var (
31- rebaser * lifecycle.Rebaser
32- fakeAppImage * fakes.Image
33- fakeNewBaseImage * fakes.Image
34- additionalNames []string
35- md platform.LayersMetadataCompat
31+ rebaser * lifecycle.Rebaser
32+ fakeAppImage * fakes.Image
33+ fakeNewBaseImage * fakes.Image
34+ fakePreviousImage * fakes.Image
35+ additionalNames []string
36+ md platform.LayersMetadataCompat
3637 )
3738
3839 it .Before (func () {
@@ -54,6 +55,15 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
5455 )
5556 h .AssertNil (t , fakeNewBaseImage .SetLabel (platform .StackIDLabel , "io.buildpacks.stacks.bionic" ))
5657
58+ fakePreviousImage = fakes .NewImage (
59+ "some-repo/previous-image" ,
60+ "previous-layer-sha" ,
61+ local.IDIdentifier {
62+ ImageID : "previous-run-id" ,
63+ },
64+ )
65+ h .AssertNil (t , fakePreviousImage .SetLabel (platform .StackIDLabel , "io.buildpacks.stacks.bionic" ))
66+
5767 additionalNames = []string {"some-repo/app-image:foo" , "some-repo/app-image:bar" }
5868
5969 rebaser = & lifecycle.Rebaser {
@@ -70,33 +80,33 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
7080 when ("#Rebase" , func () {
7181 when ("app image and run image exist" , func () {
7282 it ("updates the base image of the app image" , func () {
73- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
83+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
7484 h .AssertNil (t , err )
7585 h .AssertEq (t , fakeAppImage .Base (), "some-repo/new-base-image" )
7686 })
7787
7888 it ("saves to all names" , func () {
79- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
89+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
8090 h .AssertNil (t , err )
8191 h .AssertContains (t , fakeAppImage .SavedNames (), "some-repo/app-image" , "some-repo/app-image:foo" , "some-repo/app-image:bar" )
8292 })
8393
8494 it ("adds all names to report" , func () {
85- report , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
95+ report , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
8696 h .AssertNil (t , err )
8797 h .AssertContains (t , report .Image .Tags , "some-repo/app-image" , "some-repo/app-image:foo" , "some-repo/app-image:bar" )
8898 })
8999
90100 it ("sets the top layer in the metadata" , func () {
91- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
101+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
92102 h .AssertNil (t , err )
93103 h .AssertNil (t , image .DecodeLabel (fakeAppImage , platform .LayerMetadataLabel , & md ))
94104
95105 h .AssertEq (t , md .RunImage .TopLayer , "new-top-layer-sha" )
96106 })
97107
98108 it ("sets the run image reference in the metadata" , func () {
99- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
109+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
100110 h .AssertNil (t , err )
101111 h .AssertNil (t , image .DecodeLabel (fakeAppImage , platform .LayerMetadataLabel , & md ))
102112
@@ -108,7 +118,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
108118 platform .LayerMetadataLabel ,
109119 `{"app": [{"sha": "123456"}], "buildpacks":[{"key": "buildpack.id", "layers": {}}]}` ,
110120 ))
111- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
121+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
112122 h .AssertNil (t , err )
113123 h .AssertNil (t , image .DecodeLabel (fakeAppImage , platform .LayerMetadataLabel , & md ))
114124
@@ -144,7 +154,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
144154 })
145155
146156 it ("syncs matching labels" , func () {
147- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
157+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
148158 h .AssertNil (t , err )
149159
150160 for _ , test := range tests {
@@ -170,7 +180,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
170180 })
171181
172182 it ("add the digest to the report" , func () {
173- report , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
183+ report , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
174184 h .AssertNil (t , err )
175185
176186 h .AssertEq (t , report .Image .Digest , fakeRemoteDigest )
@@ -192,7 +202,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
192202 })
193203
194204 it ("doesn't set the manifest size in the report.toml" , func () {
195- report , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
205+ report , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
196206 h .AssertNil (t , err )
197207
198208 h .AssertEq (t , report .Image .ManifestSize , int64 (0 ))
@@ -208,7 +218,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
208218 })
209219
210220 it ("add the manifest size to the report" , func () {
211- report , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
221+ report , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
212222 h .AssertNil (t , err )
213223
214224 h .AssertEq (t , report .Image .ManifestSize , fakeRemoteManifestSize )
@@ -222,7 +232,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
222232 })
223233
224234 it ("doesn't set the manifest size in the report.toml" , func () {
225- report , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
235+ report , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
226236 h .AssertNil (t , err )
227237
228238 h .AssertEq (t , report .Image .ManifestSize , int64 (0 ))
@@ -233,7 +243,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
233243
234244 when ("image has an ID identifier" , func () {
235245 it ("add the imageID to the report" , func () {
236- report , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
246+ report , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
237247 h .AssertNil (t , err )
238248
239249 h .AssertEq (t , report .Image .ImageID , "some-image-id" )
@@ -243,7 +253,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
243253 when ("validating mixins" , func () {
244254 when ("there are no mixin labels" , func () {
245255 it ("allows rebase" , func () {
246- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
256+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
247257 h .AssertNil (t , err )
248258 h .AssertEq (t , fakeAppImage .Base (), "some-repo/new-base-image" )
249259 })
@@ -252,7 +262,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
252262 when ("there are invalid mixin labels" , func () {
253263 it ("returns an error" , func () {
254264 h .AssertNil (t , fakeAppImage .SetLabel (platform .MixinsLabel , "thisisn'tvalid!" ))
255- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
265+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
256266 h .AssertError (t , err , "get app image mixins: failed to unmarshal context of label 'io.buildpacks.stack.mixins': invalid character 'h' in literal true (expecting 'r')" )
257267 })
258268 })
@@ -261,7 +271,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
261271 it ("allows rebase" , func () {
262272 h .AssertNil (t , fakeAppImage .SetLabel (platform .MixinsLabel , "null" ))
263273 h .AssertNil (t , fakeNewBaseImage .SetLabel (platform .MixinsLabel , "null" ))
264- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
274+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
265275 h .AssertNil (t , err )
266276 h .AssertEq (t , fakeAppImage .Base (), "some-repo/new-base-image" )
267277 })
@@ -271,7 +281,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
271281 it ("allows rebase" , func () {
272282 h .AssertNil (t , fakeAppImage .SetLabel (platform .MixinsLabel , "null" ))
273283 h .AssertNil (t , fakeNewBaseImage .SetLabel (platform .MixinsLabel , "[\" mixin-1\" ]" ))
274- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
284+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
275285 h .AssertNil (t , err )
276286 h .AssertEq (t , fakeAppImage .Base (), "some-repo/new-base-image" )
277287 })
@@ -281,7 +291,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
281291 it ("allows rebase" , func () {
282292 h .AssertNil (t , fakeAppImage .SetLabel (platform .MixinsLabel , "[\" mixin-1\" , \" run:mixin-2\" ]" ))
283293 h .AssertNil (t , fakeNewBaseImage .SetLabel (platform .MixinsLabel , "[\" mixin-1\" , \" run:mixin-2\" ]" ))
284- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
294+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
285295 h .AssertNil (t , err )
286296 h .AssertEq (t , fakeAppImage .Base (), "some-repo/new-base-image" )
287297 })
@@ -291,7 +301,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
291301 it ("allows rebase" , func () {
292302 h .AssertNil (t , fakeAppImage .SetLabel (platform .MixinsLabel , "[\" mixin-1\" , \" run:mixin-2\" ]" ))
293303 h .AssertNil (t , fakeNewBaseImage .SetLabel (platform .MixinsLabel , "[\" mixin-1\" , \" run:mixin-2\" , \" mixin-3\" ]" ))
294- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
304+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
295305 h .AssertNil (t , err )
296306 h .AssertEq (t , fakeAppImage .Base (), "some-repo/new-base-image" )
297307 })
@@ -301,7 +311,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
301311 it ("allows rebase" , func () {
302312 h .AssertNil (t , fakeAppImage .SetLabel (platform .MixinsLabel , "[\" mixin-1\" , \" run:mixin-2\" ]" ))
303313 h .AssertNil (t , fakeNewBaseImage .SetLabel (platform .MixinsLabel , "[\" mixin-1\" , \" mixin-2\" ]" ))
304- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
314+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
305315 h .AssertNil (t , err )
306316 h .AssertEq (t , fakeAppImage .Base (), "some-repo/new-base-image" )
307317 })
@@ -311,7 +321,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
311321 it ("allows rebase" , func () {
312322 h .AssertNil (t , fakeAppImage .SetLabel (platform .MixinsLabel , "[\" mixin-1\" , \" run:mixin-2\" ]" ))
313323 h .AssertNil (t , fakeNewBaseImage .SetLabel (platform .MixinsLabel , "[\" run:mixin-1\" , \" run:mixin-2\" ]" ))
314- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
324+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
315325 h .AssertNil (t , err )
316326 h .AssertEq (t , fakeAppImage .Base (), "some-repo/new-base-image" )
317327 })
@@ -321,7 +331,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
321331 it ("does not allow rebase" , func () {
322332 h .AssertNil (t , fakeAppImage .SetLabel (platform .MixinsLabel , "[\" mixin-1\" , \" run:mixin-2\" ]" ))
323333 h .AssertNil (t , fakeNewBaseImage .SetLabel (platform .MixinsLabel , "[\" run:mixin-2\" ]" ))
324- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
334+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
325335 h .AssertError (t , err , "missing required mixin(s): mixin-1" )
326336 })
327337 })
@@ -333,25 +343,35 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
333343 h .AssertNil (t , fakeAppImage .SetLabel (platform .StackIDLabel , "io.buildpacks.stacks.bionic" ))
334344 h .AssertNil (t , fakeNewBaseImage .SetLabel (platform .StackIDLabel , "io.buildpacks.stacks.cflinuxfs3" ))
335345
336- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
346+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
337347 h .AssertError (t , err , "incompatible stack: 'io.buildpacks.stacks.cflinuxfs3' is not compatible with 'io.buildpacks.stacks.bionic'" )
338348 })
339349
340350 it ("returns an error and prevents the rebase from taking place when the new base image has no stack defined" , func () {
341351 h .AssertNil (t , fakeAppImage .SetLabel (platform .StackIDLabel , "io.buildpacks.stacks.bionic" ))
342352 h .AssertNil (t , fakeNewBaseImage .SetLabel (platform .StackIDLabel , "" ))
343353
344- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
354+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
345355 h .AssertError (t , err , "stack not defined on new base image" )
346356 })
347357
348358 it ("returns an error and prevents the rebase from taking place when the app image has no stack defined" , func () {
349359 h .AssertNil (t , fakeAppImage .SetLabel (platform .StackIDLabel , "" ))
350360 h .AssertNil (t , fakeNewBaseImage .SetLabel (platform .StackIDLabel , "io.buildpacks.stacks.cflinuxfs3" ))
351361
352- _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , additionalNames )
362+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , fakeAppImage . Name (), additionalNames )
353363 h .AssertError (t , err , "stack not defined on app image" )
354364 })
355365 })
366+
367+ when ("outputImageRef is different than workingImage name" , func () {
368+ it ("saves using outputImageRef, not the app image name" , func () {
369+ outputImageRef := "fizz"
370+ _ , err := rebaser .Rebase (fakeAppImage , fakeNewBaseImage , outputImageRef , additionalNames )
371+ h .AssertNil (t , err )
372+ h .AssertContains (t , fakeAppImage .SavedNames (), append (additionalNames , outputImageRef )... )
373+ h .AssertDoesNotContain (t , fakeAppImage .SavedNames (), fakePreviousImage .Name ())
374+ })
375+ })
356376 })
357377}
0 commit comments