Skip to content

Commit 2bfbe25

Browse files
author
Josef Karasek
committed
Test case for invalid manifests
Added: * Prometheus manifests where CSV is missing `APIVersion` * Test case which expects `opm index add` with the invalid manifests to fail Signed-off-by: Josef Karasek <jkarasek@redhat.com>
1 parent e27c8b3 commit 2bfbe25

File tree

7 files changed

+5989
-35
lines changed

7 files changed

+5989
-35
lines changed

test/e2e/opm_test.go

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ func (bl bundleLocations) images() []string {
6868
return images
6969
}
7070

71-
func inTemporaryBuildContext(f func() error) (rerr error) {
71+
func inTemporaryBuildContext(f func() error, source string) (rerr error) {
7272
td, err := ioutil.TempDir(".", "opm-")
7373
if err != nil {
7474
return err
7575
}
76-
err = copy.Copy("../../manifests", filepath.Join(td, "manifests"))
76+
err = copy.Copy(source, filepath.Join(td, "manifests"))
7777
if err != nil {
7878
return err
7979
}
@@ -218,43 +218,70 @@ func initialize() error {
218218

219219
var _ = Describe("opm", func() {
220220
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())
228235

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())
231252

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+
})
245258

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+
})
250271

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+
})
253283

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+
})
258285
})
259286

260287
It("builds and manipulates bundle and index images", func() {
@@ -268,7 +295,7 @@ var _ = Describe("opm", func() {
268295
for _, b := range bundles {
269296
err = inTemporaryBuildContext(func() error {
270297
return bundle.BuildFunc(b.path, "", b.image, containerTool, packageName, channels, defaultChannel, false)
271-
})
298+
}, "../../manifests")
272299
Expect(err).NotTo(HaveOccurred())
273300
}
274301

0 commit comments

Comments
 (0)