44 "testing"
55
66 "github.com/stretchr/testify/require"
7+ "k8s.io/utils/ptr"
78
89 "github.com/operator-framework/api/pkg/operators/v1alpha1"
910
@@ -25,25 +26,20 @@ func Test_UnmarshallConfig(t *testing.T) {
2526 rawConfig : nil ,
2627 expectedConfig : nil ,
2728 },
28- {
29- name : "rejects nil rv1" ,
30- rawConfig : []byte (`{"watchNamespace": "some-namespace"}` ),
31- expectedErrMessage : `bundle is nil` ,
32- },
3329 {
3430 name : "accepts json config" ,
3531 supportedInstallModes : []v1alpha1.InstallModeType {v1alpha1 .InstallModeTypeSingleNamespace },
3632 rawConfig : []byte (`{"watchNamespace": "some-namespace"}` ),
3733 expectedConfig : & bundle.Config {
38- WatchNamespace : "some-namespace" ,
34+ WatchNamespace : ptr . To ( "some-namespace" ) ,
3935 },
4036 },
4137 {
4238 name : "accepts yaml config" ,
4339 supportedInstallModes : []v1alpha1.InstallModeType {v1alpha1 .InstallModeTypeSingleNamespace },
4440 rawConfig : []byte (`watchNamespace: some-namespace` ),
4541 expectedConfig : & bundle.Config {
46- WatchNamespace : "some-namespace" ,
42+ WatchNamespace : ptr . To ( "some-namespace" ) ,
4743 },
4844 },
4945 {
@@ -111,23 +107,23 @@ func Test_UnmarshallConfig(t *testing.T) {
111107 supportedInstallModes : []v1alpha1.InstallModeType {v1alpha1 .InstallModeTypeSingleNamespace },
112108 rawConfig : []byte (`{"watchNamespace": "some-namespace"}` ),
113109 expectedConfig : & bundle.Config {
114- WatchNamespace : "some-namespace" ,
110+ WatchNamespace : ptr . To ( "some-namespace" ) ,
115111 },
116112 },
117113 {
118114 name : "accepts when install modes {AllNamespaces, SingleNamespace} and watchNamespace != install namespace" ,
119115 supportedInstallModes : []v1alpha1.InstallModeType {v1alpha1 .InstallModeTypeAllNamespaces , v1alpha1 .InstallModeTypeSingleNamespace },
120116 rawConfig : []byte (`{"watchNamespace": "some-namespace"}` ),
121117 expectedConfig : & bundle.Config {
122- WatchNamespace : "some-namespace" ,
118+ WatchNamespace : ptr . To ( "some-namespace" ) ,
123119 },
124120 },
125121 {
126122 name : "accepts when install modes {MultiNamespace, SingleNamespace} and watchNamespace != install namespace" ,
127123 supportedInstallModes : []v1alpha1.InstallModeType {v1alpha1 .InstallModeTypeMultiNamespace , v1alpha1 .InstallModeTypeSingleNamespace },
128124 rawConfig : []byte (`{"watchNamespace": "some-namespace"}` ),
129125 expectedConfig : & bundle.Config {
130- WatchNamespace : "some-namespace" ,
126+ WatchNamespace : ptr . To ( "some-namespace" ) ,
131127 },
132128 },
133129 {
@@ -136,7 +132,7 @@ func Test_UnmarshallConfig(t *testing.T) {
136132 rawConfig : []byte (`{"watchNamespace": "some-namespace"}` ),
137133 installNamespace : "not-namespace" ,
138134 expectedConfig : & bundle.Config {
139- WatchNamespace : "some-namespace" ,
135+ WatchNamespace : ptr . To ( "some-namespace" ) ,
140136 },
141137 },
142138 {
@@ -166,7 +162,7 @@ func Test_UnmarshallConfig(t *testing.T) {
166162 rawConfig : []byte (`{"watchNamespace": "some-namespace"}` ),
167163 installNamespace : "some-namespace" ,
168164 expectedConfig : & bundle.Config {
169- WatchNamespace : "some-namespace" ,
165+ WatchNamespace : ptr . To ( "some-namespace" ) ,
170166 },
171167 },
172168 {
@@ -175,7 +171,7 @@ func Test_UnmarshallConfig(t *testing.T) {
175171 rawConfig : []byte (`{"watchNamespace": "some-namespace"}` ),
176172 installNamespace : "some-namespace" ,
177173 expectedConfig : & bundle.Config {
178- WatchNamespace : "some-namespace" ,
174+ WatchNamespace : ptr . To ( "some-namespace" ) ,
179175 },
180176 },
181177 {
@@ -185,11 +181,64 @@ func Test_UnmarshallConfig(t *testing.T) {
185181 installNamespace : "not-some-namespace" ,
186182 expectedErrMessage : "invalid 'watchNamespace' \" some-namespace\" : must be install namespace (not-some-namespace)" ,
187183 },
184+ {
185+ name : "rejects with required field error when install modes {SingleNamespace} and watchNamespace is nil" ,
186+ supportedInstallModes : []v1alpha1.InstallModeType {v1alpha1 .InstallModeTypeSingleNamespace },
187+ rawConfig : []byte (`{"watchNamespace": null}` ),
188+ installNamespace : "not-some-namespace" ,
189+ expectedErrMessage : "required field \" watchNamespace\" is missing" ,
190+ },
191+ {
192+ name : "rejects with required field error when install modes {SingleNamespace, OwnNamespace} and watchNamespace is nil" ,
193+ supportedInstallModes : []v1alpha1.InstallModeType {v1alpha1 .InstallModeTypeSingleNamespace , v1alpha1 .InstallModeTypeOwnNamespace },
194+ rawConfig : []byte (`{"watchNamespace": null}` ),
195+ installNamespace : "not-some-namespace" ,
196+ expectedErrMessage : "required field \" watchNamespace\" is missing" ,
197+ },
198+ {
199+ name : "rejects with required field error when install modes {SingleNamespace, MultiNamespace} and watchNamespace is nil" ,
200+ supportedInstallModes : []v1alpha1.InstallModeType {v1alpha1 .InstallModeTypeSingleNamespace , v1alpha1 .InstallModeTypeMultiNamespace },
201+ rawConfig : []byte (`{"watchNamespace": null}` ),
202+ installNamespace : "not-some-namespace" ,
203+ expectedErrMessage : "required field \" watchNamespace\" is missing" ,
204+ },
205+ {
206+ name : "rejects with required field error when install modes {SingleNamespace, OwnNamespace, MultiNamespace} and watchNamespace is nil" ,
207+ supportedInstallModes : []v1alpha1.InstallModeType {v1alpha1 .InstallModeTypeSingleNamespace , v1alpha1 .InstallModeTypeOwnNamespace , v1alpha1 .InstallModeTypeMultiNamespace },
208+ rawConfig : []byte (`{"watchNamespace": null}` ),
209+ installNamespace : "not-some-namespace" ,
210+ expectedErrMessage : "required field \" watchNamespace\" is missing" ,
211+ },
212+ {
213+ name : "accepts null watchNamespace when install modes {AllNamespaces, OwnNamespace} and watchNamespace is nil" ,
214+ supportedInstallModes : []v1alpha1.InstallModeType {v1alpha1 .InstallModeTypeAllNamespaces , v1alpha1 .InstallModeTypeOwnNamespace },
215+ rawConfig : []byte (`{"watchNamespace": null}` ),
216+ installNamespace : "not-some-namespace" ,
217+ expectedConfig : & bundle.Config {
218+ WatchNamespace : nil ,
219+ },
220+ },
221+ {
222+ name : "accepts null watchNamespace when install modes {AllNamespaces, OwnNamespace, MultiNamespace} and watchNamespace is nil" ,
223+ supportedInstallModes : []v1alpha1.InstallModeType {v1alpha1 .InstallModeTypeAllNamespaces , v1alpha1 .InstallModeTypeOwnNamespace , v1alpha1 .InstallModeTypeMultiNamespace },
224+ rawConfig : []byte (`{"watchNamespace": null}` ),
225+ installNamespace : "not-some-namespace" ,
226+ expectedConfig : & bundle.Config {
227+ WatchNamespace : nil ,
228+ },
229+ },
230+ {
231+ name : "rejects with format error when install modes are {SingleNamespace, OwnNamespace} and watchNamespace is ''" ,
232+ supportedInstallModes : []v1alpha1.InstallModeType {v1alpha1 .InstallModeTypeSingleNamespace , v1alpha1 .InstallModeTypeOwnNamespace },
233+ rawConfig : []byte (`{"watchNamespace": ""}` ),
234+ installNamespace : "not-some-namespace" ,
235+ expectedErrMessage : "invalid 'watchNamespace' \" \" : namespace must consist of lower case alphanumeric characters" ,
236+ },
188237 } {
189238 t .Run (tc .name , func (t * testing.T ) {
190- var rv1 * bundle.RegistryV1
239+ var rv1 bundle.RegistryV1
191240 if tc .supportedInstallModes != nil {
192- rv1 = & bundle.RegistryV1 {
241+ rv1 = bundle.RegistryV1 {
193242 CSV : clusterserviceversion .Builder ().
194243 WithName ("test-operator" ).
195244 WithInstallModeSupportFor (tc .supportedInstallModes ... ).
0 commit comments