@@ -13,6 +13,7 @@ import (
1313 "github.com/buildpacks/lifecycle/api"
1414 "github.com/docker/docker/api/types/system"
1515 "github.com/golang/mock/gomock"
16+ v1 "github.com/google/go-containerregistry/pkg/v1"
1617 "github.com/heroku/color"
1718 "github.com/pkg/errors"
1819 "github.com/sclevine/spec"
@@ -49,10 +50,12 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
4950 mockBuildpackDownloader * testmocks.MockBuildpackDownloader
5051 mockImageFactory * testmocks.MockImageFactory
5152 mockImageFetcher * testmocks.MockImageFetcher
53+ mockIndexFactory * testmocks.MockIndexFactory
5254 mockDockerClient * testmocks.MockCommonAPIClient
5355 fakeBuildImage * fakes.Image
5456 fakeRunImage * fakes.Image
5557 fakeRunImageMirror * fakes.Image
58+ fakeLifecycleImage * fakes.ImageIndex
5659 opts client.CreateBuilderOptions
5760 subject * client.Client
5861 logger logging.Logger
@@ -68,6 +71,10 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
6871 mockImageFetcher .EXPECT ().Fetch (gomock .Any (), "some/build-image" , gomock .Any ()).Return (fakeBuildImage , nil )
6972 }
7073
74+ var prepareIndexFetcherWithLifecycleImage = func () {
75+ mockIndexFactory .EXPECT ().FetchIndex (gomock .Any (), gomock .Any ()).Return (fakeLifecycleImage , nil )
76+ }
77+
7178 var createBuildpack = func (descriptor dist.BuildpackDescriptor ) buildpack.BuildModule {
7279 buildpack , err := ifakes .NewFakeBuildpack (descriptor , 0644 )
7380 h .AssertNil (t , err )
@@ -89,6 +96,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
8996 mockDownloader = testmocks .NewMockBlobDownloader (mockController )
9097 mockImageFetcher = testmocks .NewMockImageFetcher (mockController )
9198 mockImageFactory = testmocks .NewMockImageFactory (mockController )
99+ mockIndexFactory = testmocks .NewMockIndexFactory (mockController )
92100 mockDockerClient = testmocks .NewMockCommonAPIClient (mockController )
93101 mockBuildpackDownloader = testmocks .NewMockBuildpackDownloader (mockController )
94102
@@ -101,6 +109,29 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
101109 fakeRunImage = fakes .NewImage ("some/run-image" , "" , nil )
102110 h .AssertNil (t , fakeRunImage .SetLabel ("io.buildpacks.stack.id" , "some.stack.id" ))
103111
112+ fakeLifecycleImage = & fakes.ImageIndex {
113+ Manifests : []v1.Descriptor {
114+ {
115+ Platform : & v1.Platform {
116+ OS : "linux" ,
117+ Architecture : "amd64" ,
118+ },
119+ },
120+ {
121+ Platform : & v1.Platform {
122+ OS : "linux" ,
123+ Architecture : "arm64" ,
124+ },
125+ },
126+ {
127+ Platform : & v1.Platform {
128+ OS : "windows" ,
129+ Architecture : "amd64" ,
130+ },
131+ },
132+ },
133+ }
134+
104135 fakeRunImageMirror = fakes .NewImage ("localhost:5000/some/run-image" , "" , nil )
105136 h .AssertNil (t , fakeRunImageMirror .SetLabel ("io.buildpacks.stack.id" , "some.stack.id" ))
106137
@@ -124,6 +155,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
124155 client .WithDownloader (mockDownloader ),
125156 client .WithImageFactory (mockImageFactory ),
126157 client .WithFetcher (mockImageFetcher ),
158+ client .WithIndexFactory (mockIndexFactory ),
127159 client .WithDockerClient (mockDockerClient ),
128160 client .WithBuildpackDownloader (mockBuildpackDownloader ),
129161 )
@@ -452,6 +484,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
452484 client .WithDownloader (mockDownloader ),
453485 client .WithImageFactory (mockImageFactory ),
454486 client .WithFetcher (mockImageFetcher ),
487+ client .WithIndexFactory (mockIndexFactory ),
455488 client .WithExperimental (true ),
456489 )
457490 h .AssertNil (t , err )
@@ -516,6 +549,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
516549 it ("should download from predetermined uri" , func () {
517550 prepareFetcherWithBuildImage ()
518551 prepareFetcherWithRunImages ()
552+ prepareIndexFetcherWithLifecycleImage ()
519553 opts .Config .Lifecycle .URI = ""
520554 opts .Config .Lifecycle .Version = "3.4.5"
521555
@@ -533,6 +567,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
533567 it ("should download from predetermined uri for arm64" , func () {
534568 prepareFetcherWithBuildImage ()
535569 prepareFetcherWithRunImages ()
570+ prepareIndexFetcherWithLifecycleImage ()
536571 opts .Config .Lifecycle .URI = ""
537572 opts .Config .Lifecycle .Version = "3.4.5"
538573 h .AssertNil (t , fakeBuildImage .SetArchitecture ("arm64" ))
@@ -557,12 +592,14 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
557592 client .WithDownloader (mockDownloader ),
558593 client .WithImageFactory (mockImageFactory ),
559594 client .WithFetcher (mockImageFetcher ),
595+ client .WithIndexFactory (mockIndexFactory ),
560596 client .WithExperimental (true ),
561597 )
562598 h .AssertNil (t , err )
563599
564600 prepareFetcherWithBuildImage ()
565601 prepareFetcherWithRunImages ()
602+ prepareIndexFetcherWithLifecycleImage ()
566603 opts .Config .Lifecycle .URI = ""
567604 opts .Config .Lifecycle .Version = "3.4.5"
568605 h .AssertNil (t , fakeBuildImage .SetOS ("windows" ))
@@ -584,6 +621,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
584621 it ("should download default lifecycle" , func () {
585622 prepareFetcherWithBuildImage ()
586623 prepareFetcherWithRunImages ()
624+ prepareIndexFetcherWithLifecycleImage ()
587625 opts .Config .Lifecycle .URI = ""
588626 opts .Config .Lifecycle .Version = ""
589627
@@ -605,6 +643,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
605643 it ("should download default lifecycle on arm64" , func () {
606644 prepareFetcherWithBuildImage ()
607645 prepareFetcherWithRunImages ()
646+ prepareIndexFetcherWithLifecycleImage ()
608647 opts .Config .Lifecycle .URI = ""
609648 opts .Config .Lifecycle .Version = ""
610649 h .AssertNil (t , fakeBuildImage .SetArchitecture ("arm64" ))
@@ -633,12 +672,14 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
633672 client .WithDownloader (mockDownloader ),
634673 client .WithImageFactory (mockImageFactory ),
635674 client .WithFetcher (mockImageFetcher ),
675+ client .WithIndexFactory (mockIndexFactory ),
636676 client .WithExperimental (true ),
637677 )
638678 h .AssertNil (t , err )
639679
640680 prepareFetcherWithBuildImage ()
641681 prepareFetcherWithRunImages ()
682+ prepareIndexFetcherWithLifecycleImage ()
642683 opts .Config .Lifecycle .URI = ""
643684 opts .Config .Lifecycle .Version = ""
644685 h .AssertNil (t , fakeBuildImage .SetOS ("windows" ))
0 commit comments