@@ -5,26 +5,31 @@ import (
55
66 "github.com/stretchr/testify/require"
77 corev1 "k8s.io/api/core/v1"
8+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
89 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910 featuregatetesting "k8s.io/component-base/featuregate/testing"
1011
11- v1 "github.com/operator-framework/operator-controller/api/v1"
12+ ocv1 "github.com/operator-framework/operator-controller/api/v1"
1213 "github.com/operator-framework/operator-controller/internal/operator-controller/applier"
1314 "github.com/operator-framework/operator-controller/internal/operator-controller/features"
1415)
1516
1617func TestGetWatchNamespacesWhenFeatureGateIsDisabled (t * testing.T ) {
17- watchNamespace , err := applier .GetWatchNamespace (& v1 .ClusterExtension {
18+ watchNamespace , err := applier .GetWatchNamespace (& ocv1 .ClusterExtension {
1819 ObjectMeta : metav1.ObjectMeta {
1920 Name : "extension" ,
20- Annotations : map [string ]string {
21- "olm.operatorframework.io/watch-namespace" : "watch-namespace" ,
21+ },
22+ Spec : ocv1.ClusterExtensionSpec {
23+ Config : & ocv1.ClusterExtensionConfig {
24+ ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
25+ Inline : & apiextensionsv1.JSON {
26+ Raw : []byte (`{"watchNamespace":"watch-namespace"}` ),
27+ },
2228 },
2329 },
24- Spec : v1.ClusterExtensionSpec {},
2530 })
2631 require .NoError (t , err )
27- t .Log ("Check watchNamespace is '' even if the annotation is set" )
32+ t .Log ("Check watchNamespace is '' even if the configuration is set" )
2833 require .Equal (t , corev1 .NamespaceAll , watchNamespace )
2934}
3035
@@ -34,57 +39,86 @@ func TestGetWatchNamespace(t *testing.T) {
3439 for _ , tt := range []struct {
3540 name string
3641 want string
37- csv * v1 .ClusterExtension
42+ csv * ocv1 .ClusterExtension
3843 expectError bool
3944 }{
4045 {
41- name : "cluster extension does not have watch namespace annotation " ,
46+ name : "cluster extension does not configure a watch namespace" ,
4247 want : corev1 .NamespaceAll ,
43- csv : & v1 .ClusterExtension {
48+ csv : & ocv1 .ClusterExtension {
4449 ObjectMeta : metav1.ObjectMeta {
4550 Name : "extension" ,
4651 Annotations : nil ,
4752 },
48- Spec : v1 .ClusterExtensionSpec {},
53+ Spec : ocv1 .ClusterExtensionSpec {},
4954 },
5055 expectError : false ,
5156 }, {
52- name : "cluster extension has valid namespace annotation " ,
57+ name : "cluster extension configures a watch namespace " ,
5358 want : "watch-namespace" ,
54- csv : & v1 .ClusterExtension {
59+ csv : & ocv1 .ClusterExtension {
5560 ObjectMeta : metav1.ObjectMeta {
5661 Name : "extension" ,
57- Annotations : map [string ]string {
58- "olm.operatorframework.io/watch-namespace" : "watch-namespace" ,
62+ },
63+ Spec : ocv1.ClusterExtensionSpec {
64+ Config : & ocv1.ClusterExtensionConfig {
65+ ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
66+ Inline : & apiextensionsv1.JSON {
67+ Raw : []byte (`{"watchNamespace":"watch-namespace"}` ),
68+ },
5969 },
6070 },
61- Spec : v1.ClusterExtensionSpec {},
6271 },
6372 expectError : false ,
6473 }, {
65- name : "cluster extension has invalid namespace annotation: multiple watch namespaces" ,
74+ name : "cluster extension configures an invalid watchNamespace: multiple watch namespaces" ,
75+ want : "" ,
76+ csv : & ocv1.ClusterExtension {
77+ ObjectMeta : metav1.ObjectMeta {
78+ Name : "extension" ,
79+ },
80+ Spec : ocv1.ClusterExtensionSpec {
81+ Config : & ocv1.ClusterExtensionConfig {
82+ ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
83+ Inline : & apiextensionsv1.JSON {
84+ Raw : []byte (`{"watchNamespace":"watch-namespace,watch-namespace2,watch-namespace3"}` ),
85+ },
86+ },
87+ },
88+ },
89+ expectError : true ,
90+ }, {
91+ name : "cluster extension configures an invalid watchNamespace: invalid name" ,
6692 want : "" ,
67- csv : & v1 .ClusterExtension {
93+ csv : & ocv1 .ClusterExtension {
6894 ObjectMeta : metav1.ObjectMeta {
6995 Name : "extension" ,
70- Annotations : map [string ]string {
71- "olm.operatorframework.io/watch-namespace" : "watch-namespace,watch-namespace2,watch-namespace3" ,
96+ },
97+ Spec : ocv1.ClusterExtensionSpec {
98+ Config : & ocv1.ClusterExtensionConfig {
99+ ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
100+ Inline : & apiextensionsv1.JSON {
101+ Raw : []byte (`{"watchNamespace":"watch-namespace-"}` ),
102+ },
72103 },
73104 },
74- Spec : v1.ClusterExtensionSpec {},
75105 },
76106 expectError : true ,
77107 }, {
78- name : "cluster extension has invalid namespace annotation : invalid name " ,
108+ name : "cluster extension configures an invalid watchNamespace : invalid json " ,
79109 want : "" ,
80- csv : & v1 .ClusterExtension {
110+ csv : & ocv1 .ClusterExtension {
81111 ObjectMeta : metav1.ObjectMeta {
82112 Name : "extension" ,
83- Annotations : map [string ]string {
84- "olm.operatorframework.io/watch-namespace" : "watch-namespace-" ,
113+ },
114+ Spec : ocv1.ClusterExtensionSpec {
115+ Config : & ocv1.ClusterExtensionConfig {
116+ ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
117+ Inline : & apiextensionsv1.JSON {
118+ Raw : []byte (`invalid json` ),
119+ },
85120 },
86121 },
87- Spec : v1.ClusterExtensionSpec {},
88122 },
89123 expectError : true ,
90124 },
0 commit comments