From 2b0617fb649bb322419fdcd3cf32a3d00387065d Mon Sep 17 00:00:00 2001 From: Vidroha Debroy Date: Fri, 25 Jan 2019 13:59:15 -0600 Subject: [PATCH] Adding pip_install_cmd as a default parameter to get_pip. Unit Tests. --- .../provisioners/ansible/cap/guest/pip/pip.rb | 4 +- .../ansible/cap/guest/pip/pip_test.rb | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 test/unit/plugins/provisioners/ansible/cap/guest/pip/pip_test.rb diff --git a/plugins/provisioners/ansible/cap/guest/pip/pip.rb b/plugins/provisioners/ansible/cap/guest/pip/pip.rb index 370aabd32..98a9ba0b8 100644 --- a/plugins/provisioners/ansible/cap/guest/pip/pip.rb +++ b/plugins/provisioners/ansible/cap/guest/pip/pip.rb @@ -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 diff --git a/test/unit/plugins/provisioners/ansible/cap/guest/pip/pip_test.rb b/test/unit/plugins/provisioners/ansible/cap/guest/pip/pip_test.rb new file mode 100644 index 000000000..79ecf7c1b --- /dev/null +++ b/test/unit/plugins/provisioners/ansible/cap/guest/pip/pip_test.rb @@ -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 \ No newline at end of file