From 3dbcf5083c6bd0ef2731361bf193f102ee549e46 Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Wed, 2 Dec 2015 08:42:44 +0100 Subject: [PATCH] provisioners/ansible(both) add more unit tests Improve the test coverage of 'get_inventory_host_vars_string' method. --- .../provisioners/ansible/provisioner_test.rb | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/test/unit/plugins/provisioners/ansible/provisioner_test.rb b/test/unit/plugins/provisioners/ansible/provisioner_test.rb index 4a352a29e..a98f456fb 100644 --- a/test/unit/plugins/provisioners/ansible/provisioner_test.rb +++ b/test/unit/plugins/provisioners/ansible/provisioner_test.rb @@ -237,9 +237,29 @@ VF describe "with host_vars option" do it_should_create_and_use_generated_inventory - it "adds host variables to the generated inventory" do + it "adds host variables (given in Hash format) to the generated inventory" do config.host_vars = { - machine.name => {"http_port" => 80, "maxRequestsPerChild" => 808} + machine1: {"http_port" => 80, "maxRequestsPerChild" => 808} + } + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + inventory_content = File.read(generated_inventory_file) + expect(inventory_content).to match("^" + Regexp.quote(machine.name) + ".+http_port=80 maxRequestsPerChild=808") + } + end + + it "adds host variables (given in Array format) to the generated inventory" do + config.host_vars = { + machine1: ["http_port=80", "maxRequestsPerChild=808"] + } + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + inventory_content = File.read(generated_inventory_file) + expect(inventory_content).to match("^" + Regexp.quote(machine.name) + ".+http_port=80 maxRequestsPerChild=808") + } + end + + it "adds host variables (given in String format) to the generated inventory " do + config.host_vars = { + :machine1 => "http_port=80 maxRequestsPerChild=808" } expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| inventory_content = File.read(generated_inventory_file)