Skip to content

Commit a4122d6

Browse files
committed
Update unit tests
1 parent dbbc3d3 commit a4122d6

6 files changed

+40
-40
lines changed

controllers/operator/authentication_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestX509CanBeEnabled_WhenThereAreOnlyTlsDeployments_ReplicaSet(t *testing.T
4747

4848
addKubernetesTlsResources(ctx, kubeClient, rs)
4949

50-
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
50+
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
5151
checkReconcileSuccessful(ctx, t, reconciler, rs, kubeClient)
5252
}
5353

@@ -57,7 +57,7 @@ func TestX509ClusterAuthentication_CanBeEnabled_IfX509AuthenticationIsEnabled_Re
5757
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
5858
addKubernetesTlsResources(ctx, kubeClient, rs)
5959

60-
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
60+
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
6161
checkReconcileSuccessful(ctx, t, reconciler, rs, kubeClient)
6262
}
6363

@@ -90,7 +90,7 @@ func TestUpdateOmAuthentication_NoAuthenticationEnabled(t *testing.T) {
9090
processNames := []string{"my-rs-0", "my-rs-1", "my-rs-2"}
9191

9292
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
93-
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
93+
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
9494
r.updateOmAuthentication(ctx, conn, processNames, rs, "", "", "", false, zap.S())
9595

9696
ac, _ := conn.ReadAutomationConfig()
@@ -111,7 +111,7 @@ func TestUpdateOmAuthentication_EnableX509_TlsNotEnabled(t *testing.T) {
111111
rs.Spec.Security.TLSConfig.Enabled = true
112112

113113
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
114-
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
114+
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
115115
status, isMultiStageReconciliation := r.updateOmAuthentication(ctx, conn, []string{"my-rs-0", "my-rs-1", "my-rs-2"}, rs, "", "", "", false, zap.S())
116116

117117
assert.True(t, status.IsOK(), "configuring both options at once should not result in a failed status")
@@ -123,7 +123,7 @@ func TestUpdateOmAuthentication_EnableX509_WithTlsAlreadyEnabled(t *testing.T) {
123123
rs := DefaultReplicaSetBuilder().SetName("my-rs").SetMembers(3).EnableTLS().Build()
124124
omConnectionFactory := om.NewCachedOMConnectionFactoryWithInitializedConnection(om.NewMockedOmConnection(deployment.CreateFromReplicaSet("fake-mongoDBImage", false, rs)))
125125
kubeClient := mock.NewDefaultFakeClientWithOMConnectionFactory(omConnectionFactory, rs)
126-
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
126+
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
127127
status, isMultiStageReconciliation := r.updateOmAuthentication(ctx, omConnectionFactory.GetConnection(), []string{"my-rs-0", "my-rs-1", "my-rs-2"}, rs, "", "", "", false, zap.S())
128128

129129
assert.True(t, status.IsOK(), "configuring x509 when tls has already been enabled should not result in a failed status")
@@ -138,7 +138,7 @@ func TestUpdateOmAuthentication_AuthenticationIsNotConfigured_IfAuthIsNotSet(t *
138138

139139
omConnectionFactory := om.NewCachedOMConnectionFactoryWithInitializedConnection(om.NewMockedOmConnection(deployment.CreateFromReplicaSet("fake-mongoDBImage", false, rs)))
140140
kubeClient := mock.NewDefaultFakeClientWithOMConnectionFactory(omConnectionFactory, rs)
141-
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
141+
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
142142

143143
status, _ := r.updateOmAuthentication(ctx, omConnectionFactory.GetConnection(), []string{"my-rs-0", "my-rs-1", "my-rs-2"}, rs, "", "", "", false, zap.S())
144144
assert.True(t, status.IsOK(), "no authentication should have been configured")
@@ -161,7 +161,7 @@ func TestUpdateOmAuthentication_DoesNotDisableAuth_IfAuthIsNotSet(t *testing.T)
161161
Build()
162162

163163
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
164-
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
164+
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
165165

166166
addKubernetesTlsResources(ctx, kubeClient, rs)
167167

@@ -174,7 +174,7 @@ func TestUpdateOmAuthentication_DoesNotDisableAuth_IfAuthIsNotSet(t *testing.T)
174174

175175
rs.Spec.Security.Authentication = nil
176176

177-
reconciler = newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
177+
reconciler = newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
178178

179179
checkReconcileSuccessful(ctx, t, reconciler, rs, kubeClient)
180180

@@ -196,7 +196,7 @@ func TestCanConfigureAuthenticationDisabled_WithNoModes(t *testing.T) {
196196
Build()
197197

198198
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
199-
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
199+
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
200200

201201
addKubernetesTlsResources(ctx, kubeClient, rs)
202202

@@ -208,7 +208,7 @@ func TestUpdateOmAuthentication_EnableX509_FromEmptyDeployment(t *testing.T) {
208208
rs := DefaultReplicaSetBuilder().SetName("my-rs").SetMembers(3).EnableTLS().EnableAuth().EnableX509().Build()
209209
omConnectionFactory := om.NewCachedOMConnectionFactoryWithInitializedConnection(om.NewMockedOmConnection(om.NewDeployment()))
210210
kubeClient := mock.NewDefaultFakeClientWithOMConnectionFactory(omConnectionFactory, rs)
211-
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
211+
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
212212
secretName := util.AgentSecretName
213213
createAgentCSRs(t, ctx, r.client, secretName, certsv1.CertificateApproved)
214214

@@ -229,7 +229,7 @@ func TestX509AgentUserIsCorrectlyConfigured(t *testing.T) {
229229

230230
// configure x509/tls resources
231231
addKubernetesTlsResources(ctx, kubeClient, rs)
232-
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
232+
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
233233

234234
checkReconcileSuccessful(ctx, t, reconciler, rs, kubeClient)
235235

@@ -265,7 +265,7 @@ func TestScramAgentUserIsCorrectlyConfigured(t *testing.T) {
265265

266266
assert.NoError(t, err)
267267

268-
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
268+
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
269269

270270
checkReconcileSuccessful(ctx, t, reconciler, rs, kubeClient)
271271

@@ -295,7 +295,7 @@ func TestScramAgentUser_IsNotOverridden(t *testing.T) {
295295
}
296296
})
297297

298-
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
298+
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
299299

300300
checkReconcileSuccessful(ctx, t, reconciler, rs, kubeClient)
301301

@@ -314,7 +314,7 @@ func TestX509InternalClusterAuthentication_CanBeEnabledWithScram_ReplicaSet(t *t
314314
Build()
315315

316316
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
317-
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
317+
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
318318
addKubernetesTlsResources(ctx, r.client, rs)
319319

320320
checkReconcileSuccessful(ctx, t, r, rs, kubeClient)
@@ -367,7 +367,7 @@ func TestConfigureLdapDeploymentAuthentication_WithScramAgentAuthentication(t *t
367367
Build()
368368

369369
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
370-
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
370+
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
371371
data := map[string]string{
372372
"password": "LITZTOd6YiCV8j",
373373
}
@@ -424,7 +424,7 @@ func TestConfigureLdapDeploymentAuthentication_WithCustomRole(t *testing.T) {
424424
Build()
425425

426426
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
427-
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
427+
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
428428
data := map[string]string{
429429
"password": "LITZTOd6YiCV8j",
430430
}
@@ -478,7 +478,7 @@ func TestConfigureLdapDeploymentAuthentication_WithAuthzQueryTemplate_AndUserToD
478478
Build()
479479

480480
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
481-
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
481+
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
482482
data := map[string]string{
483483
"password": "LITZTOd6YiCV8j",
484484
}
@@ -741,7 +741,7 @@ func TestInvalidPEM_SecretDoesNotContainKey(t *testing.T) {
741741
Build()
742742

743743
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
744-
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
744+
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
745745
addKubernetesTlsResources(ctx, kubeClient, rs)
746746

747747
// Replace the secret with an empty one
@@ -771,7 +771,7 @@ func Test_NoAdditionalDomainsPresent(t *testing.T) {
771771
rs.Spec.Security.TLSConfig.AdditionalCertificateDomains = []string{"foo"}
772772

773773
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
774-
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
774+
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
775775
addKubernetesTlsResources(ctx, kubeClient, rs)
776776

777777
certSecret := &corev1.Secret{}
@@ -797,7 +797,7 @@ func Test_NoExternalDomainPresent(t *testing.T) {
797797
rs.Spec.ExternalAccessConfiguration = &mdbv1.ExternalAccessConfiguration{ExternalDomain: ptr.To("foo")}
798798

799799
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
800-
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
800+
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
801801
addKubernetesTlsResources(ctx, kubeClient, rs)
802802

803803
secret := &corev1.Secret{}

controllers/operator/mongodbmultireplicaset_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ func TestMultiReplicaSetRace(t *testing.T) {
757757

758758
omConnectionFactory := om.NewDefaultCachedOMConnectionFactory().WithResourceToProjectMapping(resourceToProjectMapping)
759759
memberClusterMap := getFakeMultiClusterMapWithConfiguredInterceptor(clusters, omConnectionFactory, true, true)
760-
reconciler := newMultiClusterReplicaSetReconciler(ctx, fakeClient, nil, "fake-initDatabaseNonStaticImageVersion", "fake-databaseNonStaticImageVersion", false, false, omConnectionFactory.GetConnectionFunc, memberClusterMap)
760+
reconciler := newMultiClusterReplicaSetReconciler(ctx, fakeClient, nil, "fake-initDatabaseNonStaticImageVersion", "fake-databaseNonStaticImageVersion", false, false, false, "", omConnectionFactory.GetConnectionFunc, memberClusterMap)
761761

762762
testConcurrentReconciles(ctx, t, fakeClient, reconciler, rs1, rs2, rs3)
763763
}
@@ -1513,7 +1513,7 @@ func calculateHostNamesForExternalDomains(m *mdbmulti.MongoDBMultiCluster) []str
15131513
func multiReplicaSetReconciler(ctx context.Context, imageUrls images.ImageUrls, initDatabaseNonStaticImageVersion, databaseNonStaticImageVersion string, m *mdbmulti.MongoDBMultiCluster) (*ReconcileMongoDbMultiReplicaSet, kubernetesClient.Client, map[string]client.Client, *om.CachedOMConnectionFactory) {
15141514
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(m)
15151515
memberClusterMap := getFakeMultiClusterMap(omConnectionFactory)
1516-
return newMultiClusterReplicaSetReconciler(ctx, kubeClient, imageUrls, initDatabaseNonStaticImageVersion, databaseNonStaticImageVersion, false, false, omConnectionFactory.GetConnectionFunc, memberClusterMap), kubeClient, memberClusterMap, omConnectionFactory
1516+
return newMultiClusterReplicaSetReconciler(ctx, kubeClient, imageUrls, initDatabaseNonStaticImageVersion, databaseNonStaticImageVersion, false, false, false, "", omConnectionFactory.GetConnectionFunc, memberClusterMap), kubeClient, memberClusterMap, omConnectionFactory
15171517
}
15181518

15191519
func getFakeMultiClusterMap(omConnectionFactory *om.CachedOMConnectionFactory) map[string]client.Client {

controllers/operator/mongodbreplicaset_controller_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestReplicaSetRace(t *testing.T) {
9393
Get: mock.GetFakeClientInterceptorGetFunc(omConnectionFactory, true, true),
9494
}).Build()
9595

96-
reconciler := newReplicaSetReconciler(ctx, fakeClient, nil, "fake-initDatabaseNonStaticImageVersion", "fake-databaseNonStaticImageVersion", false, false, omConnectionFactory.GetConnectionFunc)
96+
reconciler := newReplicaSetReconciler(ctx, fakeClient, nil, "fake-initDatabaseNonStaticImageVersion", "fake-databaseNonStaticImageVersion", false, false, false, "", omConnectionFactory.GetConnectionFunc)
9797

9898
testConcurrentReconciles(ctx, t, fakeClient, reconciler, rs, rs2, rs3)
9999
}
@@ -394,7 +394,7 @@ func TestCreateDeleteReplicaSet(t *testing.T) {
394394

395395
omConnectionFactory := om.NewCachedOMConnectionFactory(omConnectionFactoryFuncSettingVersion())
396396
fakeClient := mock.NewDefaultFakeClientWithOMConnectionFactory(omConnectionFactory, rs)
397-
reconciler := newReplicaSetReconciler(ctx, fakeClient, nil, "fake-initDatabaseNonStaticImageVersion", "fake-databaseNonStaticImageVersion", false, false, omConnectionFactory.GetConnectionFunc)
397+
reconciler := newReplicaSetReconciler(ctx, fakeClient, nil, "fake-initDatabaseNonStaticImageVersion", "fake-databaseNonStaticImageVersion", false, false, false, "", omConnectionFactory.GetConnectionFunc)
398398

399399
checkReconcileSuccessful(ctx, t, reconciler, rs, fakeClient)
400400
omConn := omConnectionFactory.GetConnection()
@@ -533,7 +533,7 @@ func TestFeatureControlPolicyAndTagAddedWithNewerOpsManager(t *testing.T) {
533533

534534
omConnectionFactory := om.NewCachedOMConnectionFactory(omConnectionFactoryFuncSettingVersion())
535535
fakeClient := mock.NewDefaultFakeClientWithOMConnectionFactory(omConnectionFactory, rs)
536-
reconciler := newReplicaSetReconciler(ctx, fakeClient, nil, "fake-initDatabaseNonStaticImageVersion", "fake-databaseNonStaticImageVersion", false, false, omConnectionFactory.GetConnectionFunc)
536+
reconciler := newReplicaSetReconciler(ctx, fakeClient, nil, "fake-initDatabaseNonStaticImageVersion", "fake-databaseNonStaticImageVersion", false, false, false, "", omConnectionFactory.GetConnectionFunc)
537537

538538
checkReconcileSuccessful(ctx, t, reconciler, rs, fakeClient)
539539

@@ -557,7 +557,7 @@ func TestFeatureControlPolicyNoAuthNewerOpsManager(t *testing.T) {
557557

558558
omConnectionFactory := om.NewCachedOMConnectionFactory(omConnectionFactoryFuncSettingVersion())
559559
fakeClient := mock.NewDefaultFakeClientWithOMConnectionFactory(omConnectionFactory, rs)
560-
reconciler := newReplicaSetReconciler(ctx, fakeClient, nil, "fake-initDatabaseNonStaticImageVersion", "fake-databaseNonStaticImageVersion", false, false, omConnectionFactory.GetConnectionFunc)
560+
reconciler := newReplicaSetReconciler(ctx, fakeClient, nil, "fake-initDatabaseNonStaticImageVersion", "fake-databaseNonStaticImageVersion", false, false, false, "", omConnectionFactory.GetConnectionFunc)
561561

562562
checkReconcileSuccessful(ctx, t, reconciler, rs, fakeClient)
563563

@@ -896,7 +896,7 @@ func TestReplicaSetAnnotations_NotWrittenOnFailure(t *testing.T) {
896896
WithObjects(mock.GetProjectConfigMap(mock.TestProjectConfigMapName, "testProject", "testOrg")).
897897
Build()
898898

899-
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, nil)
899+
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", nil)
900900

901901
_, err := reconciler.Reconcile(ctx, requestFromObject(rs))
902902
require.NoError(t, err, "Reconcile should not return error (error captured in status)")
@@ -917,7 +917,7 @@ func TestReplicaSetAnnotations_PreservedOnSubsequentFailure(t *testing.T) {
917917
rs := DefaultReplicaSetBuilder().Build()
918918

919919
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
920-
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
920+
reconciler := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, false, "", omConnectionFactory.GetConnectionFunc)
921921

922922
_, err := reconciler.Reconcile(ctx, requestFromObject(rs))
923923
require.NoError(t, err)
@@ -1091,7 +1091,7 @@ func assertCorrectNumberOfMembersAndProcesses(ctx context.Context, t *testing.T,
10911091

10921092
func defaultReplicaSetReconciler(ctx context.Context, imageUrls images.ImageUrls, initDatabaseNonStaticImageVersion, databaseNonStaticImageVersion string, rs *mdbv1.MongoDB) (*ReconcileMongoDbReplicaSet, kubernetesClient.Client, *om.CachedOMConnectionFactory) {
10931093
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
1094-
return newReplicaSetReconciler(ctx, kubeClient, imageUrls, initDatabaseNonStaticImageVersion, databaseNonStaticImageVersion, false, false, omConnectionFactory.GetConnectionFunc), kubeClient, omConnectionFactory
1094+
return newReplicaSetReconciler(ctx, kubeClient, imageUrls, initDatabaseNonStaticImageVersion, databaseNonStaticImageVersion, false, false, false, "", omConnectionFactory.GetConnectionFunc), kubeClient, omConnectionFactory
10951095
}
10961096

10971097
// newDefaultPodSpec creates pod spec with default values,sets only the topology key and persistence sizes,

0 commit comments

Comments
 (0)