Expect group variables to be inserted in the test.

This commit is contained in:
Christian Henz 2015-12-01 14:25:41 +01:00
parent a5ff241586
commit 3fbbfeb862
1 changed files with 24 additions and 4 deletions

View File

@ -245,15 +245,11 @@ VF
"group3" => ["unknown", "#{machine.name}"], "group3" => ["unknown", "#{machine.name}"],
"bar" => ["#{machine.name}", "group3"], "bar" => ["#{machine.name}", "group3"],
"bar:children" => ["group1", "group2", "group3", "group4"], "bar:children" => ["group1", "group2", "group3", "group4"],
"bar:vars" => ["myvar=foo"],
} }
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
inventory_content = File.read(generated_inventory_file) 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 # 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]\n#{machine.name}\n")
expect(inventory_content).to include("[group1:children]\nbar\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") expect(inventory_content).to include("[bar:children]\ngroup1\ngroup2\ngroup3\n")
} }
end 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 end
describe "with host_key_checking option enabled" do describe "with host_key_checking option enabled" do