From c4eb0261bbd845f6a7d118c418ec108a714c1fef Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 7 Jan 2015 13:20:53 -0500 Subject: [PATCH] Add tests for validating push configuration --- .../plugins/commands/push/command_test.rb | 22 ++------ test/unit/vagrant/environment_test.rb | 56 ++++++++++++++++++- 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/test/unit/plugins/commands/push/command_test.rb b/test/unit/plugins/commands/push/command_test.rb index 0f649c6c4..06995d51d 100644 --- a/test/unit/plugins/commands/push/command_test.rb +++ b/test/unit/plugins/commands/push/command_test.rb @@ -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" -end -VF - iso_env.create_vagrant_env + isolated_environment.tap do |env| + env.vagrantfile("") + env.create_vagrant_env + end 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 diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index 02effd7db..84d7975d7 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -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