@@ -68,12 +68,12 @@ func (bl bundleLocations) images() []string {
68
68
return images
69
69
}
70
70
71
- func inTemporaryBuildContext (f func () error ) (rerr error ) {
71
+ func inTemporaryBuildContext (f func () error , source string ) (rerr error ) {
72
72
td , err := ioutil .TempDir ("." , "opm-" )
73
73
if err != nil {
74
74
return err
75
75
}
76
- err = copy .Copy ("../../manifests" , filepath .Join (td , "manifests" ))
76
+ err = copy .Copy (source , filepath .Join (td , "manifests" ))
77
77
if err != nil {
78
78
return err
79
79
}
@@ -218,43 +218,70 @@ func initialize() error {
218
218
219
219
var _ = Describe ("opm" , func () {
220
220
IncludeSharedSpecs := func (containerTool string ) {
221
- It ("builds and validates a bundle image" , func () {
222
- By ("building bundle" )
223
- img := bundleImage + ":" + bundleTag3
224
- err := inTemporaryBuildContext (func () error {
225
- return bundle .BuildFunc (bundlePath3 , "" , img , containerTool , packageName , channels , defaultChannel , false )
226
- })
227
- Expect (err ).NotTo (HaveOccurred ())
221
+ Describe ("builds and validates a bundle image" , func () {
222
+ var (
223
+ img string
224
+ unpackDir string
225
+ sourceDir string
226
+ validator bundle.BundleImageValidator
227
+ )
228
+
229
+ JustBeforeEach (func () {
230
+ By ("building bundle" )
231
+ err := inTemporaryBuildContext (func () error {
232
+ return bundle .BuildFunc (bundlePath3 , "" , img , containerTool , packageName , channels , defaultChannel , false )
233
+ }, sourceDir )
234
+ Expect (err ).NotTo (HaveOccurred ())
228
235
229
- By ("pushing bundle" )
230
- Expect (pushWith (containerTool , img )).To (Succeed ())
236
+ By ("pushing bundle" )
237
+ Expect (pushWith (containerTool , img )).To (Succeed ())
238
+
239
+ By ("pulling bundle" )
240
+ logger := logrus .WithFields (logrus.Fields {"image" : img })
241
+ tool := containertools .NewContainerTool (containerTool , containertools .NoneTool )
242
+ var registry image.Registry
243
+ switch tool {
244
+ case containertools .PodmanTool , containertools .DockerTool :
245
+ registry , err = execregistry .NewRegistry (tool , logger )
246
+ case containertools .NoneTool :
247
+ registry , err = containerdregistry .NewRegistry (containerdregistry .WithLog (logger ))
248
+ default :
249
+ err = fmt .Errorf ("unrecognized container-tool option: %s" , containerTool )
250
+ }
251
+ Expect (err ).NotTo (HaveOccurred ())
231
252
232
- By ("pulling bundle" )
233
- logger := logrus .WithFields (logrus.Fields {"image" : img })
234
- tool := containertools .NewContainerTool (containerTool , containertools .NoneTool )
235
- var registry image.Registry
236
- switch tool {
237
- case containertools .PodmanTool , containertools .DockerTool :
238
- registry , err = execregistry .NewRegistry (tool , logger )
239
- case containertools .NoneTool :
240
- registry , err = containerdregistry .NewRegistry (containerdregistry .WithLog (logger ))
241
- default :
242
- err = fmt .Errorf ("unrecognized container-tool option: %s" , containerTool )
243
- }
244
- Expect (err ).NotTo (HaveOccurred ())
253
+ unpackDir , err = ioutil .TempDir ("." , bundleTag3 )
254
+ Expect (err ).NotTo (HaveOccurred ())
255
+ validator = bundle .NewImageValidator (registry , logger )
256
+ Expect (validator .PullBundleImage (img , unpackDir )).To (Succeed ())
257
+ })
245
258
246
- unpackDir , err := ioutil .TempDir ("." , bundleTag3 )
247
- Expect (err ).NotTo (HaveOccurred ())
248
- validator := bundle .NewImageValidator (registry , logger )
249
- Expect (validator .PullBundleImage (img , unpackDir )).To (Succeed ())
259
+ When ("the image is valid" , func () {
260
+ BeforeEach (func () {
261
+ img = bundleImage + ":" + bundleTag3
262
+ sourceDir = "../../manifests"
263
+ })
264
+ It ("should succeed" , func () {
265
+ Expect (validator .ValidateBundleFormat (unpackDir )).To (Succeed ())
266
+ manifestsDir := filepath .Join (unpackDir , bundle .ManifestsDir )
267
+ Expect (validator .ValidateBundleContent (manifestsDir )).To (Succeed ())
268
+ Expect (os .RemoveAll (unpackDir )).To (Succeed ())
269
+ })
270
+ })
250
271
251
- By ("validating bundle format" )
252
- Expect (validator .ValidateBundleFormat (unpackDir )).To (Succeed ())
272
+ When ("the image is NOT valid" , func () {
273
+ BeforeEach (func () {
274
+ img = bundleImage + ":" + rand .String (6 )
275
+ sourceDir = "../../test/e2e/testdata/invalid-manifests"
276
+ })
277
+ It ("should fail" , func () {
278
+ Expect (validator .ValidateBundleFormat (unpackDir )).To (Succeed ())
279
+ manifestsDir := filepath .Join (unpackDir , bundle .ManifestsDir )
280
+ Expect (validator .ValidateBundleContent (manifestsDir )).Should (HaveOccurred ())
281
+ Expect (os .RemoveAll (unpackDir )).To (Succeed ())
282
+ })
253
283
254
- By ("validating bundle content" )
255
- manifestsDir := filepath .Join (unpackDir , bundle .ManifestsDir )
256
- Expect (validator .ValidateBundleContent (manifestsDir )).To (Succeed ())
257
- Expect (os .RemoveAll (unpackDir )).To (Succeed ())
284
+ })
258
285
})
259
286
260
287
It ("builds and manipulates bundle and index images" , func () {
@@ -268,7 +295,7 @@ var _ = Describe("opm", func() {
268
295
for _ , b := range bundles {
269
296
err = inTemporaryBuildContext (func () error {
270
297
return bundle .BuildFunc (b .path , "" , b .image , containerTool , packageName , channels , defaultChannel , false )
271
- })
298
+ }, "../../manifests" )
272
299
Expect (err ).NotTo (HaveOccurred ())
273
300
}
274
301
0 commit comments