Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
action/forward_ports: Merge port forwarding with sudo specs into a si…
Browse files Browse the repository at this point in the history
…ngle file [GH-259]
  • Loading branch information
fgrehm committed May 4, 2014
1 parent a0fe2f9 commit 9838d32
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 78 deletions.
32 changes: 31 additions & 1 deletion spec/unit/action/forward_ports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

describe Vagrant::LXC::Action::ForwardPorts do
let(:app) { double(:app, call: true) }
let(:env) { {machine: machine, ui: double(info: true)} }
let(:env) { {machine: machine, ui: double(info: true, warn: true)} }
let(:machine) { double(:machine) }
let!(:data_dir) { Pathname.new(Dir.mktmpdir) }
let(:provider) { double(Vagrant::LXC::Provider, ssh_info: {host: container_ip}) }
Expand Down Expand Up @@ -74,4 +74,34 @@
subject.stub(system: false)
expect { subject.call(env) }.to raise_error(Vagrant::LXC::Errors::RedirNotInstalled)
end

context 'when a privileged port is used' do
let(:host_port) { 80 }

it 'forwards ports using redir' do
subject.stub(system: true)
subject.call(env)
expect(subject).to have_received(:spawn).with(
"sudo redir --laddr=#{host_ip} --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
)
end

it 'skips --laddr parameter if host_ip is nil' do
forward_conf.delete(:host_ip)
subject.stub(system: true)
subject.call(env)
expect(subject).to have_received(:spawn).with(
"sudo redir --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
)
end

it 'skips --laddr parameter if host_ip is a blank string' do
forward_conf[:host_ip] = ' '
subject.stub(system: true)
subject.call(env)
expect(subject).to have_received(:spawn).with(
"sudo redir --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
)
end
end
end
77 changes: 0 additions & 77 deletions spec/unit/action/sudo_forward_ports_spec.rb

This file was deleted.

0 comments on commit 9838d32

Please sign in to comment.