Skip to content

Commit

Permalink
Merge pull request #285 from Kuniwak/care-nil-instance
Browse files Browse the repository at this point in the history
Fix a bug can be occurred when `instance` returns `nil`
  • Loading branch information
Seth Thomas authored Feb 13, 2017
2 parents f925a7c + 3a60651 commit f3226e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/kitchen/driver/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,13 @@ def local_kitchen_cache
# instance's Vagrantfile
# @api private
def vagrant_root
root = File.join(config[:kitchen_root], %w{.kitchen kitchen-vagrant},
"kitchen-#{File.basename(config[:kitchen_root])}-#{instance.name}"
)
@vagrant_root ||= instance.nil? ? nil : root
if !@vagrant_root && !instance.nil?
@vagrant_root = File.join(
config[:kitchen_root], %w{.kitchen kitchen-vagrant},
"kitchen-#{File.basename(config[:kitchen_root])}-#{instance.name}"
)
end
@vagrant_root
end

# @param type [Symbol] either `:ssh` or `:winrm`
Expand Down
10 changes: 10 additions & 0 deletions spec/kitchen/driver/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
d
end

let(:driver_with_no_instance) do
driver_object
end

let(:instance) do
Kitchen::Instance.new(
:verifier => verifier,
Expand Down Expand Up @@ -540,6 +544,12 @@ def run_command(_cmd, options = {})
driver.verify_dependencies
end

it "passes for supported versions of Vagrant when it has no instances" do
with_modern_vagrant

driver_with_no_instance.verify_dependencies
end

it "raises a UserError for unsupported versions of Vagrant" do
with_unsupported_vagrant

Expand Down

0 comments on commit f3226e7

Please sign in to comment.