core: MachineIndex valid test is better

This commit is contained in:
Mitchell Hashimoto 2014-05-05 21:50:51 -07:00
parent 5d94ab9e60
commit 45fc89877c
3 changed files with 28 additions and 5 deletions

View File

@ -444,10 +444,7 @@ module Vagrant
end
# Refresh the machine state
machine.state
# If the machine doesn't have an ID, it is invalid
return false if !machine.id
return false if machine.state.id == MachineState::NOT_CREATED_ID
true
end

View File

@ -11,6 +11,26 @@ module VagrantTests
end
class DummyProvider < Vagrant.plugin("2", :provider)
# No-op
def initialize(machine)
@machine = machine
end
def state=(id)
state_file.open("w+") do |f|
f.write(id.to_s)
end
end
def state
state_id = :running
state_id = state_file.read.to_sym if state_file.file?
Vagrant::MachineState.new(state_id, state_id.to_s, state_id.to_s)
end
protected
def state_file
@machine.data_dir.join("dummy_state")
end
end
end

View File

@ -308,6 +308,12 @@ describe Vagrant::MachineIndex::Entry do
expect(subject).to_not be_valid(env.home_path)
end
it "should be invalid if machine is not created" do
machine.id = "foo"
machine.provider.state = Vagrant::MachineState::NOT_CREATED_ID
expect(subject).to_not be_valid(env.home_path)
end
context "with another active machine" do
let(:vagrantfile) do
<<-VF