Skip to content

Commit 72a8021

Browse files
committed
Add WaitForCommunicator test
1 parent c4fa5df commit 72a8021

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
require File.expand_path("../../../../base", __FILE__)
2+
3+
describe Vagrant::Action::Builtin::WaitForCommunicator do
4+
let(:app) { lambda { |env| } }
5+
let(:ui) { lambda { |env| } }
6+
let(:env) { { machine: machine, ui: ui } }
7+
8+
let(:vm) do
9+
double("vm",
10+
communicator: nil
11+
)
12+
end
13+
14+
# Configuration mock
15+
let(:config) { double("config", vm: vm) }
16+
17+
# Communicate mock
18+
let(:communicate) { double("communicate") }
19+
20+
let(:state) { double("state") }
21+
22+
let(:ui) { Vagrant::UI::Silent.new }
23+
24+
let(:machine) do
25+
double("machine",
26+
config: config,
27+
communicate: communicate,
28+
state: state,)
29+
end
30+
31+
before do
32+
allow(vm).to receive(:boot_timeout).and_return(1)
33+
allow(communicate).to receive(:wait_for_ready).with(1).and_return(true)
34+
end
35+
36+
it "raise an error if a bad state is encountered" do
37+
allow(state).to receive(:id).and_return(:stopped)
38+
39+
expect { described_class.new(app, env, [:running]).call(env) }.
40+
to raise_error(Vagrant::Errors::VMBootBadState)
41+
end
42+
43+
it "raise an error if the vm doesn't boot" do
44+
allow(communicate).to receive(:wait_for_ready).and_return(false)
45+
allow(state).to receive(:id).and_return(:running)
46+
47+
expect { described_class.new(app, env, [:running]).call(env) }.
48+
to raise_error(Vagrant::Errors::VMBootTimeout)
49+
end
50+
51+
it "succeed when a valid state is encountered" do
52+
allow(communicate).to receive(:wait_for_ready).and_return(true)
53+
allow(state).to receive(:id).and_return(:running)
54+
55+
expect { described_class.new(app, env, [:running]).call(env) }.
56+
to_not raise_error()
57+
end
58+
end

0 commit comments

Comments
 (0)