@@ -193,44 +193,15 @@ func TestGatherApplicationIds(t *testing.T) {
193193}
194194
195195func TestHasSlotsInSync (t * testing.T ) {
196- client , _ := newFakeK8sStreamClient ()
197- var cluster = New (
198- Config {
199- OpConfig : config.Config {
200- Auth : config.Auth {
201- SecretNameTemplate : "{username}.{cluster}.credentials.{tprkind}.{tprgroup}" ,
202- },
203- PodManagementPolicy : "ordered_ready" ,
204- Resources : config.Resources {
205- ClusterLabels : map [string ]string {"application" : "spilo" },
206- ClusterNameLabel : "cluster-name" ,
207- DefaultCPURequest : "300m" ,
208- DefaultCPULimit : "300m" ,
209- DefaultMemoryRequest : "300Mi" ,
210- DefaultMemoryLimit : "300Mi" ,
211- PodRoleLabel : "spilo-role" ,
212- },
213- },
214- }, client , pg , logger , eventRecorder )
215-
216- cluster .Name = clusterName
217- cluster .Namespace = namespace
218-
219- appId2 := fmt .Sprintf ("%s-2" , appId )
220- dbNotExists := "dbnotexists"
221- slotNotExists := fmt .Sprintf ("%s_%s_%s" , constants .EventStreamSourceSlotPrefix , dbNotExists , strings .Replace (appId , "-" , "_" , - 1 ))
222- slotNotExistsAppId2 := fmt .Sprintf ("%s_%s_%s" , constants .EventStreamSourceSlotPrefix , dbNotExists , strings .Replace (appId2 , "-" , "_" , - 1 ))
223196
224197 tests := []struct {
225198 subTest string
226- applicationId string
227199 expectedSlots map [string ]map [string ]zalandov1.Slot
228200 actualSlots map [string ]map [string ]string
229201 slotsInSync bool
230202 }{
231203 {
232- subTest : fmt .Sprintf ("slots in sync for applicationId %s" , appId ),
233- applicationId : appId ,
204+ subTest : "slots are in sync" ,
234205 expectedSlots : map [string ]map [string ]zalandov1.Slot {
235206 dbName : {
236207 slotName : zalandov1.Slot {
@@ -256,70 +227,7 @@ func TestHasSlotsInSync(t *testing.T) {
256227 },
257228 slotsInSync : true ,
258229 }, {
259- subTest : fmt .Sprintf ("slots empty for applicationId %s" , appId ),
260- applicationId : appId ,
261- expectedSlots : map [string ]map [string ]zalandov1.Slot {
262- dbNotExists : {
263- slotNotExists : zalandov1.Slot {
264- Slot : map [string ]string {
265- "databases" : dbName ,
266- "plugin" : constants .EventStreamSourcePluginType ,
267- "type" : "logical" ,
268- },
269- Publication : map [string ]acidv1.StreamTable {
270- "test1" : acidv1.StreamTable {
271- EventType : "stream-type-a" ,
272- },
273- },
274- },
275- },
276- },
277- actualSlots : map [string ]map [string ]string {},
278- slotsInSync : false ,
279- }, {
280- subTest : fmt .Sprintf ("one slot not in sync for applicationId %s" , appId ),
281- applicationId : appId ,
282- expectedSlots : map [string ]map [string ]zalandov1.Slot {
283- dbName : {
284- slotName : zalandov1.Slot {
285- Slot : map [string ]string {
286- "databases" : dbName ,
287- "plugin" : constants .EventStreamSourcePluginType ,
288- "type" : "logical" ,
289- },
290- Publication : map [string ]acidv1.StreamTable {
291- "test1" : acidv1.StreamTable {
292- EventType : "stream-type-a" ,
293- },
294- },
295- },
296- },
297- dbNotExists : {
298- slotNotExists : zalandov1.Slot {
299- Slot : map [string ]string {
300- "databases" : "dbnotexists" ,
301- "plugin" : constants .EventStreamSourcePluginType ,
302- "type" : "logical" ,
303- },
304- Publication : map [string ]acidv1.StreamTable {
305- "test2" : acidv1.StreamTable {
306- EventType : "stream-type-b" ,
307- },
308- },
309- },
310- },
311- },
312- actualSlots : map [string ]map [string ]string {
313- slotName : map [string ]string {
314- "databases" : dbName ,
315- "plugin" : constants .EventStreamSourcePluginType ,
316- "type" : "logical" ,
317- },
318- },
319- slotsInSync : false ,
320- }, {
321- subTest : fmt .Sprintf ("slots in sync for applicationId %s, but not for for %s - checking %s" , appId , appId2 , appId ),
322- applicationId : appId ,
230+ subTest : "slots are not in sync" ,
323231 expectedSlots : map [string ]map [string ]zalandov1.Slot {
324232 dbName : {
325233 slotName : zalandov1.Slot {
@@ -335,49 +243,8 @@ func TestHasSlotsInSync(t *testing.T) {
335243 },
336244 },
337245 },
338- dbNotExists : {
339- slotNotExistsAppId2 : zalandov1.Slot {
340- Slot : map [string ]string {
341- "databases" : "dbnotexists" ,
342- "plugin" : constants .EventStreamSourcePluginType ,
343- "type" : "logical" ,
344- },
345- Publication : map [string ]acidv1.StreamTable {
346- "test2" : acidv1.StreamTable {
347- EventType : "stream-type-b" ,
348- },
349- },
350- },
351- },
352- },
353- actualSlots : map [string ]map [string ]string {
354- slotName : map [string ]string {
355- "databases" : dbName ,
356- "plugin" : constants .EventStreamSourcePluginType ,
357- "type" : "logical" ,
358- },
359- },
360- slotsInSync : true ,
361- }, {
362- subTest : fmt .Sprintf ("slots in sync for applicationId %s, but not for for %s - checking %s" , appId , appId2 , appId2 ),
363- applicationId : appId2 ,
364- expectedSlots : map [string ]map [string ]zalandov1.Slot {
365- dbName : {
246+ "dbnotexists" : {
366247 slotName : zalandov1.Slot {
367- Slot : map [string ]string {
368- "databases" : dbName ,
369- "plugin" : constants .EventStreamSourcePluginType ,
370- "type" : "logical" ,
371- },
372- Publication : map [string ]acidv1.StreamTable {
373- "test1" : acidv1.StreamTable {
374- EventType : "stream-type-a" ,
375- },
376- },
377- },
378- },
379- dbNotExists : {
380- slotNotExistsAppId2 : zalandov1.Slot {
381248 Slot : map [string ]string {
382249 "databases" : "dbnotexists" ,
383250 "plugin" : constants .EventStreamSourcePluginType ,
@@ -403,9 +270,9 @@ func TestHasSlotsInSync(t *testing.T) {
403270 }
404271
405272 for _ , tt := range tests {
406- result := cluster . hasSlotsInSync (tt . applicationId , tt .expectedSlots , tt .actualSlots )
407- if result != tt . slotsInSync {
408- t .Errorf ("%s: unexpected result for slot test of applicationId: %v , expected slots %#v, actual slots %#v" , tt . subTest , tt . applicationId , tt .expectedSlots , tt .actualSlots )
273+ result := hasSlotsInSync (appId , tt .expectedSlots , tt .actualSlots )
274+ if ! result {
275+ t .Errorf ("slots are not in sync , expected %#v, got %#v" , tt .expectedSlots , tt .actualSlots )
409276 }
410277 }
411278}
0 commit comments