|
346 | 346 |
|
347 | 347 | describe '#read_used_ports' do
|
348 | 348 | let(:all_containers) { ["container1\ncontainer2"] }
|
349 |
| - let(:container_info) { {"Name"=>"/container", "HostConfig"=>{"PortBindings"=>{}}} } |
| 349 | + let(:container_info) { {"Name"=>"/container", "State"=>{"Running"=>true}, "HostConfig"=>{"PortBindings"=>{}}} } |
350 | 350 | let(:empty_used_ports) { {} }
|
351 | 351 |
|
352 | 352 | context "with existing port forwards" do
|
353 |
| - let(:container_info) { {"Name"=>"/container", "HostConfig"=>{"PortBindings"=>{"22/tcp"=>[{"HostIp"=>"127.0.0.1","HostPort"=>"2222"}] }}} } |
| 353 | + let(:container_info) { {"Name"=>"/container","State"=>{"Running"=>true}, "HostConfig"=>{"PortBindings"=>{"22/tcp"=>[{"HostIp"=>"127.0.0.1","HostPort"=>"2222"}] }}} } |
354 | 354 | let(:used_ports_set) { {"2222"=>Set["127.0.0.1"]} }
|
355 | 355 |
|
356 |
| - it 'should read all port bindings and return a hash of sets' do |
357 |
| - allow(subject).to receive(:all_containers).and_return(all_containers) |
358 |
| - allow(subject).to receive(:inspect_container).and_return(container_info) |
| 356 | + context "with active containers" do |
| 357 | + it 'should read all port bindings and return a hash of sets' do |
| 358 | + allow(subject).to receive(:all_containers).and_return(all_containers) |
| 359 | + allow(subject).to receive(:inspect_container).and_return(container_info) |
359 | 360 |
|
360 |
| - used_ports = subject.read_used_ports |
361 |
| - expect(used_ports).to eq(used_ports_set) |
| 361 | + used_ports = subject.read_used_ports |
| 362 | + expect(used_ports).to eq(used_ports_set) |
| 363 | + end |
| 364 | + end |
| 365 | + |
| 366 | + context "with inactive containers" do |
| 367 | + let(:container_info) { {"Name"=>"/container", "State"=>{"Running"=>false}, "HostConfig"=>{"PortBindings"=>{"22/tcp"=>[{"HostIp"=>"127.0.0.1","HostPort"=>"2222"}] }}} } |
| 368 | + |
| 369 | + it 'returns empty' do |
| 370 | + allow(subject).to receive(:all_containers).and_return(all_containers) |
| 371 | + allow(subject).to receive(:inspect_container).and_return(container_info) |
| 372 | + |
| 373 | + used_ports = subject.read_used_ports |
| 374 | + expect(used_ports).to eq(empty_used_ports) |
| 375 | + end |
362 | 376 | end
|
363 | 377 | end
|
364 | 378 |
|
|
0 commit comments