@@ -39,13 +39,13 @@ func TestGetWatchNamespace(t *testing.T) {
3939 for _ , tt := range []struct {
4040 name string
4141 want string
42- csv * ocv1.ClusterExtension
42+ ce * ocv1.ClusterExtension
4343 expectError bool
4444 }{
4545 {
46- name : "cluster extension does not configure a watch namespace " ,
46+ name : "no watch namespace is configured in a ClusterExtension CR " ,
4747 want : corev1 .NamespaceAll ,
48- csv : & ocv1.ClusterExtension {
48+ ce : & ocv1.ClusterExtension {
4949 ObjectMeta : metav1.ObjectMeta {
5050 Name : "extension" ,
5151 Annotations : nil ,
@@ -54,9 +54,9 @@ func TestGetWatchNamespace(t *testing.T) {
5454 },
5555 expectError : false ,
5656 }, {
57- name : "cluster extension configures a watch namespace " ,
57+ name : "a watch namespace is configured in a ClusterExtension CR " ,
5858 want : "watch-namespace" ,
59- csv : & ocv1.ClusterExtension {
59+ ce : & ocv1.ClusterExtension {
6060 ObjectMeta : metav1.ObjectMeta {
6161 Name : "extension" ,
6262 },
@@ -71,63 +71,41 @@ func TestGetWatchNamespace(t *testing.T) {
7171 },
7272 expectError : false ,
7373 }, {
74- name : "cluster extension configures a watch namespace through annotation" ,
75- want : "watch-namespace" ,
76- csv : & ocv1.ClusterExtension {
74+ name : "a watch namespace is configured in a ClusterExtension CR but with invalid namespace" ,
75+ ce : & ocv1.ClusterExtension {
7776 ObjectMeta : metav1.ObjectMeta {
7877 Name : "extension" ,
79- Annotations : map [string ]string {
80- "olm.operatorframework.io/watch-namespace" : "watch-namespace" ,
81- },
8278 },
83- },
84- expectError : false ,
85- }, {
86- name : "cluster extension configures a watch namespace through annotation with invalid ns" ,
87- csv : & ocv1.ClusterExtension {
88- ObjectMeta : metav1.ObjectMeta {
89- Name : "extension" ,
90- Annotations : map [string ]string {
91- "olm.operatorframework.io/watch-namespace" : "watch-namespace-" ,
92- },
93- },
94- },
95- expectError : true ,
96- }, {
97- name : "cluster extension configures a watch namespace through annotation with empty ns" ,
98- csv : & ocv1.ClusterExtension {
99- ObjectMeta : metav1.ObjectMeta {
100- Name : "extension" ,
101- Annotations : map [string ]string {
102- "olm.operatorframework.io/watch-namespace" : "" ,
79+ Spec : ocv1.ClusterExtensionSpec {
80+ Config : & ocv1.ClusterExtensionConfig {
81+ ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
82+ Inline : & apiextensionsv1.JSON {
83+ Raw : []byte (`{"watchNamespace":"watch-namespace-"}` ),
84+ },
10385 },
10486 },
10587 },
10688 expectError : true ,
10789 }, {
108- name : "cluster extension configures a watch namespace through annotation and config (take config)" ,
109- want : "watch-namespace" ,
110- csv : & ocv1.ClusterExtension {
90+ name : "a watch namespace is configured in a ClusterExtension CR with an empty string as the namespace" ,
91+ ce : & ocv1.ClusterExtension {
11192 ObjectMeta : metav1.ObjectMeta {
11293 Name : "extension" ,
113- Annotations : map [string ]string {
114- "olm.operatorframework.io/watch-namespace" : "dont-use-this-watch-namespace" ,
115- },
11694 },
11795 Spec : ocv1.ClusterExtensionSpec {
11896 Config : & ocv1.ClusterExtensionConfig {
11997 ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
12098 Inline : & apiextensionsv1.JSON {
121- Raw : []byte (`{"watchNamespace":"watch-namespace "}` ),
99+ Raw : []byte (`{"watchNamespace":""}` ),
122100 },
123101 },
124102 },
125103 },
126- expectError : false ,
104+ expectError : true ,
127105 }, {
128- name : "cluster extension configures an invalid watchNamespace: multiple watch namespaces" ,
106+ name : "an invalid watchNamespace value is configured in a ClusterExtension CR : multiple watch namespaces" ,
129107 want : "" ,
130- csv : & ocv1.ClusterExtension {
108+ ce : & ocv1.ClusterExtension {
131109 ObjectMeta : metav1.ObjectMeta {
132110 Name : "extension" ,
133111 },
@@ -142,9 +120,9 @@ func TestGetWatchNamespace(t *testing.T) {
142120 },
143121 expectError : true ,
144122 }, {
145- name : "cluster extension configures an invalid watchNamespace: invalid name" ,
123+ name : "an invalid watchNamespace value is configured in a ClusterExtension CR : invalid name" ,
146124 want : "" ,
147- csv : & ocv1.ClusterExtension {
125+ ce : & ocv1.ClusterExtension {
148126 ObjectMeta : metav1.ObjectMeta {
149127 Name : "extension" ,
150128 },
@@ -159,9 +137,9 @@ func TestGetWatchNamespace(t *testing.T) {
159137 },
160138 expectError : true ,
161139 }, {
162- name : "cluster extension configures an invalid watchNamespace: invalid json" ,
140+ name : "an invalid watchNamespace value is configured in a ClusterExtension CR : invalid json" ,
163141 want : "" ,
164- csv : & ocv1.ClusterExtension {
142+ ce : & ocv1.ClusterExtension {
165143 ObjectMeta : metav1.ObjectMeta {
166144 Name : "extension" ,
167145 },
@@ -178,7 +156,7 @@ func TestGetWatchNamespace(t *testing.T) {
178156 },
179157 } {
180158 t .Run (tt .name , func (t * testing.T ) {
181- got , err := applier .GetWatchNamespace (tt .csv )
159+ got , err := applier .GetWatchNamespace (tt .ce )
182160 require .Equal (t , tt .want , got )
183161 require .Equal (t , tt .expectError , err != nil )
184162 })
0 commit comments