From e884dfad7174ab2a5bc1074b209463a02809b43d Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Mon, 5 May 2014 09:08:10 +0200 Subject: [PATCH] provisioners/ansible: try to improve unit tests I still cannot explain the cause of these random errors in this unit test, but it is anyway safe and suitable to update the test code as following: - use stricter regular expression matching (-l is included in --limit) - array lengths substraction instead of array contents substraction --- .../plugins/provisioners/ansible/provisioner_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit/plugins/provisioners/ansible/provisioner_test.rb b/test/unit/plugins/provisioners/ansible/provisioner_test.rb index 05fe103a8..45951e8b3 100644 --- a/test/unit/plugins/provisioners/ansible/provisioner_test.rb +++ b/test/unit/plugins/provisioners/ansible/provisioner_test.rb @@ -68,7 +68,7 @@ VF expect(args[1]).to eq("--private-key=#{machine.ssh_info[:private_key_path][0]}") expect(args[2]).to eq("--user=#{machine.ssh_info[:username]}") - inventory_count = args.count { |x| x =~ /--inventory-file=.+/ } + inventory_count = args.count { |x| x =~ /^--inventory-file=.+$/ } expect(inventory_count).to be > 0 expect(args[args.length-2]).to eq("playbook.yml") @@ -79,10 +79,10 @@ VF 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/ } + 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) + all_limits = args.select { |x| x =~ /^(--limit=|-l)/ } + expect(all_limits.length - raw_limits.length).to eq(1) if config.limit limit = config.limit.kind_of?(Array) ? config.limit.join(',') : config.limit @@ -136,7 +136,7 @@ VF it "does not force any transport mode" do expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| - total = args.count { |x| x =~ /--connection=\w+/ } + total = args.count { |x| x =~ /^--connection=\w+$/ } expect(total).to eql(0) } end