@@ -289,7 +289,7 @@ func Test_RegistryV1ManifestProvider_SingleOwnNamespaceSupport(t *testing.T) {
289289 require .Contains (t , err .Error (), "unsupported bundle" )
290290 })
291291
292- t .Run ("accepts bundles without AllNamespaces install mode and with SingleNamespace support when Single/OwnNamespace install mode support is enabled " , func (t * testing.T ) {
292+ t .Run ("accepts bundles with install modes { SingleNamespace} when the appropriate configuration is given " , func (t * testing.T ) {
293293 expectedWatchNamespace := "some-namespace"
294294 provider := applier.RegistryV1ManifestProvider {
295295 BundleRenderer : render.BundleRenderer {
@@ -321,7 +321,34 @@ func Test_RegistryV1ManifestProvider_SingleOwnNamespaceSupport(t *testing.T) {
321321 require .NoError (t , err )
322322 })
323323
324- t .Run ("accepts bundles without AllNamespaces install mode and with OwnNamespace support when Single/OwnNamespace install mode support is enabled" , func (t * testing.T ) {
324+ t .Run ("rejects bundles with {SingleNamespace} install modes when no configuration is given" , func (t * testing.T ) {
325+ expectedWatchNamespace := "some-namespace"
326+ provider := applier.RegistryV1ManifestProvider {
327+ BundleRenderer : render.BundleRenderer {
328+ ResourceGenerators : []render.ResourceGenerator {
329+ func (rv1 * bundle.RegistryV1 , opts render.Options ) ([]client.Object , error ) {
330+ t .Log ("ensure watch namespace is appropriately configured" )
331+ require .Equal (t , []string {expectedWatchNamespace }, opts .TargetNamespaces )
332+ return nil , nil
333+ },
334+ },
335+ },
336+ IsSingleOwnNamespaceEnabled : true ,
337+ }
338+
339+ bundleFS := bundlefs .Builder ().WithPackageName ("test" ).
340+ WithCSV (clusterserviceversion .Builder ().WithInstallModeSupportFor (v1alpha1 .InstallModeTypeSingleNamespace ).Build ()).Build ()
341+
342+ _ , err := provider .Get (bundleFS , & ocv1.ClusterExtension {
343+ Spec : ocv1.ClusterExtensionSpec {
344+ Namespace : "install-namespace" ,
345+ },
346+ })
347+ require .Error (t , err )
348+ require .Contains (t , err .Error (), "required field \" watchNamespace\" is missing" )
349+ })
350+
351+ t .Run ("accepts bundles with {OwnNamespace} install modes when the appropriate configuration is given" , func (t * testing.T ) {
325352 provider := applier.RegistryV1ManifestProvider {
326353 IsSingleOwnNamespaceEnabled : true ,
327354 }
@@ -330,11 +357,53 @@ func Test_RegistryV1ManifestProvider_SingleOwnNamespaceSupport(t *testing.T) {
330357 _ , err := provider .Get (bundleFS , & ocv1.ClusterExtension {
331358 Spec : ocv1.ClusterExtensionSpec {
332359 Namespace : "install-namespace" ,
360+ Config : & ocv1.ClusterExtensionConfig {
361+ ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
362+ Inline : & apiextensionsv1.JSON {
363+ Raw : []byte (`{"watchNamespace": "install-namespace"}` ),
364+ },
365+ },
333366 },
334367 })
335368 require .NoError (t , err )
336369 })
337370
371+ t .Run ("rejects bundles with {OwnNamespace} install modes when no configuration is given" , func (t * testing.T ) {
372+ provider := applier.RegistryV1ManifestProvider {
373+ IsSingleOwnNamespaceEnabled : true ,
374+ }
375+ bundleFS := bundlefs .Builder ().WithPackageName ("test" ).
376+ WithCSV (clusterserviceversion .Builder ().WithInstallModeSupportFor (v1alpha1 .InstallModeTypeOwnNamespace ).Build ()).Build ()
377+ _ , err := provider .Get (bundleFS , & ocv1.ClusterExtension {
378+ Spec : ocv1.ClusterExtensionSpec {
379+ Namespace : "install-namespace" ,
380+ },
381+ })
382+ require .Error (t , err )
383+ require .Contains (t , err .Error (), "required field \" watchNamespace\" is missing" )
384+ })
385+
386+ t .Run ("rejects bundles with {OwnNamespace} install modes when watchNamespace is not install namespace" , func (t * testing.T ) {
387+ provider := applier.RegistryV1ManifestProvider {
388+ IsSingleOwnNamespaceEnabled : true ,
389+ }
390+ bundleFS := bundlefs .Builder ().WithPackageName ("test" ).
391+ WithCSV (clusterserviceversion .Builder ().WithInstallModeSupportFor (v1alpha1 .InstallModeTypeOwnNamespace ).Build ()).Build ()
392+ _ , err := provider .Get (bundleFS , & ocv1.ClusterExtension {
393+ Spec : ocv1.ClusterExtensionSpec {
394+ Namespace : "install-namespace" ,
395+ Config : & ocv1.ClusterExtensionConfig {
396+ ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
397+ Inline : & apiextensionsv1.JSON {
398+ Raw : []byte (`{"watchNamespace": "not-install-namespace"}` ),
399+ },
400+ },
401+ },
402+ })
403+ require .Error (t , err )
404+ require .Contains (t , err .Error (), "invalid 'watchNamespace' \" not-install-namespace\" : must be install namespace (install-namespace)" )
405+ })
406+
338407 t .Run ("rejects bundles without AllNamespaces, SingleNamespace, or OwnNamespace install mode support when Single/OwnNamespace install mode support is enabled" , func (t * testing.T ) {
339408 provider := applier.RegistryV1ManifestProvider {
340409 IsSingleOwnNamespaceEnabled : true ,
0 commit comments