Sha256: fee41a335a598539377d23192da3c70b95109a353944af5e5596ab21b7d5119b

Contents?: true

Size: 1.19 KB

Versions: 18

Compression:

Stored size: 1.19 KB

Contents

require 'unit_helper'

require 'tmpdir'
require 'vagrant-lxc/action/clear_forwarded_ports'

describe Vagrant::LXC::Action::ClearForwardedPorts do
  let(:app)       { double(:app, call: true) }
  let(:env)       { {machine: machine, ui: double(info: true)} }
  let(:machine)   { double(:machine, data_dir: data_dir) }
  let!(:data_dir) { Pathname.new(Dir.mktmpdir) }
  let(:pids_dir)  { data_dir.join('pids') }
  let(:pid)       { 'a-pid' }
  let(:pid_cmd)   { 'redir' }

  subject { described_class.new(app, env) }

  before do
    pids_dir.mkdir
    pids_dir.join('redir_1234.pid').open('w') { |f| f.write(pid) }
    subject.stub(system: true, :` => pid_cmd)
    subject.call(env)
  end

  after { FileUtils.rm_rf data_dir.to_s }

  it 'removes all files under pid directory' do
    expect(Dir[pids_dir.to_s + "/redir_*.pid"]).to be_empty
  end

  context 'with a valid redir pid' do
    it 'kills known processes' do
      expect(subject).to have_received(:system).with("pkill -TERM -P #{pid}")
    end
  end

  context 'with an invalid pid' do
    let(:pid_cmd) { 'sudo ls' }

    it 'does not kill the process' do
      expect(subject).not_to have_received(:system).with("pkill -TERM -P #{pid}")
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
vagrant-lxc-1.4.3 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.4.2 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.4.1 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-2.1-patch-1.4.0 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.4.0 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.3.1 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.3.0 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.2.4 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.2.3 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.2.2 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.2.1 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.2.0 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.1.0 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.0.1 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.0.0 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.0.0.alpha.3 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.0.0.alpha.2 spec/unit/action/clear_forwarded_ports_spec.rb
vagrant-lxc-1.0.0.alpha.1 spec/unit/action/clear_forwarded_ports_spec.rb