2014-11-14 20:51:35 +00:00
|
|
|
require_relative "../../../base"
|
|
|
|
|
|
|
|
require Vagrant.source_root.join("plugins/pushes/local-exec/push")
|
|
|
|
|
|
|
|
describe VagrantPlugins::LocalExecPush::Push do
|
|
|
|
include_context "unit"
|
|
|
|
|
|
|
|
before(:all) do
|
|
|
|
I18n.load_path << Vagrant.source_root.join("plugins/pushes/local-exec/locales/en.yml")
|
|
|
|
I18n.reload!
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:env) { isolated_environment }
|
|
|
|
let(:config) do
|
|
|
|
double("config",
|
2014-11-17 18:16:39 +00:00
|
|
|
script: nil,
|
|
|
|
inline: nil,
|
2014-11-14 20:51:35 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(env, config) }
|
|
|
|
|
2014-11-17 18:16:39 +00:00
|
|
|
before do
|
|
|
|
allow(env).to receive(:root_path)
|
|
|
|
.and_return(File.expand_path("..", __FILE__))
|
|
|
|
end
|
|
|
|
|
2014-11-14 20:51:35 +00:00
|
|
|
describe "#push" do
|
2014-11-17 18:16:39 +00:00
|
|
|
before do
|
|
|
|
allow(subject).to receive(:execute_inline!)
|
|
|
|
allow(subject).to receive(:execute_script!)
|
|
|
|
allow(subject).to receive(:execute!)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when inline is given" do
|
|
|
|
before { allow(config).to receive(:inline).and_return("echo") }
|
|
|
|
|
|
|
|
it "executes the inline script" do
|
|
|
|
expect(subject).to receive(:execute_inline!)
|
|
|
|
.with(config.inline)
|
|
|
|
subject.push
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when script is given" do
|
|
|
|
before { allow(config).to receive(:script).and_return("foo.sh") }
|
|
|
|
|
|
|
|
it "executes the script" do
|
|
|
|
expect(subject).to receive(:execute_script!)
|
|
|
|
.with(config.script)
|
|
|
|
subject.push
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#execute_inline!" do
|
|
|
|
before { allow(subject).to receive(:execute_script!) }
|
|
|
|
|
|
|
|
it "writes the script to a tempfile" do
|
|
|
|
expect(Tempfile).to receive(:new).and_call_original
|
|
|
|
subject.execute_inline!("echo")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "executes the script" do
|
|
|
|
expect(subject).to receive(:execute_script!)
|
|
|
|
subject.execute_inline!("echo")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#execute_script!" do
|
2014-11-14 20:51:35 +00:00
|
|
|
before do
|
|
|
|
allow(subject).to receive(:execute!)
|
2014-11-17 18:16:39 +00:00
|
|
|
allow(FileUtils).to receive(:chmod)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "expands the path relative to the machine root" do
|
|
|
|
expect(subject).to receive(:execute!)
|
|
|
|
.with(File.expand_path("foo.sh", env.root_path))
|
|
|
|
subject.execute_script!("./foo.sh")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "makes the file executable" do
|
|
|
|
expect(FileUtils).to receive(:chmod)
|
|
|
|
.with("+x", File.expand_path("foo.sh", env.root_path))
|
|
|
|
subject.execute_script!("./foo.sh")
|
2014-11-14 20:51:35 +00:00
|
|
|
end
|
|
|
|
|
2014-11-17 18:16:39 +00:00
|
|
|
it "calls execute!" do
|
2014-11-14 20:51:35 +00:00
|
|
|
expect(subject).to receive(:execute!)
|
2014-11-17 18:16:39 +00:00
|
|
|
.with(File.expand_path("foo.sh", env.root_path))
|
|
|
|
subject.execute_script!("./foo.sh")
|
2014-11-14 20:51:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#execute!" do
|
2015-11-20 00:55:48 +00:00
|
|
|
it "uses exec on unix" do
|
|
|
|
allow(Vagrant::Util::Platform).to receive(:windows?).and_return(false)
|
2014-12-15 04:36:32 +00:00
|
|
|
expect(Vagrant::Util::SafeExec).to receive(:exec)
|
2014-11-14 20:51:35 +00:00
|
|
|
expect { subject.execute! }.to_not raise_error
|
|
|
|
end
|
2015-11-20 00:55:48 +00:00
|
|
|
|
|
|
|
it "uses subprocess on windows" do
|
|
|
|
allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true)
|
|
|
|
result = double("result", exit_code: 0)
|
|
|
|
expect(Vagrant::Util::Subprocess).to receive(:execute).and_return(result)
|
|
|
|
expect { subject.execute! }.to raise_error { |e|
|
|
|
|
expect(e).to be_a(SystemExit)
|
|
|
|
}
|
|
|
|
end
|
2014-11-14 20:51:35 +00:00
|
|
|
end
|
|
|
|
end
|