@@ -212,79 +212,59 @@ func TestRunContainer_withAllSettings(t *testing.T) {
212
212
testcontainers .CleanupContainer (t , rabbitmqContainer )
213
213
require .NoError (t , err )
214
214
215
- require . True (t , assertEntity ( t , rabbitmqContainer , "queues" , "queue1" , "queue2" , "queue3" , "queue4" ) )
216
- require . True (t , assertEntity ( t , rabbitmqContainer , "exchanges" , "direct-exchange" , "topic-exchange" , "topic-exchange-2" , "topic-exchange-3" , "topic-exchange-4" ) )
217
- require . True (t , assertEntity ( t , rabbitmqContainer , "users" , "user1" , "user2" ) )
218
- require . True (t , assertEntity ( t , rabbitmqContainer , "policies" , "max length policy" , "alternate exchange policy" ) )
219
- require . True (t , assertEntityWithVHost ( t , rabbitmqContainer , "policies" , 2 , "max length policy" , "alternate exchange policy" ) )
220
- require . True (t , assertEntity ( t , rabbitmqContainer , "operator_policies" , "operator policy 1" ) )
221
- require . True (t , assertPluginIsEnabled ( t , rabbitmqContainer , "rabbitmq_shovel" , "rabbitmq_random_exchange" ) )
215
+ requireEntity (t , rabbitmqContainer , "queues" , "queue1" , "queue2" , "queue3" , "queue4" )
216
+ requireEntity (t , rabbitmqContainer , "exchanges" , "direct-exchange" , "topic-exchange" , "topic-exchange-2" , "topic-exchange-3" , "topic-exchange-4" )
217
+ requireEntity (t , rabbitmqContainer , "users" , "user1" , "user2" )
218
+ requireEntity (t , rabbitmqContainer , "policies" , "max length policy" , "alternate exchange policy" )
219
+ requireEntityWithVHost (t , rabbitmqContainer , "policies" , 2 , "max length policy" , "alternate exchange policy" )
220
+ requireEntity (t , rabbitmqContainer , "operator_policies" , "operator policy 1" )
221
+ requirePluginIsEnabled (t , rabbitmqContainer , "rabbitmq_shovel" , "rabbitmq_random_exchange" )
222
222
}
223
223
224
- func assertEntity (t * testing.T , container testcontainers.Container , listCommand string , entities ... string ) bool {
224
+ func requireContainerExec (t * testing.T , container testcontainers.Container , cmd [] string ) string {
225
225
t .Helper ()
226
226
227
- ctx := context .Background ()
228
-
229
- cmd := []string {"rabbitmqadmin" , "list" , listCommand }
230
-
231
- _ , out , err := container .Exec (ctx , cmd )
227
+ _ , out , err := container .Exec (context .Background (), cmd )
232
228
require .NoError (t , err )
233
229
234
- check , err := io .ReadAll (out )
230
+ checkBytes , err := io .ReadAll (out )
235
231
require .NoError (t , err )
232
+ return string (checkBytes )
233
+ }
236
234
235
+ func requireEntity (t * testing.T , container testcontainers.Container , listCommand string , entities ... string ) {
236
+ t .Helper ()
237
+
238
+ cmd := []string {"rabbitmqadmin" , "list" , listCommand }
239
+
240
+ check := requireContainerExec (t , container , cmd )
237
241
for _ , e := range entities {
238
- if ! strings .Contains (string (check ), e ) {
239
- return false
240
- }
242
+ require .Contains (t , check , e )
241
243
}
242
-
243
- return true
244
244
}
245
245
246
- func assertEntityWithVHost (t * testing.T , container testcontainers.Container , listCommand string , vhostID int , entities ... string ) bool {
246
+ func requireEntityWithVHost (t * testing.T , container testcontainers.Container , listCommand string , vhostID int , entities ... string ) {
247
247
t .Helper ()
248
248
249
- ctx := context .Background ()
250
-
251
249
cmd := []string {"rabbitmqadmin" , "list" , listCommand }
252
250
if vhostID > 0 {
253
251
cmd = append (cmd , fmt .Sprintf ("--vhost=vhost%d" , vhostID ))
254
252
}
255
253
256
- _ , out , err := container .Exec (ctx , cmd )
257
- require .NoError (t , err )
258
-
259
- check , err := io .ReadAll (out )
260
- require .NoError (t , err )
261
-
254
+ check := requireContainerExec (t , container , cmd )
262
255
for _ , e := range entities {
263
- if ! strings .Contains (string (check ), e ) {
264
- return false
265
- }
256
+ require .Contains (t , check , e )
266
257
}
267
-
268
- return true
269
258
}
270
259
271
- func assertPluginIsEnabled (t * testing.T , container testcontainers.Container , plugins ... string ) bool {
260
+ func requirePluginIsEnabled (t * testing.T , container testcontainers.Container , plugins ... string ) {
272
261
t .Helper ()
273
262
274
- ctx := context .Background ()
275
-
276
263
for _ , plugin := range plugins {
277
264
278
- _ , out , err := container .Exec (ctx , []string {"rabbitmq-plugins" , "is_enabled" , plugin })
279
- require .NoError (t , err )
265
+ cmd := []string {"rabbitmq-plugins" , "is_enabled" , plugin }
280
266
281
- check , err := io .ReadAll (out )
282
- require .NoError (t , err )
283
-
284
- if ! strings .Contains (string (check ), plugin + " is enabled" ) {
285
- return false
286
- }
267
+ check := requireContainerExec (t , container , cmd )
268
+ require .Contains (t , check , plugin + " is enabled" )
287
269
}
288
-
289
- return true
290
270
}
0 commit comments