@@ -2,11 +2,13 @@ package images
22
33import (
44 "context"
5+ "fmt"
56 "time"
67
78 g "github.com/onsi/ginkgo/v2"
89 o "github.com/onsi/gomega"
910
11+ apierrors "k8s.io/apimachinery/pkg/api/errors"
1012 admissionapi "k8s.io/pod-security-admission/api"
1113 "k8s.io/apimachinery/pkg/util/wait"
1214
@@ -76,4 +78,26 @@ var _ = g.Describe("[sig-imageregistry] Image --dry-run", func() {
7678 o .Expect (err ).NotTo (o .HaveOccurred ())
7779 o .Expect (output ).To (o .BeEmpty ())
7880 })
81+
82+ g .It ("should not create resources [apigroup:image.openshift.io]" , func () {
83+ g .By ("triggering create operation of imagestream with --dry-run=server" )
84+ err := oc .Run ("create" ).Args ("imagestream" , "dryrun-test" , "--dry-run=server" ).Execute ()
85+ o .Expect (err ).NotTo (o .HaveOccurred ())
86+
87+ // wait for 10s to make sure we'll not miss any resource created accidentally
88+ err = wait .PollUntilContextTimeout (context .Background (), 1 * time .Second , 10 * time .Second , true , func (ctx context.Context ) (bool , error ) {
89+ _ , err := oc .Run ("get" ).Args ("imagestream" , "dryrun-test" , "-o" , "jsonpath={.metadata.name}" ).Output ()
90+ if err == nil {
91+ return false , fmt .Errorf ("imagestream was created when it shouldn't have been" )
92+ }
93+ return false , nil
94+ })
95+ // polling must timeout otherwise it means we found the object
96+ o .Expect (err ).To (o .Equal (context .DeadlineExceeded ))
97+
98+ g .By ("the test imagestream must not exist" )
99+ _ , err = oc .Run ("get" ).Args ("imagestream" , "dryrun-test" , "-o" , "jsonpath={.image.metadata.name}" ).Output ()
100+ o .Expect (err ).To (o .HaveOccurred ())
101+ o .Expect (apierrors .IsNotFound (err )).To (o .BeTrue (), fmt .Sprintf ("expected NotFound error, got: %v" , err ))
102+ })
79103})
0 commit comments