provisioners/ansible: fix unit tests for [GH-3491]

This commit is contained in:
Gilles Cornu 2014-04-26 14:08:10 +02:00
parent 7ef8477e43
commit de6ad1d5d3
1 changed files with 25 additions and 12 deletions

View File

@ -68,13 +68,6 @@ VF
expect(args[1]).to eq("--private-key=#{machine.ssh_info[:private_key_path][0]}") expect(args[1]).to eq("--private-key=#{machine.ssh_info[:private_key_path][0]}")
expect(args[2]).to eq("--user=#{machine.ssh_info[:username]}") expect(args[2]).to eq("--user=#{machine.ssh_info[:username]}")
limit_index = args.index("--limit=#{machine.name}")
expect(limit_index).to be > 2
expect(limit_index).to be < 5
if (limit_index == 4)
expect(args[3]).to match("--connection=ssh")
end
inventory_count = args.count { |x| x =~ /--inventory-file=.+/ } inventory_count = args.count { |x| x =~ /--inventory-file=.+/ }
expect(inventory_count).to be > 0 expect(inventory_count).to be > 0
@ -82,6 +75,24 @@ VF
} }
end end
it "sets --limit argument" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
raw_limits = []
if config.raw_arguments
raw_limits = config.raw_arguments.select { |x| x =~ /--limit=|-l/ }
end
all_limits = args.select { |x| x =~ /--limit=|-l/ }
expect((all_limits - raw_limits).length).to eq(1)
if config.limit
limit = config.limit.kind_of?(Array) ? config.limit.join(',') : config.limit
expect(all_limits.last).to eq("--limit=#{limit}")
else
expect(all_limits.first).to eq("--limit=#{machine.name}")
end
}
end
it "exports environment variables" do it "exports environment variables" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
cmd_opts = args.last cmd_opts = args.last
@ -295,11 +306,14 @@ VF
"--skip-tags=ignored", "--skip-tags=ignored",
"--module-path=/other/modules", "--module-path=/other/modules",
"--sudo", "--sudo",
"-l localhost",
"--limit=foo",
"--limit=bar",
"--inventory-file=/forget/it/my/friend", "--inventory-file=/forget/it/my/friend",
"--new-arg=yeah"] "--new-arg=yeah"]
end end
it_should_set_arguments_and_environment_variables 12 it_should_set_arguments_and_environment_variables 15
it_should_create_and_use_generated_inventory it_should_create_and_use_generated_inventory
it_should_use_transport_mode('paramiko') it_should_use_transport_mode('paramiko')
@ -330,8 +344,7 @@ VF
config.limit = %w(foo !bar) config.limit = %w(foo !bar)
end end
it_should_set_arguments_and_environment_variables 5 it_should_set_arguments_and_environment_variables
it_should_set_optional_arguments({ "limit" => "--limit=foo,!bar" })
end end
describe "with inventory_path option" do describe "with inventory_path option" do
@ -450,14 +463,14 @@ VF
config.skip_tags = %w(foo bar) config.skip_tags = %w(foo bar)
config.limit = 'machine*:&vagrant:!that_one' config.limit = 'machine*:&vagrant:!that_one'
config.start_at_task = 'an awesome task' config.start_at_task = 'an awesome task'
config.raw_arguments = ["--why-not", "--su-user=foot", "--ask-su-pass"] config.raw_arguments = ["--why-not", "--su-user=foot", "--ask-su-pass", "--limit=all"]
# environment variables # environment variables
config.host_key_checking = true config.host_key_checking = true
config.raw_ssh_args = ['-o ControlMaster=no'] config.raw_ssh_args = ['-o ControlMaster=no']
end end
it_should_set_arguments_and_environment_variables 19, 4, true it_should_set_arguments_and_environment_variables 20, 4, true
it_should_force_ssh_transport_mode it_should_force_ssh_transport_mode
it_should_set_optional_arguments({ "extra_vars" => "--extra-vars=@#{File.expand_path(__FILE__)}", it_should_set_optional_arguments({ "extra_vars" => "--extra-vars=@#{File.expand_path(__FILE__)}",
"sudo" => "--sudo", "sudo" => "--sudo",