From 15f0885328d43f8dfe0127dc5548e4b883f0ceea Mon Sep 17 00:00:00 2001 From: Ilias Rinis Date: Tue, 21 Oct 2025 10:16:40 +0200 Subject: [PATCH] images: test that creating an imagestream with --dry-run does not actually create the object --- test/extended/images/dryrun.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/extended/images/dryrun.go b/test/extended/images/dryrun.go index 7b146cc50d08..1cb401fbcc3f 100644 --- a/test/extended/images/dryrun.go +++ b/test/extended/images/dryrun.go @@ -2,11 +2,13 @@ package images import ( "context" + "fmt" "time" g "github.com/onsi/ginkgo/v2" o "github.com/onsi/gomega" + apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/util/wait" admissionapi "k8s.io/pod-security-admission/api" @@ -76,4 +78,26 @@ var _ = g.Describe("[sig-imageregistry] Image --dry-run", func() { o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(output).To(o.BeEmpty()) }) + + g.It("should not create resources [apigroup:image.openshift.io]", func() { + g.By("triggering create operation of imagestream with --dry-run=server") + err := oc.Run("create").Args("imagestream", "dryrun-test", "--dry-run=server").Execute() + o.Expect(err).NotTo(o.HaveOccurred()) + + // wait for 10s to make sure we'll not miss any resource created accidentally + err = wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + _, err := oc.Run("get").Args("imagestream", "dryrun-test", "-o", "jsonpath={.metadata.name}").Output() + if err == nil { + return false, fmt.Errorf("imagestream was created when it shouldn't have been") + } + return false, nil + }) + // polling must timeout otherwise it means we found the object + o.Expect(err).To(o.Equal(context.DeadlineExceeded)) + + g.By("the test imagestream must not exist") + _, err = oc.Run("get").Args("imagestream", "dryrun-test", "-o", "jsonpath={.image.metadata.name}").Output() + o.Expect(err).To(o.HaveOccurred()) + o.Expect(apierrors.IsNotFound(err)).To(o.BeTrue(), fmt.Sprintf("expected NotFound error, got: %v", err)) + }) })