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 "command plugin helpers"
let(:iso_env) { isolated_environment }
let(:env) do
iso_env.vagrantfile(<<-VF)
Vagrant.configure("2") do |config|
config.vm.box = "nope"
isolated_environment.tap do |env|
env.vagrantfile("")
env.create_vagrant_env
end
VF
iso_env.create_vagrant_env
end
let(:argv) { [] }
@ -38,17 +35,6 @@ VF
subject.execute
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
expect(env).to receive(:push).once
subject.execute

View File

@ -991,7 +991,7 @@ VF
end
def push
!!self.class.class_variable_set(:@@pushed, true)
self.class.class_variable_set(:@@pushed, true)
end
end
end
@ -1005,6 +1005,7 @@ VF
environment = isolated_environment do |env|
env.vagrantfile(<<-VF.gsub(/^ {10}/, ''))
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.push.define "lolwatbacon"
end
VF
@ -1015,6 +1016,58 @@ VF
.to raise_error(Vagrant::Errors::PushStrategyNotLoaded)
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
register_plugin("2") do |plugin|
plugin.name "foo"
@ -1027,6 +1080,7 @@ VF
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