Skip to content

Commit 033e738

Browse files
committed
adding test case to produce panic when csv.releateImages is empty
Signed-off-by: Adam D. Cornett <adc@redhat.com>
1 parent d25e6bf commit 033e738

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

internal/policy/operator/certified_images_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,30 @@ spec:
215215
Expect(result).To(BeFalse())
216216
})
217217
})
218+
When("the CSV has empty relatedImages entries", func() {
219+
It("should handle gracefully without panicking", func() {
220+
csvContents := `kind: ClusterServiceVersion
221+
apiVersion: operators.coreos.com/v1alpha1
222+
spec:
223+
install:
224+
spec:
225+
deployments:
226+
- spec:
227+
template:
228+
spec:
229+
containers:
230+
- image: registry.example.io/foo/bar@sha256:f000432f07cd187469f0310e3ed9dcf9a5db2be14b8bab9c5293dd1ee8518176
231+
name: the-operator
232+
relatedImages:
233+
- name: the-operator
234+
image: registry.example.io/foo/bar@sha256:f000432f07cd187469f0310e3ed9dcf9a5db2be14b8bab9c5293dd1ee8518176
235+
- name: ''
236+
image: ''`
237+
Expect(os.WriteFile(filepath.Join(imageRef.ImageFSPath, manifestsDir, clusterServiceVersionFilename), []byte(csvContents), 0o644)).To(Succeed())
238+
result, err := certifiedImagesCheck.Validate(context.TODO(), imageRef)
239+
Expect(err).ToNot(HaveOccurred())
240+
Expect(result).To(BeTrue())
241+
})
242+
})
218243
AssertMetaData(certifiedImagesCheck)
219244
})

0 commit comments

Comments
 (0)