Adding pip_install_cmd as a default parameter to get_pip. Unit Tests.

This commit is contained in:
Vidroha Debroy 2019-01-25 13:59:15 -06:00
parent da81948212
commit 2b0617fb64
2 changed files with 43 additions and 2 deletions

View File

@ -18,9 +18,9 @@ module VagrantPlugins
machine.communicate.sudo "pip install #{args_array.join(' ')}"
end
def self.get_pip(machine)
def self.get_pip(machine, pip_install_cmd="curl https://bootstrap.pypa.io/get-pip.py | sudo python")
machine.ui.detail I18n.t("vagrant.provisioners.ansible.installing_pip")
machine.communicate.execute "curl https://bootstrap.pypa.io/get-pip.py | sudo python"
machine.communicate.execute pip_install_cmd
end
end

View File

@ -0,0 +1,41 @@
require_relative "../../../../../../base"
require Vagrant.source_root.join("plugins/provisioners/ansible/cap/guest/pip/pip")
describe VagrantPlugins::Ansible::Cap::Guest::Pip do
include_context "unit"
subject { VagrantPlugins::Ansible::Cap::Guest::Pip }
let(:iso_env) do
# We have to create a Vagrantfile so there is a root path
env = isolated_environment
env.vagrantfile("")
env.create_vagrant_env
end
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
let(:communicator) { double("comm") }
before do
allow(machine).to receive(:communicate).and_return(communicator)
allow(communicator).to receive(:execute).and_return(true)
end
describe "#get_pip" do
describe 'when no pip_install_command argument is provided' do
it "installs pip using the default command" do
expect(communicator).to receive(:execute).with("curl https://bootstrap.pypa.io/get-pip.py | sudo python")
subject.get_pip(machine)
end
end
describe 'when pip_install_command argument is provided' do
it "runs the supplied argument instead of default" do
pip_install_command = "foo"
expect(communicator).to receive(:execute).with(pip_install_command)
subject.get_pip(machine,pip_install_command)
end
end
end
end