@@ -39,13 +39,13 @@ func TestGetWatchNamespace(t *testing.T) {
39
39
for _ , tt := range []struct {
40
40
name string
41
41
want string
42
- csv * ocv1.ClusterExtension
42
+ ce * ocv1.ClusterExtension
43
43
expectError bool
44
44
}{
45
45
{
46
- name : "cluster extension does not configure a watch namespace " ,
46
+ name : "no watch namespace is configured in a ClusterExtension CR " ,
47
47
want : corev1 .NamespaceAll ,
48
- csv : & ocv1.ClusterExtension {
48
+ ce : & ocv1.ClusterExtension {
49
49
ObjectMeta : metav1.ObjectMeta {
50
50
Name : "extension" ,
51
51
Annotations : nil ,
@@ -54,9 +54,9 @@ func TestGetWatchNamespace(t *testing.T) {
54
54
},
55
55
expectError : false ,
56
56
}, {
57
- name : "cluster extension configures a watch namespace " ,
57
+ name : "a watch namespace is configured in a ClusterExtension CR " ,
58
58
want : "watch-namespace" ,
59
- csv : & ocv1.ClusterExtension {
59
+ ce : & ocv1.ClusterExtension {
60
60
ObjectMeta : metav1.ObjectMeta {
61
61
Name : "extension" ,
62
62
},
@@ -71,63 +71,41 @@ func TestGetWatchNamespace(t *testing.T) {
71
71
},
72
72
expectError : false ,
73
73
}, {
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 {
77
76
ObjectMeta : metav1.ObjectMeta {
78
77
Name : "extension" ,
79
- Annotations : map [string ]string {
80
- "olm.operatorframework.io/watch-namespace" : "watch-namespace" ,
81
- },
82
78
},
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
+ },
103
85
},
104
86
},
105
87
},
106
88
expectError : true ,
107
89
}, {
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 {
111
92
ObjectMeta : metav1.ObjectMeta {
112
93
Name : "extension" ,
113
- Annotations : map [string ]string {
114
- "olm.operatorframework.io/watch-namespace" : "dont-use-this-watch-namespace" ,
115
- },
116
94
},
117
95
Spec : ocv1.ClusterExtensionSpec {
118
96
Config : & ocv1.ClusterExtensionConfig {
119
97
ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
120
98
Inline : & apiextensionsv1.JSON {
121
- Raw : []byte (`{"watchNamespace":"watch-namespace "}` ),
99
+ Raw : []byte (`{"watchNamespace":""}` ),
122
100
},
123
101
},
124
102
},
125
103
},
126
- expectError : false ,
104
+ expectError : true ,
127
105
}, {
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" ,
129
107
want : "" ,
130
- csv : & ocv1.ClusterExtension {
108
+ ce : & ocv1.ClusterExtension {
131
109
ObjectMeta : metav1.ObjectMeta {
132
110
Name : "extension" ,
133
111
},
@@ -142,9 +120,9 @@ func TestGetWatchNamespace(t *testing.T) {
142
120
},
143
121
expectError : true ,
144
122
}, {
145
- name : "cluster extension configures an invalid watchNamespace: invalid name" ,
123
+ name : "an invalid watchNamespace value is configured in a ClusterExtension CR : invalid name" ,
146
124
want : "" ,
147
- csv : & ocv1.ClusterExtension {
125
+ ce : & ocv1.ClusterExtension {
148
126
ObjectMeta : metav1.ObjectMeta {
149
127
Name : "extension" ,
150
128
},
@@ -159,9 +137,9 @@ func TestGetWatchNamespace(t *testing.T) {
159
137
},
160
138
expectError : true ,
161
139
}, {
162
- name : "cluster extension configures an invalid watchNamespace: invalid json" ,
140
+ name : "an invalid watchNamespace value is configured in a ClusterExtension CR : invalid json" ,
163
141
want : "" ,
164
- csv : & ocv1.ClusterExtension {
142
+ ce : & ocv1.ClusterExtension {
165
143
ObjectMeta : metav1.ObjectMeta {
166
144
Name : "extension" ,
167
145
},
@@ -178,7 +156,7 @@ func TestGetWatchNamespace(t *testing.T) {
178
156
},
179
157
} {
180
158
t .Run (tt .name , func (t * testing.T ) {
181
- got , err := applier .GetWatchNamespace (tt .csv )
159
+ got , err := applier .GetWatchNamespace (tt .ce )
182
160
require .Equal (t , tt .want , got )
183
161
require .Equal (t , tt .expectError , err != nil )
184
162
})
0 commit comments