Machine queries state from the provider
This commit is contained in:
parent
353610021c
commit
8fc5591b8e
|
@ -28,17 +28,26 @@ module Vagrant
|
|||
# Initialize a new machine.
|
||||
#
|
||||
# @param [String] name Name of the virtual machine.
|
||||
# @param [Object] provider The provider backing this machine. This is
|
||||
# @param [Class] provider The provider backing this machine. This is
|
||||
# currently expected to be a V1 `provider` plugin.
|
||||
# @param [Object] config The configuration for this machine.
|
||||
# @param [Box] box The box that is backing this virtual machine.
|
||||
# @param [Environment] env The environment that this machine is a
|
||||
# part of.
|
||||
def initialize(name, provider, config, box, env)
|
||||
@name = name
|
||||
@config = config
|
||||
@box = box
|
||||
@env = env
|
||||
def initialize(name, provider_cls, config, box, env)
|
||||
@name = name
|
||||
@box = box
|
||||
@config = config
|
||||
@env = env
|
||||
@provider = provider_cls.new(self)
|
||||
end
|
||||
|
||||
# Returns the state of this machine. The state is queried from the
|
||||
# backing provider, so it can be any arbitrary symbol.
|
||||
#
|
||||
# @return [Symbol]
|
||||
def state
|
||||
@provider.state
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,12 +4,39 @@ describe Vagrant::Machine do
|
|||
include_context "unit"
|
||||
|
||||
let(:name) { "foo" }
|
||||
let(:provider) { Object.new }
|
||||
let(:provider) { double("provider") }
|
||||
let(:provider_cls) do
|
||||
obj = double("provider_cls")
|
||||
obj.stub(:new => provider)
|
||||
obj
|
||||
end
|
||||
let(:box) { Object.new }
|
||||
let(:config) { Object.new }
|
||||
let(:environment) { isolated_environment }
|
||||
|
||||
let(:instance) { described_class.new(name, provider, config, box, environment) }
|
||||
let(:instance) { described_class.new(name, provider_cls, config, box, environment) }
|
||||
|
||||
describe "initialization" do
|
||||
it "should initialize the provider with the machine object" do
|
||||
received_machine = nil
|
||||
|
||||
provider_cls = double("provider_cls")
|
||||
provider_cls.should_receive(:new) do |machine|
|
||||
# Store this for later so we can verify that it is the
|
||||
# one we expected to receive.
|
||||
received_machine = machine
|
||||
|
||||
# Verify the machine is fully ready to be used.
|
||||
machine.name.should == name
|
||||
machine.config.should eql(config)
|
||||
machine.box.should eql(box)
|
||||
machine.env.should eql(environment)
|
||||
end
|
||||
|
||||
instance = described_class.new(name, provider_cls, config, box, environment)
|
||||
received_machine.should eql(instance)
|
||||
end
|
||||
end
|
||||
|
||||
describe "attributes" do
|
||||
it "should provide access to the name" do
|
||||
|
@ -28,4 +55,13 @@ describe Vagrant::Machine do
|
|||
instance.env.should eql(environment)
|
||||
end
|
||||
end
|
||||
|
||||
describe "state" do
|
||||
it "should query state from the provider" do
|
||||
state = :running
|
||||
|
||||
provider.should_receive(:state).and_return(state)
|
||||
instance.state.should == state
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue