2013-03-26 23:00:05 +00:00
|
|
|
require 'unit_helper'
|
|
|
|
|
|
|
|
require 'vagrant-lxc/action/forward_ports'
|
|
|
|
|
|
|
|
describe Vagrant::LXC::Action::ForwardPorts do
|
2013-07-13 16:41:39 +00:00
|
|
|
let(:app) { double(:app, call: true) }
|
|
|
|
let(:env) { {machine: machine, ui: double(info: true)} }
|
|
|
|
let(:machine) { double(:machine) }
|
2013-03-26 23:00:05 +00:00
|
|
|
let!(:data_dir) { Pathname.new(Dir.mktmpdir) }
|
|
|
|
let(:networks) { [[:other_config, {}], [:forwarded_port, {guest: guest_port, host: host_port}]] }
|
|
|
|
let(:host_port) { 8080 }
|
|
|
|
let(:guest_port) { 80 }
|
2013-07-13 16:33:09 +00:00
|
|
|
let(:provider) { instance_double('Vagrant::LXC::Provider', driver: driver) }
|
|
|
|
let(:driver) { instance_double('Vagrant::LXC::Driver', assigned_ip: container_ip) }
|
2013-03-26 23:00:05 +00:00
|
|
|
let(:container_ip) { '10.0.1.234' }
|
|
|
|
let(:pid) { 'a-pid' }
|
|
|
|
|
|
|
|
subject { described_class.new(app, env) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
machine.stub_chain(:config, :vm, :networks).and_return(networks)
|
|
|
|
machine.stub(provider: provider, data_dir: data_dir)
|
|
|
|
|
|
|
|
subject.stub(exec: true)
|
2013-04-23 11:03:29 +00:00
|
|
|
subject.stub(spawn: pid)
|
2013-03-26 23:00:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
after { FileUtils.rm_rf data_dir.to_s }
|
|
|
|
|
|
|
|
it 'forwards ports using redir' do
|
2013-07-16 04:56:40 +00:00
|
|
|
subject.stub(system: true)
|
|
|
|
subject.call(env)
|
2013-04-23 11:03:29 +00:00
|
|
|
subject.should have_received(:spawn).with(
|
2013-04-10 05:22:19 +00:00
|
|
|
"sudo redir --laddr=127.0.0.1 --lport=#{host_port} --cport=#{guest_port} --caddr=#{container_ip} 2>/dev/null"
|
2013-03-26 23:00:05 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "stores redir pids on machine's data dir" do
|
2013-07-16 04:56:40 +00:00
|
|
|
subject.stub(system: true)
|
|
|
|
subject.call(env)
|
2013-03-26 23:00:05 +00:00
|
|
|
pid_file = data_dir.join('pids', "redir_#{host_port}.pid").read
|
|
|
|
pid_file.should == pid
|
|
|
|
end
|
2013-07-16 04:56:40 +00:00
|
|
|
|
|
|
|
it 'raises RedirNotInstalled error if `redir` is not installed' do
|
|
|
|
subject.stub(system: false)
|
|
|
|
lambda { subject.call(env) }.should raise_error(Vagrant::LXC::Errors::RedirNotInstalled)
|
|
|
|
end
|
2013-03-26 23:00:05 +00:00
|
|
|
end
|