@@ -282,23 +282,58 @@ func Test_PortCreateHook(t *testing.T) {
282
282
changesChannel , err := testutils .EventsConn .SubscribeChanges (ctx , "create.load-balancer-port" )
283
283
require .NoError (t , err , "failed to subscribe to changes" )
284
284
285
- lb := (& testutils.LoadBalancerBuilder {}).MustNew (ctx )
286
- pool := (& testutils.PoolBuilder {}).MustNew (ctx )
287
-
288
285
testutils .EntClient .Port .Use (manualhooks .PortHooks ()... )
289
286
290
- // Act
291
- port := (& testutils.PortBuilder {PoolIDs : []gidx.PrefixedID {pool .ID }, LoadBalancerID : lb .ID }).MustNew (ctx )
287
+ t .Run ("with pool" , func (t * testing.T ) {
288
+ // Act
289
+ lb := (& testutils.LoadBalancerBuilder {}).MustNew (ctx )
290
+ pool := (& testutils.PoolBuilder {OwnerID : lb .OwnerID }).MustNew (ctx )
291
+ port := (& testutils.PortBuilder {PoolIDs : []gidx.PrefixedID {pool .ID }, LoadBalancerID : lb .ID }).MustNew (ctx )
292
292
293
- msg := testutils .ChannelReceiveWithTimeout [events.Message [events.ChangeMessage ]](t , changesChannel , defaultTimeout )
293
+ msg := testutils .ChannelReceiveWithTimeout [events.Message [events.ChangeMessage ]](t , changesChannel , defaultTimeout )
294
294
295
- // Assert
296
- expectedAdditionalSubjectIDs := []gidx.PrefixedID {pool .ID , pool . OwnerID , lb .ID , lb .LocationID , lb .ProviderID , lb .OwnerID }
297
- actualAdditionalSubjectIDs := msg .Message ().AdditionalSubjectIDs
295
+ // Assert
296
+ expectedAdditionalSubjectIDs := []gidx.PrefixedID {pool .ID , lb .ID , lb .LocationID , lb .ProviderID , lb .OwnerID }
297
+ actualAdditionalSubjectIDs := msg .Message ().AdditionalSubjectIDs
298
298
299
- assert .ElementsMatch (t , expectedAdditionalSubjectIDs , actualAdditionalSubjectIDs )
300
- assert .Equal (t , port .ID , msg .Message ().SubjectID )
301
- assert .Equal (t , createEventType , msg .Message ().EventType )
299
+ assert .ElementsMatch (t , expectedAdditionalSubjectIDs , actualAdditionalSubjectIDs )
300
+ assert .Equal (t , port .ID , msg .Message ().SubjectID )
301
+ assert .Equal (t , createEventType , msg .Message ().EventType )
302
+ })
303
+
304
+ t .Run ("with multiple pools" , func (t * testing.T ) {
305
+ // Act
306
+ lb := (& testutils.LoadBalancerBuilder {}).MustNew (ctx )
307
+ pool := (& testutils.PoolBuilder {OwnerID : lb .OwnerID }).MustNew (ctx )
308
+ pool2 := (& testutils.PoolBuilder {OwnerID : lb .OwnerID }).MustNew (ctx )
309
+ port := (& testutils.PortBuilder {PoolIDs : []gidx.PrefixedID {pool .ID , pool2 .ID }, LoadBalancerID : lb .ID }).MustNew (ctx )
310
+
311
+ msg := testutils .ChannelReceiveWithTimeout [events.Message [events.ChangeMessage ]](t , changesChannel , defaultTimeout )
312
+
313
+ // Assert
314
+ expectedAdditionalSubjectIDs := []gidx.PrefixedID {pool .ID , pool2 .ID , lb .ID , lb .LocationID , lb .ProviderID , lb .OwnerID }
315
+ actualAdditionalSubjectIDs := msg .Message ().AdditionalSubjectIDs
316
+
317
+ assert .ElementsMatch (t , expectedAdditionalSubjectIDs , actualAdditionalSubjectIDs )
318
+ assert .Equal (t , port .ID , msg .Message ().SubjectID )
319
+ assert .Equal (t , createEventType , msg .Message ().EventType )
320
+ })
321
+
322
+ t .Run ("with no pool" , func (t * testing.T ) {
323
+ // Act
324
+ lb := (& testutils.LoadBalancerBuilder {}).MustNew (ctx )
325
+ port := (& testutils.PortBuilder {PoolIDs : []gidx.PrefixedID {}, LoadBalancerID : lb .ID }).MustNew (ctx )
326
+
327
+ msg := testutils .ChannelReceiveWithTimeout [events.Message [events.ChangeMessage ]](t , changesChannel , defaultTimeout )
328
+
329
+ // Assert
330
+ expectedAdditionalSubjectIDs := []gidx.PrefixedID {lb .ID , lb .LocationID , lb .ProviderID , lb .OwnerID }
331
+ actualAdditionalSubjectIDs := msg .Message ().AdditionalSubjectIDs
332
+
333
+ assert .ElementsMatch (t , expectedAdditionalSubjectIDs , actualAdditionalSubjectIDs )
334
+ assert .Equal (t , port .ID , msg .Message ().SubjectID )
335
+ assert .Equal (t , createEventType , msg .Message ().EventType )
336
+ })
302
337
}
303
338
304
339
func Test_PortUpdateHook (t * testing.T ) {
0 commit comments