Isolate push deprecation to atlas strategy only

This commit is contained in:
Chris Roberts 2017-03-21 14:50:12 -07:00
parent e0b9a6fabd
commit 72d0eb497d
5 changed files with 149 additions and 146 deletions

View File

@ -29,11 +29,11 @@ module Vagrant
end end
alias_method :non_deprecated_execute, :execute alias_method :non_deprecated_execute, :execute
def execute def execute(*args, &block)
@env[:ui].warn(I18n.t("vagrant.commands.deprecated", @env[:ui].warn(I18n.t("vagrant.commands.deprecated",
name: deprecation_command_name name: deprecation_command_name
) + "\n") ) + "\n")
non_deprecated_execute non_deprecated_execute(*args, &block)
end end
end end
end end
@ -44,7 +44,7 @@ module Vagrant
def self.included(klass) def self.included(klass)
klass.include(CommandDeprecation) klass.include(CommandDeprecation)
klass.class_eval do klass.class_eval do
def execute def execute(*_)
raise Vagrant::Errors::CommandDeprecated, raise Vagrant::Errors::CommandDeprecated,
name: deprecation_command_name name: deprecation_command_name
end end

View File

@ -70,8 +70,6 @@ module VagrantPlugins
return name return name
end end
include Vagrant::Util::CommandDeprecation::Complete
end end
end end
end end

View File

@ -73,6 +73,12 @@ module VagrantPlugins
return result return result
end end
include Vagrant::Util::CommandDeprecation::Complete
def deprecation_command_name
"push (atlas strategy)"
end
end end
end end
end end

View File

@ -33,37 +33,35 @@ describe VagrantPlugins::CommandPush::Command do
allow(env).to receive(:push) allow(env).to receive(:push)
end end
# NOTE: Disabled due to deprecation it "validates the pushes" do
# expect(subject).to receive(:validate_pushes!).once
# it "validates the pushes" do subject.execute
# expect(subject).to receive(:validate_pushes!).once end
# subject.execute
# end
# it "delegates to Environment#push" do it "delegates to Environment#push" do
# expect(env).to receive(:push).once expect(env).to receive(:push).once
# subject.execute subject.execute
# end end
# it "validates the configuration" do it "validates the configuration" do
# iso_env.vagrantfile <<-EOH iso_env.vagrantfile <<-EOH
# Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
# config.vm.box = "hashicorp/precise64" config.vm.box = "hashicorp/precise64"
# config.push.define "noop" do |push| config.push.define "noop" do |push|
# push.bad = "ham" push.bad = "ham"
# end end
# end end
# EOH EOH
# subject = described_class.new(argv, iso_env.create_vagrant_env) subject = described_class.new(argv, iso_env.create_vagrant_env)
# allow(subject).to receive(:validate_pushes!) allow(subject).to receive(:validate_pushes!)
# .and_return(:noop) .and_return(:noop)
# expect { subject.execute }.to raise_error(Vagrant::Errors::ConfigInvalid) { |err| expect { subject.execute }.to raise_error(Vagrant::Errors::ConfigInvalid) { |err|
# expect(err.message).to include("The following settings shouldn't exist: bad") expect(err.message).to include("The following settings shouldn't exist: bad")
# } }
# end end
end end
describe "#validate_pushes!" do describe "#validate_pushes!" do

View File

