Add tests for sending metadata

This commit is contained in:
Seth Vargo 2015-02-04 11:45:02 -05:00
parent 257ff57772
commit 7d25a687ca
2 changed files with 40 additions and 14 deletions

View File

@ -58,10 +58,20 @@ module VagrantPlugins
#
# @return [Array<String>]
def metadata
hash = {
"box" => env.vagrantfile.config.vm.box,
"box_url" => env.vagrantfile.config.vm.box_url,
}.reject { |k,v| v.nil? || v.empty? }
box = env.vagrantfile.config.vm.box
box_url = env.vagrantfile.config.vm.box_url
result = {}
if !box.nil? && !box.empty?
result["box"] = box
end
if !box_url.nil? && !box_url.empty?
result["box_url"] = Array(box_url).first
end
return result
end
end
end

View File

@ -8,17 +8,10 @@ describe VagrantPlugins::AtlasPush::Push do
let(:bin) { VagrantPlugins::AtlasPush::Push::UPLOADER_BIN }
# let(:env) do
# double("env",
# root_path: File.expand_path("..", __FILE__)
# )
# end
let(:env) do
# We have to create a Vagrantfile so there is a root path
env = isolated_environment
env.vagrantfile("")
env.create_vagrant_env
iso_env = isolated_environment
iso_env.vagrantfile("")
iso_env.create_vagrant_env
end
let(:config) do
@ -106,6 +99,29 @@ describe VagrantPlugins::AtlasPush::Push do
config.token = "atlas_token"
subject.execute("foo")
end
context "when metadata is available" do
let(:env) do
iso_env = isolated_environment
iso_env.vagrantfile <<-EOH
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise64"
config.vm.box_url = "https://atlas.hashicorp.com/hashicorp/precise64"
end
EOH
iso_env.create_vagrant_env
end
it "sends the metadata" do
expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", "-vcs", "-metadata", "box=hashicorp/precise64",
"-metadata", "box_url=https://atlas.hashicorp.com/hashicorp/precise64",
"-token", "atlas_token", app, env.root_path.to_s)
config.token = "atlas_token"
subject.execute("foo")
end
end
end
describe "#uploader_path" do