@@ -110,6 +110,12 @@ module Beaker
110
110
111
111
before do
112
112
allow ( ::Docker ) . to receive ( :rootless? ) . and_return ( true )
113
+ @docker_host = ENV . fetch ( 'DOCKER_HOST' , nil )
114
+ ENV . delete ( 'DOCKER_HOST' ) if @docker_host
115
+ end
116
+
117
+ after do
118
+ ENV [ 'DOCKER_HOST' ] = @docker_host if @docker_host
113
119
end
114
120
115
121
context 'with connection failure' do
@@ -476,64 +482,46 @@ module Beaker
476
482
end
477
483
478
484
context 'when connecting to ssh' do
479
- context 'when rootless' do
480
- before { @docker_host = ENV . fetch ( 'DOCKER_HOST' , nil ) }
481
-
482
- after { ENV [ 'DOCKER_HOST' ] = @docker_host }
483
-
484
- it 'exposes port 22 to beaker' do
485
- ENV [ 'DOCKER_HOST' ] = nil
486
- docker . provision
487
-
488
- expect ( hosts [ 0 ] [ 'ip' ] ) . to eq '127.0.0.1'
489
- expect ( hosts [ 0 ] [ 'port' ] ) . to eq 8022
490
- end
491
-
492
- it 'exposes port 22 to beaker when using DOCKER_HOST' do
493
- ENV [ 'DOCKER_HOST' ] = 'tcp://192.0.2.2:2375'
494
- docker . provision
495
-
496
- expect ( hosts [ 0 ] [ 'ip' ] ) . to eq '192.0.2.2'
497
- expect ( hosts [ 0 ] [ 'port' ] ) . to eq 8022
498
- end
485
+ %w[ rootless privileged ] . each do |mode |
486
+ context "when #{ mode } " do
487
+ let ( :container_mode ) do
488
+ mode
489
+ end
499
490
500
- it 'has ssh agent forwarding enabled' do
501
- ENV [ 'DOCKER_HOST' ] = nil
502
- docker . provision
491
+ it 'exposes port 22 to beaker' do
492
+ docker . provision
503
493
504
- expect ( hosts [ 0 ] [ 'ip' ] ) . to eq '127.0.0.1'
505
- expect ( hosts [ 0 ] [ 'port' ] ) . to eq 8022
506
- expect ( hosts [ 0 ] [ 'ssh' ] [ :password ] ) . to eq 'root'
507
- expect ( hosts [ 0 ] [ 'ssh' ] [ :port ] ) . to eq 8022
508
- expect ( hosts [ 0 ] [ 'ssh' ] [ :forward_agent ] ) . to be true
509
- end
494
+ expect ( hosts [ 0 ] [ 'ip' ] ) . to eq '127.0.0.1'
495
+ expect ( hosts [ 0 ] [ 'port' ] ) . to eq 8022
496
+ end
510
497
511
- it 'connects to gateway ip' do
512
- FakeFS do
513
- FileUtils . touch ( '/.dockerenv' )
498
+ it 'exposes port 22 to beaker when using DOCKER_HOST' do
499
+ ENV [ 'DOCKER_HOST' ] = 'tcp://192.0.2.2:2375'
514
500
docker . provision
515
501
516
- expect ( hosts [ 0 ] [ 'ip' ] ) . to eq '192.0.2.254 '
502
+ expect ( hosts [ 0 ] [ 'ip' ] ) . to eq '192.0.2.2 '
517
503
expect ( hosts [ 0 ] [ 'port' ] ) . to eq 8022
518
504
end
519
- end
520
- end
521
-
522
- context 'when rootful' do
523
- before { @docker_host = ENV . fetch ( 'DOCKER_HOST' , nil ) }
524
505
525
- after { ENV [ 'DOCKER_HOST' ] = @docker_host }
506
+ it 'has ssh agent forwarding enabled' do
507
+ docker . provision
526
508
527
- let ( :container_mode ) do
528
- 'rootful'
529
- end
509
+ expect ( hosts [ 0 ] [ 'ip' ] ) . to eq '127.0.0.1'
510
+ expect ( hosts [ 0 ] [ 'port' ] ) . to eq 8022
511
+ expect ( hosts [ 0 ] [ 'ssh' ] [ :password ] ) . to eq 'root'
512
+ expect ( hosts [ 0 ] [ 'ssh' ] [ :port ] ) . to eq 8022
513
+ expect ( hosts [ 0 ] [ 'ssh' ] [ :forward_agent ] ) . to be true
514
+ end
530
515
531
- it 'exposes port 22 to beaker' do
532
- ENV [ 'DOCKER_HOST' ] = nil
533
- docker . provision
516
+ it 'connects to gateway ip' do
517
+ FakeFS do
518
+ FileUtils . touch ( '/.dockerenv' )
519
+ docker . provision
534
520
535
- expect ( hosts [ 0 ] [ 'ip' ] ) . to eq '127.0.0.1'
536
- expect ( hosts [ 0 ] [ 'port' ] ) . to eq 8022
521
+ expect ( hosts [ 0 ] [ 'ip' ] ) . to eq '192.0.2.254'
522
+ expect ( hosts [ 0 ] [ 'port' ] ) . to eq 8022
523
+ end
524
+ end
537
525
end
538
526
end
539
527
end
0 commit comments