@@ -173,7 +173,130 @@ func TestStatefulSet_IsCorrectlyConfigured(t *testing.T) {
173
173
assert .NoError (t , err )
174
174
assert .NotNil (t , acVolume .Secret , "automation config should be stored in a secret!" )
175
175
assert .Nil (t , acVolume .ConfigMap , "automation config should be stored in a secret, not a config map!" )
176
+ }
176
177
178
+ func TestGuessEnterprise (t * testing.T ) {
179
+ type testConfig struct {
180
+ setArgs func (t * testing.T )
181
+ mdb mdbv1.MongoDBCommunity
182
+ expectedEnterprise bool
183
+ }
184
+ tests := map [string ]testConfig {
185
+ "No override and Community image" : {
186
+ setArgs : func (t * testing.T ) {
187
+ t .Setenv (construct .MongodbRepoUrl , "docker.io/mongodb" )
188
+ t .Setenv (construct .MongodbImageEnv , "mongodb-community-server" )
189
+ },
190
+ mdb : mdbv1.MongoDBCommunity {},
191
+ expectedEnterprise : false ,
192
+ },
193
+ "No override and Enterprise image" : {
194
+ setArgs : func (t * testing.T ) {
195
+ t .Setenv (construct .MongodbRepoUrl , "docker.io/mongodb" )
196
+ t .Setenv (construct .MongodbImageEnv , "mongodb-enterprise-server" )
197
+ },
198
+ mdb : mdbv1.MongoDBCommunity {},
199
+ expectedEnterprise : true ,
200
+ },
201
+ "Assuming enterprise manually" : {
202
+ setArgs : func (t * testing.T ) {
203
+ t .Setenv (construct .MongodbRepoUrl , "docker.io/mongodb" )
204
+ t .Setenv (construct .MongodbImageEnv , "mongodb-community-server" )
205
+ t .Setenv (construct .MongoDBAssumeEnterpriseEnv , "true" )
206
+ },
207
+ mdb : mdbv1.MongoDBCommunity {},
208
+ expectedEnterprise : true ,
209
+ },
210
+ "Assuming community manually" : {
211
+ setArgs : func (t * testing.T ) {
212
+ t .Setenv (construct .MongodbRepoUrl , "docker.io/mongodb" )
213
+ t .Setenv (construct .MongodbImageEnv , "mongodb-enterprise-server" )
214
+ t .Setenv (construct .MongoDBAssumeEnterpriseEnv , "false" )
215
+ },
216
+ mdb : mdbv1.MongoDBCommunity {},
217
+ expectedEnterprise : false ,
218
+ },
219
+ "Enterprise with different repo" : {
220
+ setArgs : func (t * testing.T ) {
221
+ t .Setenv (construct .MongodbRepoUrl , "some_other_repo.com/some_other_org" )
222
+ t .Setenv (construct .MongodbImageEnv , "mongodb-enterprise-server" )
223
+ },
224
+ mdb : mdbv1.MongoDBCommunity {},
225
+ expectedEnterprise : true ,
226
+ },
227
+ "Community with different repo" : {
228
+ setArgs : func (t * testing.T ) {
229
+ t .Setenv (construct .MongodbRepoUrl , "some_other_repo.com/some_other_org" )
230
+ t .Setenv (construct .MongodbImageEnv , "mongodb-community-server" )
231
+ },
232
+ mdb : mdbv1.MongoDBCommunity {},
233
+ expectedEnterprise : false ,
234
+ },
235
+ // This one is a corner case. We don't expect users to fall here very often as there are
236
+ // dedicated variables to control this type of behavior.
237
+ "Enterprise with StatefulSet override" : {
238
+ setArgs : func (t * testing.T ) {
239
+ t .Setenv (construct .MongodbRepoUrl , "some_other_repo.com/some_other_org" )
240
+ t .Setenv (construct .MongodbImageEnv , "mongodb-community-server" )
241
+ },
242
+ mdb : mdbv1.MongoDBCommunity {
243
+ Spec : mdbv1.MongoDBCommunitySpec {
244
+ StatefulSetConfiguration : mdbv1.StatefulSetConfiguration {
245
+ SpecWrapper : mdbv1.StatefulSetSpecWrapper {
246
+ Spec : appsv1.StatefulSetSpec {
247
+ Template : corev1.PodTemplateSpec {
248
+ Spec : corev1.PodSpec {
249
+ Containers : []corev1.Container {
250
+ {
251
+ Name : construct .MongodbName ,
252
+ Image : "another_repo.com/another_org/mongodb-enterprise-server" ,
253
+ },
254
+ },
255
+ },
256
+ },
257
+ },
258
+ },
259
+ },
260
+ },
261
+ },
262
+ expectedEnterprise : true ,
263
+ },
264
+ "Enterprise with StatefulSet override to Community" : {
265
+ setArgs : func (t * testing.T ) {
266
+ t .Setenv (construct .MongodbRepoUrl , "some_other_repo.com/some_other_org" )
267
+ t .Setenv (construct .MongodbImageEnv , "mongodb-enterprise-server" )
268
+ },
269
+ mdb : mdbv1.MongoDBCommunity {
270
+ Spec : mdbv1.MongoDBCommunitySpec {
271
+ StatefulSetConfiguration : mdbv1.StatefulSetConfiguration {
272
+ SpecWrapper : mdbv1.StatefulSetSpecWrapper {
273
+ Spec : appsv1.StatefulSetSpec {
274
+ Template : corev1.PodTemplateSpec {
275
+ Spec : corev1.PodSpec {
276
+ Containers : []corev1.Container {
277
+ {
278
+ Name : construct .MongodbName ,
279
+ Image : "another_repo.com/another_org/mongodb-community-server" ,
280
+ },
281
+ },
282
+ },
283
+ },
284
+ },
285
+ },
286
+ },
287
+ },
288
+ },
289
+ expectedEnterprise : false ,
290
+ },
291
+ }
292
+ for testName := range tests {
293
+ t .Run (testName , func (t * testing.T ) {
294
+ testConfig := tests [testName ]
295
+ testConfig .setArgs (t )
296
+ calculatedEnterprise := guessEnterprise (testConfig .mdb )
297
+ assert .Equal (t , testConfig .expectedEnterprise , calculatedEnterprise )
298
+ })
299
+ }
177
300
}
178
301
179
302
func getVolumeByName (sts appsv1.StatefulSet , volumeName string ) (corev1.Volume , error ) {
0 commit comments