@@ -3,6 +3,9 @@ package atlasproject
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "github.com/google/go-cmp/cmp"
7
+ "github.com/google/go-cmp/cmp/cmpopts"
8
+ "github.com/mongodb/mongodb-atlas-kubernetes/v2/api"
6
9
"testing"
7
10
8
11
"github.com/stretchr/testify/assert"
@@ -215,41 +218,81 @@ func TestPrivateEndpointsNonGreedyBehaviour(t *testing.T) {
215
218
atlasPEids []string
216
219
wantRemoved []string
217
220
wantResult workflow.Result
221
+ conditions []api.Condition
218
222
}{
219
223
{
220
- title : "no last applied no removal in Atlas " ,
224
+ title : "empty last applied, empty spec, two entries in atlas: shouldn't remove entries " ,
221
225
lastAppliedPEids : []string {},
222
226
specPEids : []string {},
223
227
atlasPEids : []string {"pe1" , "pe2" },
224
228
wantRemoved : []string {},
225
229
wantResult : workflow .OK (),
230
+ conditions : []api.Condition {},
226
231
},
227
232
{
228
- title : "removed from last applied removes from Atlas" ,
233
+ title : "empty last applied, a entry in spec, two entries in atlas: shouldn't remove missing entry" ,
234
+ lastAppliedPEids : []string {},
235
+ specPEids : []string {"pe1" },
236
+ atlasPEids : []string {"pe1" , "pe2" },
237
+ wantRemoved : []string {},
238
+ wantResult : workflow .OK ().WithMessage ("Interface Private Endpoint awaits configuration" ),
239
+ conditions : []api.Condition {
240
+ api .TrueCondition (api .PrivateEndpointServiceReadyType ).
241
+ WithMessageRegexp ("Interface Private Endpoint awaits configuration" ),
242
+ },
243
+ },
244
+ {
245
+ title : "empty last applied, one entry in spec, empty atlas: no remove action" ,
246
+ lastAppliedPEids : []string {},
247
+ specPEids : []string {"pe1" },
248
+ atlasPEids : []string {},
249
+ wantRemoved : []string {},
250
+ wantResult : notReadyServiceResult ,
251
+ conditions : []api.Condition {
252
+ api .FalseCondition (api .PrivateEndpointServiceReadyType ).
253
+ WithReason (string (workflow .ProjectPEServiceIsNotReadyInAtlas )).
254
+ WithMessageRegexp ("Private Endpoint Service is not ready" ),
255
+ },
256
+ },
257
+ {
258
+ title : "two entries in last applied, one entry in spec, two entries in atlas: should remove one entry" ,
229
259
lastAppliedPEids : []string {"pe1" , "pe2" },
230
260
specPEids : []string {"pe1" },
231
261
atlasPEids : []string {"pe1" , "pe2" },
232
262
wantRemoved : []string {"pe2" },
233
263
wantResult : workflow .InProgress (
234
264
workflow .ProjectPEServiceIsNotReadyInAtlas , "Private Endpoint is deleting" ),
265
+ conditions : []api.Condition {
266
+ api .FalseCondition (api .PrivateEndpointServiceReadyType ).
267
+ WithReason (string (workflow .ProjectPEServiceIsNotReadyInAtlas )).
268
+ WithMessageRegexp ("Private Endpoint is deleting" ),
269
+ },
235
270
},
236
271
{
237
- title : "removed all from last applied removes all from Atlas " ,
272
+ title : "two entries in last applied, empty spec, two entries in atlas: should remove entries " ,
238
273
lastAppliedPEids : []string {"pe1" , "pe2" },
239
274
specPEids : []string {},
240
275
atlasPEids : []string {"pe1" , "pe2" },
241
276
wantRemoved : []string {"pe1" , "pe2" },
242
277
wantResult : workflow .InProgress (
243
278
workflow .ProjectPEServiceIsNotReadyInAtlas , "Private Endpoint is deleting" ),
279
+ conditions : []api.Condition {
280
+ api .FalseCondition (api .PrivateEndpointServiceReadyType ).
281
+ WithReason (string (workflow .ProjectPEServiceIsNotReadyInAtlas )).
282
+ WithMessageRegexp ("Private Endpoint is deleting" ),
283
+ },
244
284
},
245
285
{
246
- title : "not in last applied not removed from Atlas " ,
286
+ title : "an entry in last applied, an entry in spec, two entries in atlas: shouldn't remove an entry " ,
247
287
lastAppliedPEids : []string {"pe1" },
248
288
specPEids : []string {"pe1" },
249
289
atlasPEids : []string {"pe1" , "pe2" },
250
290
wantRemoved : []string {},
251
- wantResult : workflow .InProgress (
252
- workflow .ProjectPrivateEndpointIsNotReadyInAtlas , "Interface Private Endpoint is not ready" ),
291
+ wantResult : workflow .OK ().WithMessage ("Interface Private Endpoint awaits configuration" ),
292
+ conditions : []api.Condition {
293
+ api .TrueCondition (api .PrivateEndpointServiceReadyType ).
294
+ WithMessageRegexp ("Interface Private Endpoint awaits configuration" ),
295
+ },
253
296
},
254
297
} {
255
298
t .Run (tc .title , func (t * testing.T ) {
@@ -279,20 +322,18 @@ func TestPrivateEndpointsNonGreedyBehaviour(t *testing.T) {
279
322
280
323
removals := len (tc .wantRemoved )
281
324
if removals > 0 {
282
- privateEndpointsAPI .EXPECT ().DeletePrivateEndpointServiceWithParams (
283
- mock .Anything , mock .Anything ,
284
- ).Return (admin.DeletePrivateEndpointServiceApiRequest {ApiService : privateEndpointsAPI }).Times (removals )
325
+ privateEndpointsAPI .EXPECT ().DeletePrivateEndpointServiceWithParams (mock .Anything , mock .Anything ).
326
+ Return (admin.DeletePrivateEndpointServiceApiRequest {ApiService : privateEndpointsAPI }).Times (removals )
285
327
privateEndpointsAPI .EXPECT ().DeletePrivateEndpointServiceExecute (
286
328
mock .AnythingOfType ("admin.DeletePrivateEndpointServiceApiRequest" )).Return (
287
329
nil , nil , nil ,
288
330
).Times (removals )
289
331
}
290
- privateEndpointsAPI .EXPECT ().CreatePrivateEndpointWithParams (
291
- mock .Anything , mock .Anything ,
292
- ).Return (admin.CreatePrivateEndpointApiRequest {ApiService : privateEndpointsAPI }).Maybe ()
293
- privateEndpointsAPI .EXPECT ().CreatePrivateEndpointExecute (
294
- mock .AnythingOfType ("admin.CreatePrivateEndpointApiRequest" )).Return (
295
- nil , nil , nil ,
332
+ privateEndpointsAPI .EXPECT ().CreatePrivateEndpointService (mock .Anything , mock .Anything , mock .Anything ).
333
+ Return (admin.CreatePrivateEndpointServiceApiRequest {ApiService : privateEndpointsAPI }).Maybe ()
334
+ privateEndpointsAPI .EXPECT ().CreatePrivateEndpointServiceExecute (
335
+ mock .AnythingOfType ("admin.CreatePrivateEndpointServiceApiRequest" )).Return (
336
+ & admin.EndpointService {CloudProvider : "AWS" , RegionName : pointer .MakePtr ("fake-region-pe1" )}, nil , nil ,
296
337
).Maybe ()
297
338
298
339
workflowCtx := workflow.Context {
@@ -307,6 +348,19 @@ func TestPrivateEndpointsNonGreedyBehaviour(t *testing.T) {
307
348
308
349
result := ensurePrivateEndpoint (& workflowCtx , prj )
309
350
require .Equal (t , tc .wantResult , result )
351
+ t .Log (cmp .Diff (
352
+ tc .conditions ,
353
+ workflowCtx .Conditions (),
354
+ cmpopts .IgnoreFields (api.Condition {}, "LastTransitionTime" ),
355
+ ))
356
+ assert .True (
357
+ t ,
358
+ cmp .Equal (
359
+ tc .conditions ,
360
+ workflowCtx .Conditions (),
361
+ cmpopts .IgnoreFields (api.Condition {}, "LastTransitionTime" ),
362
+ ),
363
+ )
310
364
})
311
365
}
312
366
}
@@ -328,7 +382,6 @@ func synthesizePEs(peIDs []string) []akov2.PrivateEndpoint {
328
382
for _ , id := range peIDs {
329
383
pes = append (pes , akov2.PrivateEndpoint {
330
384
Provider : "AWS" ,
331
- ID : id ,
332
385
Region : fmt .Sprintf ("fake-region-%s" , id ),
333
386
})
334
387
}
@@ -340,7 +393,7 @@ func synthesizeAtlasPEs(peIDs []string) []admin.EndpointService {
340
393
for _ , id := range peIDs {
341
394
atlasPEs = append (atlasPEs , admin.EndpointService {
342
395
CloudProvider : "AWS" ,
343
- Id : pointer .MakePtr (id ),
396
+ Id : pointer .MakePtr (id + "-id" ),
344
397
RegionName : pointer .MakePtr (fmt .Sprintf ("fake-region-%s" , id )),
345
398
Status : pointer .MakePtr ("AVAILABLE" ),
346
399
})
0 commit comments