From 3fbbfeb8628ee16fa660ec4a9db44867eeef62bb Mon Sep 17 00:00:00 2001 From: Christian Henz Date: Tue, 1 Dec 2015 14:25:41 +0100 Subject: [PATCH] Expect group variables to be inserted in the test. --- .../provisioners/ansible/provisioner_test.rb | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/test/unit/plugins/provisioners/ansible/provisioner_test.rb b/test/unit/plugins/provisioners/ansible/provisioner_test.rb index 55b40cd18..a382dfc71 100644 --- a/test/unit/plugins/provisioners/ansible/provisioner_test.rb +++ b/test/unit/plugins/provisioners/ansible/provisioner_test.rb @@ -245,15 +245,11 @@ VF "group3" => ["unknown", "#{machine.name}"], "bar" => ["#{machine.name}", "group3"], "bar:children" => ["group1", "group2", "group3", "group4"], - "bar:vars" => ["myvar=foo"], } expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| inventory_content = File.read(generated_inventory_file) - # Group variables are intentionally not supported in generated inventory - expect(inventory_content).not_to match(/^\[.*:vars\]$/) - # Accept String instead of Array for group that contains a single item expect(inventory_content).to include("[group1]\n#{machine.name}\n") expect(inventory_content).to include("[group1:children]\nbar\n") @@ -272,6 +268,30 @@ VF expect(inventory_content).to include("[bar:children]\ngroup1\ngroup2\ngroup3\n") } end + + it "adds group vars to the generated inventory" do + config.groups = { + "group1" => [machine.name], + "group2" => [machine.name], + "group3" => [machine.name], + "group1:vars" => {"hashvar1" => "hashvalue1", "hashvar2" => "hashvalue2"}, + "group2:vars" => ["arrayvar1=arrayvalue1", "arrayvar2=arrayvalue2"], + "group3:vars" => "stringvar1=stringvalue1 stringvar2=stringvalue2", + } + + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + inventory_content = File.read(generated_inventory_file) + + # Hash syntax + expect(inventory_content).to include("[group1:vars]\nhashvar1=hashvalue1\nhashvar2=hashvalue2\n") + + # Array syntax + expect(inventory_content).to include("[group2:vars]\narrayvar1=arrayvalue1\narrayvar2=arrayvalue2\n") + + # Single string syntax + expect(inventory_content).to include("[group3:vars]\nstringvar1=stringvalue1\nstringvar2=stringvalue2\n") + } + end end describe "with host_key_checking option enabled" do