provisioners/ansible: use strict boolean options

With this change, the ansible provisioner fully complies with
the current user documentation.
This commit is contained in:
Gilles Cornu 2014-04-12 11:00:34 +02:00
parent ad038890bb
commit 7ed17ae9ed
4 changed files with 47 additions and 8 deletions

View File

@ -33,7 +33,7 @@ module VagrantPlugins
@skip_tags = UNSET_VALUE
@start_at_task = UNSET_VALUE
@groups = UNSET_VALUE
@host_key_checking = "false"
@host_key_checking = UNSET_VALUE
@raw_arguments = UNSET_VALUE
@raw_ssh_args = UNSET_VALUE
end
@ -42,16 +42,16 @@ module VagrantPlugins
@playbook = nil if @playbook == UNSET_VALUE
@extra_vars = nil if @extra_vars == UNSET_VALUE
@inventory_path = nil if @inventory_path == UNSET_VALUE
@ask_sudo_pass = nil if @ask_sudo_pass == UNSET_VALUE
@ask_sudo_pass = false unless @ask_sudo_pass == true
@limit = nil if @limit == UNSET_VALUE
@sudo = nil if @sudo == UNSET_VALUE
@sudo = false unless @sudo == true
@sudo_user = nil if @sudo_user == UNSET_VALUE
@verbose = nil if @verbose == UNSET_VALUE
@tags = nil if @tags == UNSET_VALUE
@skip_tags = nil if @skip_tags == UNSET_VALUE
@start_at_task = nil if @start_at_task == UNSET_VALUE
@groups = {} if @groups == UNSET_VALUE
@host_key_checking = nil if @host_key_checking == UNSET_VALUE
@host_key_checking = false unless @host_key_checking == true
@raw_arguments = nil if @raw_arguments == UNSET_VALUE
@raw_ssh_args = nil if @raw_ssh_args == UNSET_VALUE
end

View File

@ -1,4 +1,5 @@
require_relative "../../../base"
require_relative "../support/shared/config"
require Vagrant.source_root.join("plugins/provisioners/ansible/config")
@ -38,20 +39,30 @@ describe VagrantPlugins::Ansible::Config do
expect(subject.playbook).to be_nil
expect(subject.extra_vars).to be_nil
expect(subject.ask_sudo_pass).to be_nil
expect(subject.ask_sudo_pass).to be_false
expect(subject.limit).to be_nil
expect(subject.sudo).to be_nil
expect(subject.sudo).to be_false
expect(subject.sudo_user).to be_nil
expect(subject.verbose).to be_nil
expect(subject.tags).to be_nil
expect(subject.skip_tags).to be_nil
expect(subject.start_at_task).to be_nil
expect(subject.groups).to eq({})
expect(subject.host_key_checking).to eq('false')
expect(subject.host_key_checking).to be_false
expect(subject.raw_arguments).to be_nil
expect(subject.raw_ssh_args).to be_nil
end
describe "host_key_checking option" do
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :host_key_checking, false
end
describe "ask_sudo_pass option" do
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :ask_sudo_pass, false
end
describe "sudo option" do
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :sudo, false
end
describe "#validate" do
before do
subject.playbook = existing_file

View File

@ -259,7 +259,7 @@ VF
describe "with host_key_checking option enabled" do
before do
config.host_key_checking = "true"
config.host_key_checking = true
end
it_should_set_arguments_and_environment_variables 5, 3, true

View File

@ -0,0 +1,28 @@
shared_examples_for 'any VagrantConfigProvisioner strict boolean attribute' do |attr_name, attr_default_value|
[true, false].each do |bool|
it "returns the assigned boolean value (#{bool})" do
subject.send("#{attr_name}=", bool)
subject.finalize!
expect(subject.send(attr_name)).to eql(bool)
end
end
it "returns the default value (#{attr_default_value}) if undefined" do
subject.finalize!
expect(subject.send(attr_name)).to eql(attr_default_value)
end
[nil, 'true', 'false', 1, 0, 'this is not a boolean'].each do |nobool|
it "returns the default value when assigned value is invalid (#{nobool.class}: #{nobool})" do
subject.send("#{attr_name}=", nobool)
subject.finalize!
expect(subject.send(attr_name)).to eql(attr_default_value)
end
end
end