@ -27,154 +27,155 @@ describe VagrantPlugins::AtlasPush::Push do
allow(Vagrant::Util::SafeExec).to receive(:exec) allow(Vagrant::Util::SafeExec).to receive(:exec)
end end
describe "#push" do # DEPRECATED
it "pushes with the uploader" do # describe "#push" do
allow(subject).to receive(:uploader_path).and_return("foo") # it "pushes with the uploader" do
# allow(subject).to receive(:uploader_path).and_return("foo")
expect(subject).to receive(:execute).with("foo") # expect(subject).to receive(:execute).with("foo")
subject.push # subject.push
end # end
it "raises an exception if the uploader couldn't be found" do # it "raises an exception if the uploader couldn't be found" do
expect(subject).to receive(:uploader_path).and_return(nil) # expect(subject).to receive(:uploader_path).and_return(nil)
expect { subject.push }.to raise_error( # expect { subject.push }.to raise_error(
VagrantPlugins::AtlasPush::Errors::UploaderNotFound) # VagrantPlugins::AtlasPush::Errors::UploaderNotFound)
end # end
end # end
describe "#execute" do # describe "#execute" do
let(:app) { "foo/bar" } # let(:app) { "foo/bar" }
before do # before do
config.app = app # config.app = app
end # end
it "sends the basic flags" do # it "sends the basic flags" do
expect(Vagrant::Util::SafeExec).to receive(:exec). # expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", "-vcs", app, env.root_path.to_s) # with("foo", "-vcs", app, env.root_path.to_s)
subject.execute("foo") # subject.execute("foo")
end # end
it "doesn't send VCS if disabled" do # it "doesn't send VCS if disabled" do
expect(Vagrant::Util::SafeExec).to receive(:exec). # expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", app, env.root_path.to_s) # with("foo", app, env.root_path.to_s)
config.vcs = false # config.vcs = false
subject.execute("foo") # subject.execute("foo")
end # end
it "sends includes" do # it "sends includes" do
expect(Vagrant::Util::SafeExec).to receive(:exec). # expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", "-vcs", "-include", "foo", "-include", # with("foo", "-vcs", "-include", "foo", "-include",
"bar", app, env.root_path.to_s) # "bar", app, env.root_path.to_s)
config.includes = ["foo", "bar"] # config.includes = ["foo", "bar"]
subject.execute("foo") # subject.execute("foo")
end # end
it "sends excludes" do # it "sends excludes" do
expect(Vagrant::Util::SafeExec).to receive(:exec). # expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", "-vcs", "-exclude", "foo", "-exclude", # with("foo", "-vcs", "-exclude", "foo", "-exclude",
"bar", app, env.root_path.to_s) # "bar", app, env.root_path.to_s)
config.excludes = ["foo", "bar"] # config.excludes = ["foo", "bar"]
subject.execute("foo") # subject.execute("foo")
end # end
it "sends custom server address" do # it "sends custom server address" do
expect(Vagrant::Util::SafeExec).to receive(:exec). # expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", "-vcs", "-address", "foo", app, env.root_path.to_s) # with("foo", "-vcs", "-address", "foo", app, env.root_path.to_s)
config.address = "foo" # config.address = "foo"
subject.execute("foo") # subject.execute("foo")
end # end
it "sends custom token" do # it "sends custom token" do
expect(Vagrant::Util::SafeExec).to receive(:exec). # expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", "-vcs", "-token", "atlas_token", app, env.root_path.to_s) # with("foo", "-vcs", "-token", "atlas_token", app, env.root_path.to_s)
config.token = "atlas_token" # config.token = "atlas_token"
subject.execute("foo") # subject.execute("foo")
end # end
context "when metadata is available" do # context "when metadata is available" do
let(:env) do # let(:env) do
iso_env = isolated_environment # iso_env = isolated_environment
iso_env.vagrantfile <<-EOH # iso_env.vagrantfile <<-EOH
Vagrant.configure("2") do |config| # Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64" # config.vm.box = "hashicorp/precise64"
config.vm.box_url = "https://atlas.hashicorp.com/hashicorp/precise64" # config.vm.box_url = "https://atlas.hashicorp.com/hashicorp/precise64"
end # end
EOH # EOH
iso_env.create_vagrant_env # iso_env.create_vagrant_env
end # end
it "sends the metadata" do # it "sends the metadata" do
expect(Vagrant::Util::SafeExec).to receive(:exec). # expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", "-vcs", "-metadata", "box=hashicorp/precise64", # with("foo", "-vcs", "-metadata", "box=hashicorp/precise64",
"-metadata", "box_url=https://atlas.hashicorp.com/hashicorp/precise64", # "-metadata", "box_url=https://atlas.hashicorp.com/hashicorp/precise64",
"-token", "atlas_token", app, env.root_path.to_s) # "-token", "atlas_token", app, env.root_path.to_s)
config.token = "atlas_token" # config.token = "atlas_token"
subject.execute("foo") # subject.execute("foo")
end # end
end # end
end # end
describe "#uploader_path" do # describe "#uploader_path" do
let(:scratch) do # let(:scratch) do
Pathname.new(Dir.mktmpdir("vagrant-test-atlas-push-upload-path")) # Pathname.new(Dir.mktmpdir("vagrant-test-atlas-push-upload-path"))
end # end
after do # after do
FileUtils.rm_rf(scratch) # FileUtils.rm_rf(scratch)
end # end
it "should return the configured path if set" do # it "should return the configured path if set" do
config.uploader_path = "foo" # config.uploader_path = "foo"
expect(subject.uploader_path).to eq("foo") # expect(subject.uploader_path).to eq("foo")
end # end
it "should look up the uploader via PATH if not set" do # it "should look up the uploader via PATH if not set" do
allow(Vagrant).to receive(:in_installer?).and_return(false) # allow(Vagrant).to receive(:in_installer?).and_return(false)
expect(Vagrant::Util::Which).to receive(:which). # expect(Vagrant::Util::Which).to receive(:which).
with(described_class.const_get(:UPLOADER_BIN)). # with(described_class.const_get(:UPLOADER_BIN)).
and_return("bar") # and_return("bar")
expect(subject.uploader_path).to eq("bar") # expect(subject.uploader_path).to eq("bar")
end # end
it "should look up the uploader in the embedded dir if installer" do # it "should look up the uploader in the embedded dir if installer" do
allow(Vagrant).to receive(:in_installer?).and_return(true) # allow(Vagrant).to receive(:in_installer?).and_return(true)
allow(Vagrant).to receive(:installer_embedded_dir).and_return(scratch.to_s) # allow(Vagrant).to receive(:installer_embedded_dir).and_return(scratch.to_s)
bin_path = scratch.join("bin", bin) # bin_path = scratch.join("bin", bin)
bin_path.dirname.mkpath # bin_path.dirname.mkpath
bin_path.open("w+") { |f| f.write("hi") } # bin_path.open("w+") { |f| f.write("hi") }
expect(subject.uploader_path).to eq(bin_path.to_s) # expect(subject.uploader_path).to eq(bin_path.to_s)
end # end
it "should look up the uploader in the PATH if not in the installer" do # it "should look up the uploader in the PATH if not in the installer" do
allow(Vagrant).to receive(:in_installer?).and_return(true) # allow(Vagrant).to receive(:in_installer?).and_return(true)
allow(Vagrant).to receive(:installer_embedded_dir).and_return(scratch.to_s) # allow(Vagrant).to receive(:installer_embedded_dir).and_return(scratch.to_s)
expect(Vagrant::Util::Which).to receive(:which). # expect(Vagrant::Util::Which).to receive(:which).
with(described_class.const_get(:UPLOADER_BIN)). # with(described_class.const_get(:UPLOADER_BIN)).
and_return("bar") # and_return("bar")
expect(subject.uploader_path).to eq("bar") # expect(subject.uploader_path).to eq("bar")
end # end
it "should return nil if its not found anywhere" do # it "should return nil if its not found anywhere" do
allow(Vagrant).to receive(:in_installer?).and_return(false) # allow(Vagrant).to receive(:in_installer?).and_return(false)
allow(Vagrant::Util::Which).to receive(:which).and_return(nil) # allow(Vagrant::Util::Which).to receive(:which).and_return(nil)
expect(subject.uploader_path).to be_nil # expect(subject.uploader_path).to be_nil
end # end
end # end
end end