@@ -13,6 +13,7 @@ import (
13
13
"github.com/buildpacks/lifecycle/api"
14
14
"github.com/docker/docker/api/types/system"
15
15
"github.com/golang/mock/gomock"
16
+ v1 "github.com/google/go-containerregistry/pkg/v1"
16
17
"github.com/heroku/color"
17
18
"github.com/pkg/errors"
18
19
"github.com/sclevine/spec"
@@ -49,10 +50,12 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
49
50
mockBuildpackDownloader * testmocks.MockBuildpackDownloader
50
51
mockImageFactory * testmocks.MockImageFactory
51
52
mockImageFetcher * testmocks.MockImageFetcher
53
+ mockIndexFactory * testmocks.MockIndexFactory
52
54
mockDockerClient * testmocks.MockCommonAPIClient
53
55
fakeBuildImage * fakes.Image
54
56
fakeRunImage * fakes.Image
55
57
fakeRunImageMirror * fakes.Image
58
+ fakeLifecycleImage * fakes.ImageIndex
56
59
opts client.CreateBuilderOptions
57
60
subject * client.Client
58
61
logger logging.Logger
@@ -68,6 +71,10 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
68
71
mockImageFetcher .EXPECT ().Fetch (gomock .Any (), "some/build-image" , gomock .Any ()).Return (fakeBuildImage , nil )
69
72
}
70
73
74
+ var prepareIndexFetcherWithLifecycleImage = func () {
75
+ mockIndexFactory .EXPECT ().FetchIndex (gomock .Any (), gomock .Any ()).Return (fakeLifecycleImage , nil )
76
+ }
77
+
71
78
var createBuildpack = func (descriptor dist.BuildpackDescriptor ) buildpack.BuildModule {
72
79
buildpack , err := ifakes .NewFakeBuildpack (descriptor , 0644 )
73
80
h .AssertNil (t , err )
@@ -89,6 +96,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
89
96
mockDownloader = testmocks .NewMockBlobDownloader (mockController )
90
97
mockImageFetcher = testmocks .NewMockImageFetcher (mockController )
91
98
mockImageFactory = testmocks .NewMockImageFactory (mockController )
99
+ mockIndexFactory = testmocks .NewMockIndexFactory (mockController )
92
100
mockDockerClient = testmocks .NewMockCommonAPIClient (mockController )
93
101
mockBuildpackDownloader = testmocks .NewMockBuildpackDownloader (mockController )
94
102
@@ -101,6 +109,29 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
101
109
fakeRunImage = fakes .NewImage ("some/run-image" , "" , nil )
102
110
h .AssertNil (t , fakeRunImage .SetLabel ("io.buildpacks.stack.id" , "some.stack.id" ))
103
111
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
+
104
135
fakeRunImageMirror = fakes .NewImage ("localhost:5000/some/run-image" , "" , nil )
105
136
h .AssertNil (t , fakeRunImageMirror .SetLabel ("io.buildpacks.stack.id" , "some.stack.id" ))
106
137
@@ -124,6 +155,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
124
155
client .WithDownloader (mockDownloader ),
125
156
client .WithImageFactory (mockImageFactory ),
126
157
client .WithFetcher (mockImageFetcher ),
158
+ client .WithIndexFactory (mockIndexFactory ),
127
159
client .WithDockerClient (mockDockerClient ),
128
160
client .WithBuildpackDownloader (mockBuildpackDownloader ),
129
161
)
@@ -452,6 +484,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
452
484
client .WithDownloader (mockDownloader ),
453
485
client .WithImageFactory (mockImageFactory ),
454
486
client .WithFetcher (mockImageFetcher ),
487
+ client .WithIndexFactory (mockIndexFactory ),
455
488
client .WithExperimental (true ),
456
489
)
457
490
h .AssertNil (t , err )
@@ -516,6 +549,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
516
549
it ("should download from predetermined uri" , func () {
517
550
prepareFetcherWithBuildImage ()
518
551
prepareFetcherWithRunImages ()
552
+ prepareIndexFetcherWithLifecycleImage ()
519
553
opts .Config .Lifecycle .URI = ""
520
554
opts .Config .Lifecycle .Version = "3.4.5"
521
555
@@ -533,6 +567,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
533
567
it ("should download from predetermined uri for arm64" , func () {
534
568
prepareFetcherWithBuildImage ()
535
569
prepareFetcherWithRunImages ()
570
+ prepareIndexFetcherWithLifecycleImage ()
536
571
opts .Config .Lifecycle .URI = ""
537
572
opts .Config .Lifecycle .Version = "3.4.5"
538
573
h .AssertNil (t , fakeBuildImage .SetArchitecture ("arm64" ))
@@ -557,12 +592,14 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
557
592
client .WithDownloader (mockDownloader ),
558
593
client .WithImageFactory (mockImageFactory ),
559
594
client .WithFetcher (mockImageFetcher ),
595
+ client .WithIndexFactory (mockIndexFactory ),
560
596
client .WithExperimental (true ),
561
597
)
562
598
h .AssertNil (t , err )
563
599
564
600
prepareFetcherWithBuildImage ()
565
601
prepareFetcherWithRunImages ()
602
+ prepareIndexFetcherWithLifecycleImage ()
566
603
opts .Config .Lifecycle .URI = ""
567
604
opts .Config .Lifecycle .Version = "3.4.5"
568
605
h .AssertNil (t , fakeBuildImage .SetOS ("windows" ))
@@ -584,6 +621,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
584
621
it ("should download default lifecycle" , func () {
585
622
prepareFetcherWithBuildImage ()
586
623
prepareFetcherWithRunImages ()
624
+ prepareIndexFetcherWithLifecycleImage ()
587
625
opts .Config .Lifecycle .URI = ""
588
626
opts .Config .Lifecycle .Version = ""
589
627
@@ -605,6 +643,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
605
643
it ("should download default lifecycle on arm64" , func () {
606
644
prepareFetcherWithBuildImage ()
607
645
prepareFetcherWithRunImages ()
646
+ prepareIndexFetcherWithLifecycleImage ()
608
647
opts .Config .Lifecycle .URI = ""
609
648
opts .Config .Lifecycle .Version = ""
610
649
h .AssertNil (t , fakeBuildImage .SetArchitecture ("arm64" ))
@@ -633,12 +672,14 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
633
672
client .WithDownloader (mockDownloader ),
634
673
client .WithImageFactory (mockImageFactory ),
635
674
client .WithFetcher (mockImageFetcher ),
675
+ client .WithIndexFactory (mockIndexFactory ),
636
676
client .WithExperimental (true ),
637
677
)
638
678
h .AssertNil (t , err )
639
679
640
680
prepareFetcherWithBuildImage ()
641
681
prepareFetcherWithRunImages ()
682
+ prepareIndexFetcherWithLifecycleImage ()
642
683
opts .Config .Lifecycle .URI = ""
643
684
opts .Config .Lifecycle .Version = ""
644
685
h .AssertNil (t , fakeBuildImage .SetOS ("windows" ))
0 commit comments