Add test coverage on new functionality
This commit is contained in:
parent
29880ccd1f
commit
3ebe5b40e3
|
@ -162,6 +162,26 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
|
|||
end
|
||||
end
|
||||
|
||||
describe "reset!" do
|
||||
let(:connection) { double("connection") }
|
||||
|
||||
before do
|
||||
allow(communicator).to receive(:wait_for_ready)
|
||||
allow(connection).to receive(:close)
|
||||
communicator.send(:instance_variable_set, :@connection, connection)
|
||||
end
|
||||
|
||||
it "should close existing connection" do
|
||||
expect(connection).to receive(:close)
|
||||
communicator.reset!
|
||||
end
|
||||
|
||||
it "should call wait_for_ready to re-enable the connection" do
|
||||
expect(communicator).to receive(:wait_for_ready)
|
||||
communicator.reset!
|
||||
end
|
||||
end
|
||||
|
||||
describe ".ready?" do
|
||||
before(&connection_setup)
|
||||
it "returns true if shell test is successful" do
|
||||
|
|
|
@ -57,6 +57,13 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do
|
|||
end
|
||||
end
|
||||
|
||||
describe ".reset!" do
|
||||
it "should create a new shell" do
|
||||
expect(subject).to receive(:shell).with(true)
|
||||
subject.reset!
|
||||
end
|
||||
end
|
||||
|
||||
describe ".ready?" do
|
||||
it "returns true if hostname command executes without error" do
|
||||
expect(shell).to receive(:cmd).with("hostname").and_return({ exitcode: 0 })
|
||||
|
|
|
@ -109,6 +109,31 @@ describe "VagrantPlugins::Shell::Config" do
|
|||
I18n.t("vagrant.provisioners.shell.env_must_be_a_hash")
|
||||
)
|
||||
end
|
||||
|
||||
it "returns an error if file and script are unset" do
|
||||
subject.finalize!
|
||||
result = subject.validate(machine)
|
||||
expect(result["shell provisioner"]).to include(
|
||||
I18n.t("vagrant.provisioners.shell.no_path_or_inline")
|
||||
)
|
||||
end
|
||||
|
||||
it "returns an error if inline and path are both set" do
|
||||
subject.inline = "script"
|
||||
subject.path = "script"
|
||||
result = subject.validate(machine)
|
||||
expect(result["shell provisioner"]).to include(
|
||||
I18n.t("vagrant.provisioners.shell.path_and_inline_set")
|
||||
)
|
||||
end
|
||||
|
||||
it "returns no error when inline and path are unset but reset is true" do
|
||||
subject.reset = true
|
||||
subject.finalize!
|
||||
|
||||
result = subject.validate(machine)
|
||||
expect(result["shell provisioner"]).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe 'finalize!' do
|
||||
|
|
|
@ -16,6 +16,52 @@ describe "Vagrant::Shell::Provisioner" do
|
|||
allow(env).to receive(:tmp_path).and_return(Pathname.new("/dev/null"))
|
||||
end
|
||||
|
||||
context "when reset is enabled" do
|
||||
let(:path) { nil }
|
||||
let(:inline) { "" }
|
||||
let(:communicator) { double("communicator") }
|
||||
|
||||
let(:config) {
|
||||
double(
|
||||
:config,
|
||||
:args => "doesn't matter",
|
||||
:env => {},
|
||||
:upload_path => "arbitrary",
|
||||
:remote? => false,
|
||||
:path => path,
|
||||
:inline => inline,
|
||||
:binary => false,
|
||||
:reset => true
|
||||
)
|
||||
}
|
||||
|
||||
let(:vsp) {
|
||||
VagrantPlugins::Shell::Provisioner.new(machine, config)
|
||||
}
|
||||
|
||||
before {
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
allow(vsp).to receive(:provision_ssh)
|
||||
}
|
||||
|
||||
it "should provision and then reset the connection" do
|
||||
expect(vsp).to receive(:provision_ssh)
|
||||
expect(communicator).to receive(:reset!)
|
||||
vsp.provision
|
||||
end
|
||||
|
||||
context "when path and inline are not set" do
|
||||
let(:path) { nil }
|
||||
let(:inline) { nil }
|
||||
|
||||
it "should reset the connection and not provision" do
|
||||
expect(vsp).not_to receive(:provision_ssh)
|
||||
expect(communicator).to receive(:reset!)
|
||||
vsp.provision
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with a script that contains invalid us-ascii byte sequences" do
|
||||
let(:config) {
|
||||
double(
|
||||
|
@ -27,6 +73,7 @@ describe "Vagrant::Shell::Provisioner" do
|
|||
:path => nil,
|
||||
:inline => script_that_is_incorrectly_us_ascii_encoded,
|
||||
:binary => false,
|
||||
:reset => false
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -59,6 +106,7 @@ describe "Vagrant::Shell::Provisioner" do
|
|||
:path => nil,
|
||||
:inline => script,
|
||||
:binary => false,
|
||||
:reset => false
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -87,7 +135,8 @@ describe "Vagrant::Shell::Provisioner" do
|
|||
:path => "http://example.com/script.sh",
|
||||
:binary => false,
|
||||
:md5 => nil,
|
||||
:sha1 => 'EXPECTED_VALUE'
|
||||
:sha1 => 'EXPECTED_VALUE',
|
||||
:reset => false
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -117,7 +166,8 @@ describe "Vagrant::Shell::Provisioner" do
|
|||
:path => "http://example.com/script.sh",
|
||||
:binary => false,
|
||||
:md5 => 'EXPECTED_VALUE',
|
||||
:sha1 => nil
|
||||
:sha1 => nil,
|
||||
:reset => false
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue