@@ -10,6 +10,11 @@ import (
1010 mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"
1111)
1212
13+ func init () {
14+ logger , _ := zap .NewDevelopment ()
15+ zap .ReplaceGlobals (logger )
16+ }
17+
1318func TestClusterMatchesSpec (t * testing.T ) {
1419 t .Run ("Clusters match (enums)" , func (t * testing.T ) {
1520 atlasCluster := mongodbatlas.Cluster {
@@ -82,6 +87,10 @@ func TestClusterMatchesSpec(t *testing.T) {
8287 "US_EAST" : {AnalyticsNodes : int64ptr (0 ), ElectableNodes : int64ptr (3 ), Priority : int64ptr (7 ), ReadOnlyNodes : int64ptr (0 )}}},
8388 }
8489 operatorCluster := mdbv1 .DefaultAWSCluster ("test-ns" , "project-name" )
90+ operatorCluster .Spec .ReplicationSpecs = []mdbv1.ReplicationSpec {{
91+ NumShards : int64ptr (1 ),
92+ ZoneName : "zone1" ,
93+ }}
8594
8695 merged , err := MergedCluster (* atlasCluster , operatorCluster .Spec )
8796 assert .NoError (t , err )
@@ -120,6 +129,43 @@ func TestClusterMatchesSpec(t *testing.T) {
120129 equal := ClustersEqual (zap .S (), * atlasCluster , merged )
121130 assert .False (t , equal )
122131 })
132+
133+ t .Run ("Clusters don't match - Operator removed the region" , func (t * testing.T ) {
134+ atlasCluster , err := mdbv1 .DefaultAWSCluster ("test-ns" , "project-name" ).Spec .Cluster ()
135+ assert .NoError (t , err )
136+ atlasCluster .ReplicationSpecs = []mongodbatlas.ReplicationSpec {{
137+ ID : "id" ,
138+ NumShards : int64ptr (1 ),
139+ ZoneName : "zone1" ,
140+ RegionsConfig : map [string ]mongodbatlas.RegionsConfig {
141+ "US_EAST" : {AnalyticsNodes : int64ptr (0 ), ElectableNodes : int64ptr (3 ), Priority : int64ptr (7 ), ReadOnlyNodes : int64ptr (0 )},
142+ "US_WEST" : {AnalyticsNodes : int64ptr (2 ), ElectableNodes : int64ptr (5 ), Priority : int64ptr (6 ), ReadOnlyNodes : int64ptr (0 )},
143+ }},
144+ }
145+ operatorCluster := mdbv1 .DefaultAWSCluster ("test-ns" , "project-name" )
146+ operatorCluster .Spec .ReplicationSpecs = []mdbv1.ReplicationSpec {{
147+ NumShards : int64ptr (1 ),
148+ ZoneName : "zone1" ,
149+ RegionsConfig : map [string ]mdbv1.RegionsConfig {
150+ "US_EAST" : {AnalyticsNodes : int64ptr (0 ), ElectableNodes : int64ptr (3 ), Priority : int64ptr (7 ), ReadOnlyNodes : int64ptr (0 )},
151+ }},
152+ }
153+
154+ merged , err := MergedCluster (* atlasCluster , operatorCluster .Spec )
155+ assert .NoError (t , err )
156+
157+ expectedReplicationSpecs := []mongodbatlas.ReplicationSpec {{
158+ ID : "id" ,
159+ NumShards : int64ptr (1 ),
160+ ZoneName : "zone1" ,
161+ RegionsConfig : map [string ]mongodbatlas.RegionsConfig {
162+ "US_EAST" : {AnalyticsNodes : int64ptr (0 ), ElectableNodes : int64ptr (3 ), Priority : int64ptr (7 ), ReadOnlyNodes : int64ptr (0 )}}},
163+ }
164+ assert .Equal (t , expectedReplicationSpecs , merged .ReplicationSpecs )
165+
166+ equal := ClustersEqual (zap .S (), * atlasCluster , merged )
167+ assert .False (t , equal )
168+ })
123169}
124170func int64ptr (i int64 ) * int64 {
125171 return & i
0 commit comments