@@ -81,44 +81,140 @@ func testBpDescriptor(t *testing.T, when spec.G, it spec.S) {
81
81
h .AssertEq (t , descriptor .Targets [0 ].Distros [0 ].Version , "V8.4-2L3" )
82
82
})
83
83
84
- it ("does translate one special stack value into target values for older apis" , func () {
85
- path := filepath .Join ("testdata" , "buildpack" , "by-id" , "B" , "v1" , "buildpack.toml" )
86
- descriptor , err := buildpack .ReadBpDescriptor (path )
87
- h .AssertNil (t , err )
88
- // common sanity checks
89
- h .AssertEq (t , descriptor .WithAPI , "0.7" )
90
- h .AssertEq (t , descriptor .Buildpack .ID , "B" )
91
- h .AssertEq (t , descriptor .Buildpack .Name , "Buildpack B" )
92
- h .AssertEq (t , descriptor .Buildpack .Version , "v1" )
93
- h .AssertEq (t , descriptor .Buildpack .Homepage , "Buildpack B Homepage" )
94
- h .AssertEq (t , descriptor .Buildpack .SBOM , []string {"application/vnd.cyclonedx+json" })
95
- // specific behaviors for this test
96
- h .AssertEq (t , descriptor .Stacks [0 ].ID , "io.buildpacks.stacks.bionic" )
97
- h .AssertEq (t , len (descriptor .Targets ), 1 )
98
- h .AssertEq (t , descriptor .Targets [0 ].Arch , "amd64" )
99
- h .AssertEq (t , descriptor .Targets [0 ].OS , "linux" )
100
- h .AssertEq (t , descriptor .Targets [0 ].Distros [0 ].Name , "ubuntu" )
101
- h .AssertEq (t , descriptor .Targets [0 ].Distros [0 ].Version , "18.04" )
102
- })
84
+ when ("translating stacks to targets" , func () {
85
+ when ("older buildpacks" , func () {
86
+ when ("there is only bionic" , func () {
87
+ it ("creates a target" , func () {
88
+ path := filepath .Join ("testdata" , "buildpack" , "by-id" , "B" , "v1" , "buildpack.toml" )
89
+ descriptor , err := buildpack .ReadBpDescriptor (path )
90
+ h .AssertNil (t , err )
91
+ // common sanity checks
92
+ h .AssertEq (t , descriptor .WithAPI , "0.7" )
93
+ h .AssertEq (t , descriptor .Buildpack .ID , "B" )
94
+ h .AssertEq (t , descriptor .Buildpack .Name , "Buildpack B" )
95
+ h .AssertEq (t , descriptor .Buildpack .Version , "v1" )
96
+ h .AssertEq (t , descriptor .Buildpack .Homepage , "Buildpack B Homepage" )
97
+ h .AssertEq (t , descriptor .Buildpack .SBOM , []string {"application/vnd.cyclonedx+json" })
98
+ // specific behaviors for this test
99
+ h .AssertEq (t , descriptor .Stacks [0 ].ID , "io.buildpacks.stacks.bionic" )
100
+ h .AssertEq (t , len (descriptor .Targets ), 1 )
101
+ h .AssertEq (t , descriptor .Targets [0 ].Arch , "amd64" )
102
+ h .AssertEq (t , descriptor .Targets [0 ].OS , "linux" )
103
+ h .AssertEq (t , descriptor .Targets [0 ].Distros [0 ].Name , "ubuntu" )
104
+ h .AssertEq (t , descriptor .Targets [0 ].Distros [0 ].Version , "18.04" )
105
+ })
106
+ })
103
107
104
- it ("translates one special stack value into target values" , func () {
105
- path := filepath .Join ("testdata" , "buildpack" , "by-id" , "B" , "v2" , "buildpack.toml" )
106
- descriptor , err := buildpack .ReadBpDescriptor (path )
107
- h .AssertNil (t , err )
108
- // common sanity checks
109
- h .AssertEq (t , descriptor .WithAPI , "0.12" )
110
- h .AssertEq (t , descriptor .Buildpack .ID , "B" )
111
- h .AssertEq (t , descriptor .Buildpack .Name , "Buildpack B" )
112
- h .AssertEq (t , descriptor .Buildpack .Version , "v1" )
113
- h .AssertEq (t , descriptor .Buildpack .Homepage , "Buildpack B Homepage" )
114
- h .AssertEq (t , descriptor .Buildpack .SBOM , []string {"application/vnd.cyclonedx+json" })
115
- // specific behaviors for this test
116
- h .AssertEq (t , descriptor .Stacks [0 ].ID , "io.buildpacks.stacks.bionic" )
117
- h .AssertEq (t , len (descriptor .Targets ), 1 )
118
- h .AssertEq (t , descriptor .Targets [0 ].Arch , "amd64" )
119
- h .AssertEq (t , descriptor .Targets [0 ].OS , "linux" )
120
- h .AssertEq (t , descriptor .Targets [0 ].Distros [0 ].Name , "ubuntu" )
121
- h .AssertEq (t , descriptor .Targets [0 ].Distros [0 ].Version , "18.04" )
108
+ when ("there are multiple stacks" , func () {
109
+ it ("does NOT create a target" , func () {
110
+ path := filepath .Join ("testdata" , "buildpack" , "by-id" , "B" , "v1.2" , "buildpack.toml" )
111
+ descriptor , err := buildpack .ReadBpDescriptor (path )
112
+ h .AssertNil (t , err )
113
+ // common sanity checks
114
+ h .AssertEq (t , descriptor .WithAPI , "0.7" )
115
+ h .AssertEq (t , descriptor .Buildpack .ID , "B" )
116
+ h .AssertEq (t , descriptor .Buildpack .Name , "Buildpack B" )
117
+ h .AssertEq (t , descriptor .Buildpack .Version , "v1.2" )
118
+ h .AssertEq (t , descriptor .Buildpack .Homepage , "Buildpack B Homepage" )
119
+ h .AssertEq (t , descriptor .Buildpack .SBOM , []string {"application/vnd.cyclonedx+json" })
120
+ // specific behaviors for this test
121
+ h .AssertEq (t , descriptor .Stacks [0 ].ID , "io.buildpacks.stacks.bionic" )
122
+ h .AssertEq (t , len (descriptor .Targets ), 0 )
123
+ })
124
+ })
125
+
126
+ when ("there is a wildcard stack" , func () {
127
+ it ("creates a wildcard target" , func () {
128
+ path := filepath .Join ("testdata" , "buildpack" , "by-id" , "B" , "v1.star" , "buildpack.toml" )
129
+ descriptor , err := buildpack .ReadBpDescriptor (path )
130
+ h .AssertNil (t , err )
131
+ // common sanity checks
132
+ h .AssertEq (t , descriptor .WithAPI , "0.7" )
133
+ h .AssertEq (t , descriptor .Buildpack .ID , "B" )
134
+ h .AssertEq (t , descriptor .Buildpack .Name , "Buildpack B" )
135
+ h .AssertEq (t , descriptor .Buildpack .Version , "v1.star" )
136
+ h .AssertEq (t , descriptor .Buildpack .Homepage , "Buildpack B Homepage" )
137
+ h .AssertEq (t , descriptor .Buildpack .SBOM , []string {"application/vnd.cyclonedx+json" })
138
+ // specific behaviors for this test
139
+ h .AssertEq (t , descriptor .Stacks [0 ].ID , "*" )
140
+ h .AssertEq (t , len (descriptor .Targets ), 1 )
141
+ // a target that is completely empty will always match whatever is the base image target
142
+ h .AssertEq (t , descriptor .Targets [0 ].Arch , "" )
143
+ h .AssertEq (t , descriptor .Targets [0 ].OS , "" )
144
+ h .AssertEq (t , descriptor .Targets [0 ].ArchVariant , "" )
145
+ h .AssertEq (t , len (descriptor .Targets [0 ].Distros ), 0 )
146
+ })
147
+ })
148
+ })
149
+
150
+ when ("newer buildpacks" , func () {
151
+ when ("there is only bionic" , func () {
152
+ it ("creates a target" , func () {
153
+ path := filepath .Join ("testdata" , "buildpack" , "by-id" , "B" , "v2" , "buildpack.toml" )
154
+ descriptor , err := buildpack .ReadBpDescriptor (path )
155
+ h .AssertNil (t , err )
156
+ // common sanity checks
157
+ h .AssertEq (t , descriptor .WithAPI , "0.12" )
158
+ h .AssertEq (t , descriptor .Buildpack .ID , "B" )
159
+ h .AssertEq (t , descriptor .Buildpack .Name , "Buildpack B" )
160
+ h .AssertEq (t , descriptor .Buildpack .Version , "v2" )
161
+ h .AssertEq (t , descriptor .Buildpack .Homepage , "Buildpack B Homepage" )
162
+ h .AssertEq (t , descriptor .Buildpack .SBOM , []string {"application/vnd.cyclonedx+json" })
163
+ // specific behaviors for this test
164
+ h .AssertEq (t , descriptor .Stacks [0 ].ID , "io.buildpacks.stacks.bionic" )
165
+ h .AssertEq (t , len (descriptor .Targets ), 1 )
166
+ h .AssertEq (t , descriptor .Targets [0 ].Arch , "amd64" )
167
+ h .AssertEq (t , descriptor .Targets [0 ].OS , "linux" )
168
+ h .AssertEq (t , descriptor .Targets [0 ].Distros [0 ].Name , "ubuntu" )
169
+ h .AssertEq (t , descriptor .Targets [0 ].Distros [0 ].Version , "18.04" )
170
+ })
171
+ })
172
+
173
+ when ("there are multiple stacks" , func () {
174
+ it ("creates a target" , func () {
175
+ path := filepath .Join ("testdata" , "buildpack" , "by-id" , "B" , "v2.2" , "buildpack.toml" )
176
+ descriptor , err := buildpack .ReadBpDescriptor (path )
177
+ h .AssertNil (t , err )
178
+ // common sanity checks
179
+ h .AssertEq (t , descriptor .WithAPI , "0.12" )
180
+ h .AssertEq (t , descriptor .Buildpack .ID , "B" )
181
+ h .AssertEq (t , descriptor .Buildpack .Name , "Buildpack B" )
182
+ h .AssertEq (t , descriptor .Buildpack .Version , "v2.2" )
183
+ h .AssertEq (t , descriptor .Buildpack .Homepage , "Buildpack B Homepage" )
184
+ h .AssertEq (t , descriptor .Buildpack .SBOM , []string {"application/vnd.cyclonedx+json" })
185
+ // specific behaviors for this test
186
+ h .AssertEq (t , descriptor .Stacks [0 ].ID , "io.buildpacks.stacks.bionic" )
187
+ h .AssertEq (t , len (descriptor .Targets ), 1 )
188
+ h .AssertEq (t , descriptor .Targets [0 ].Arch , "amd64" )
189
+ h .AssertEq (t , descriptor .Targets [0 ].OS , "linux" )
190
+ h .AssertEq (t , descriptor .Targets [0 ].Distros [0 ].Name , "ubuntu" )
191
+ h .AssertEq (t , descriptor .Targets [0 ].Distros [0 ].Version , "18.04" )
192
+ })
193
+ })
194
+
195
+ when ("there is a wildcard stack" , func () {
196
+ it ("creates a wildcard target" , func () {
197
+ path := filepath .Join ("testdata" , "buildpack" , "by-id" , "B" , "v2.star" , "buildpack.toml" )
198
+ descriptor , err := buildpack .ReadBpDescriptor (path )
199
+ h .AssertNil (t , err )
200
+ // common sanity checks
201
+ h .AssertEq (t , descriptor .WithAPI , "0.12" )
202
+ h .AssertEq (t , descriptor .Buildpack .ID , "B" )
203
+ h .AssertEq (t , descriptor .Buildpack .Name , "Buildpack B" )
204
+ h .AssertEq (t , descriptor .Buildpack .Version , "v2.star" )
205
+ h .AssertEq (t , descriptor .Buildpack .Homepage , "Buildpack B Homepage" )
206
+ h .AssertEq (t , descriptor .Buildpack .SBOM , []string {"application/vnd.cyclonedx+json" })
207
+ // specific behaviors for this test
208
+ h .AssertEq (t , descriptor .Stacks [0 ].ID , "*" )
209
+ h .AssertEq (t , len (descriptor .Targets ), 1 )
210
+ // a target that is completely empty will always match whatever is the base image target
211
+ h .AssertEq (t , descriptor .Targets [0 ].Arch , "" )
212
+ h .AssertEq (t , descriptor .Targets [0 ].OS , "" )
213
+ h .AssertEq (t , descriptor .Targets [0 ].ArchVariant , "" )
214
+ h .AssertEq (t , len (descriptor .Targets [0 ].Distros ), 0 )
215
+ })
216
+ })
217
+ })
122
218
})
123
219
124
220
it ("does not translate non-special stack values" , func () {
0 commit comments