Unit test + vault password file existence check

This commit is contained in:
Emilien Kenler 2014-04-14 12:24:57 +09:00 committed by Mitchell Hashimoto
parent dd06dffe85
commit b77bd3e6bb
3 changed files with 29 additions and 1 deletions

View File

@ -47,7 +47,7 @@ module VagrantPlugins
@extra_vars = nil if @extra_vars == UNSET_VALUE
@inventory_path = nil if @inventory_path == UNSET_VALUE
@ask_sudo_pass = false unless @ask_sudo_pass == true
@ask_vault_pass = false unless @ask_sudo_pass == true
@ask_vault_pass = false unless @ask_vault_pass == true
@vault_password_file = nil if @vault_password_file == UNSET_VALUE
@limit = nil if @limit == UNSET_VALUE
@sudo = false unless @sudo == true
@ -112,6 +112,15 @@ module VagrantPlugins
end
end
# Validate the existence of the vault_password_file, if specified
if vault_password_file
expanded_path = Pathname.new(vault_password_file).expand_path(machine.env.root_path)
if !expanded_path.exist?
errors << I18n.t("vagrant.provisioners.ansible.vault_password_file_invalid",
:path => expanded_path)
end
end
{ "ansible provisioner" => errors }
end
end

View File

@ -1700,6 +1700,7 @@ en:
no_playbook: "`playbook` must be set for the Ansible provisioner."
playbook_path_invalid: "`playbook` for the Ansible provisioner does not exist on the host system: %{path}"
inventory_path_invalid: "`inventory_path` for the Ansible provisioner does not exist on the host system: %{path}"
vault_password_file_invalid: "`vault_password_file` for the Ansible provisioner does not exist on the host system: %{path}"
extra_vars_invalid: "`extra_vars` for the Ansible provisioner must be a hash or a path to an existing file. Received: %{value} (as %{type})"
docker:

View File

@ -16,6 +16,7 @@ describe VagrantPlugins::Ansible::Config do
config_options = subject.public_methods(false).find_all { |i| i.to_s.end_with?('=') }
config_options.map! { |i| i.to_s.sub('=', '') }
supported_options = %w( ask_sudo_pass
ask_vault_pass
extra_vars
groups
host_key_checking
@ -29,6 +30,7 @@ describe VagrantPlugins::Ansible::Config do
sudo
sudo_user
tags
vault_password_file
verbose )
expect(config_options.sort).to eql(supported_options)
@ -40,6 +42,8 @@ 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_false
expect(subject.ask_vault_pass).to be_false
expect(subject.vault_password_file).to be_nil
expect(subject.limit).to be_nil
expect(subject.sudo).to be_false
expect(subject.sudo_user).to be_nil
@ -59,6 +63,9 @@ describe VagrantPlugins::Ansible::Config do
describe "ask_sudo_pass option" do
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :ask_sudo_pass, false
end
describe "ask_vault_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
@ -155,6 +162,17 @@ describe VagrantPlugins::Ansible::Config do
])
end
it "returns an error if vault_password_file is specified, but does not exist" do
subject.vault_password_file = non_existing_file
subject.finalize!
result = subject.validate(machine)
expect(result["ansible provisioner"]).to eql([
I18n.t("vagrant.provisioners.ansible.vault_password_file_invalid",
:path => non_existing_file)
])
end
it "it collects and returns all detected errors" do
subject.playbook = non_existing_file
subject.inventory_path = non_existing_file