Add tests for validating push configuration

This commit is contained in:
Seth Vargo 2015-01-07 13:20:53 -05:00
parent 6b51526ba2
commit c4eb0261bb
2 changed files with 59 additions and 19 deletions

View File

@ -6,14 +6,11 @@ describe VagrantPlugins::CommandPush::Command do
include_context "unit" include_context "unit"
include_context "command plugin helpers" include_context "command plugin helpers"
let(:iso_env) { isolated_environment }
let(:env) do let(:env) do
iso_env.vagrantfile(<<-VF) isolated_environment.tap do |env|
Vagrant.configure("2") do |config| env.vagrantfile("")
config.vm.box = "nope" env.create_vagrant_env
end end
VF
iso_env.create_vagrant_env
end end
let(:argv) { [] } let(:argv) { [] }
@ -38,17 +35,6 @@ VF
subject.execute subject.execute
end end
it "validates the configuration" do
iso_env.vagrantfile("")
subject = described_class.new(argv, iso_env.create_vagrant_env)
allow(subject).to receive(:validate_pushes!)
.and_return(:noop)
expect { subject.execute }.to raise_error(
Vagrant::Errors::ConfigInvalid)
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

View File

@ -991,7 +991,7 @@ VF
end end
def push def push
!!self.class.class_variable_set(:@@pushed, true) self.class.class_variable_set(:@@pushed, true)
end end
end end
end end
@ -1005,6 +1005,7 @@ VF
environment = isolated_environment do |env| environment = isolated_environment do |env|
env.vagrantfile(<<-VF.gsub(/^ {10}/, '')) env.vagrantfile(<<-VF.gsub(/^ {10}/, ''))
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.push.define "lolwatbacon" config.push.define "lolwatbacon"
end end
VF VF
@ -1015,6 +1016,58 @@ VF
.to raise_error(Vagrant::Errors::PushStrategyNotLoaded) .to raise_error(Vagrant::Errors::PushStrategyNotLoaded)
end end
it "runs global config validation" do
environment = isolated_environment do |env|
env.vagrantfile(<<-VF.gsub(/^ {10}/, ''))
Vagrant.configure("2") do |config|
config.push.define "noop"
end
VF
end
env = environment.create_vagrant_env
expect { env.push("noop") }
.to raise_error(Vagrant::Errors::ConfigInvalid)
end
it "runs push config validations" do
config_class = Class.new(Vagrant.plugin("2", :config)) do
def self.validated?
!!class_variable_get(:@@validated)
end
def validate(machine)
self.class.class_variable_set(:@@validated, true)
{}
end
end
register_plugin("2") do |plugin|
plugin.name "foo"
plugin.config(:foo, :push) do
config_class
end
plugin.push(:foo) do
push_class
end
end
environment = isolated_environment do |env|
env.vagrantfile(<<-VF.gsub(/^ {10}/, ''))
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.push.define "foo"
end
VF
end
env = environment.create_vagrant_env
env.push("foo")
expect(config_class.validated?).to be(true)
end
it "executes the push action" do it "executes the push action" do
register_plugin("2") do |plugin| register_plugin("2") do |plugin|
plugin.name "foo" plugin.name "foo"
@ -1027,6 +1080,7 @@ VF
environment = isolated_environment do |env| environment = isolated_environment do |env|
env.vagrantfile(<<-VF.gsub(/^ {10}/, '')) env.vagrantfile(<<-VF.gsub(/^ {10}/, ''))
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.push.define "foo" config.push.define "foo"
end end
VF VF