From a66d5dcc4331f12f08a3dffd2f39a5c91e75929e Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Mon, 27 Feb 2017 12:36:52 +0100 Subject: [PATCH] win_chocolatey: Add integration tests (#21930) And also fix a known issue. --- .../modules/windows/win_chocolatey.ps1 | 4 +- .../targets/win_chocolatey/aliases | 1 + .../targets/win_chocolatey/tasks/main.yml | 61 +++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 test/integration/targets/win_chocolatey/aliases create mode 100644 test/integration/targets/win_chocolatey/tasks/main.yml diff --git a/lib/ansible/modules/windows/win_chocolatey.ps1 b/lib/ansible/modules/windows/win_chocolatey.ps1 index 9d5da360d1..318c16e453 100644 --- a/lib/ansible/modules/windows/win_chocolatey.ps1 +++ b/lib/ansible/modules/windows/win_chocolatey.ps1 @@ -110,7 +110,7 @@ Function Choco-IsInstalled Throw "Error checking installation status for $package" } - If ("$results" -match "$package .* (\d+) packages installed.") + If ("$output" -match "(\d+) packages installed.") { return $matches[1] -gt 0 } @@ -200,7 +200,7 @@ Function Choco-Upgrade Throw "Error installing $package" } - if ("$results" -match ' upgraded (\d+)/\d+ package\(s\)\. ') + if ("$output" -match ' upgraded (\d+)/\d+ package\(s\)\. ') { if ($matches[1] -gt 0) { diff --git a/test/integration/targets/win_chocolatey/aliases b/test/integration/targets/win_chocolatey/aliases new file mode 100644 index 0000000000..ee0ed5974e --- /dev/null +++ b/test/integration/targets/win_chocolatey/aliases @@ -0,0 +1 @@ +windows/ci/group2 diff --git a/test/integration/targets/win_chocolatey/tasks/main.yml b/test/integration/targets/win_chocolatey/tasks/main.yml new file mode 100644 index 0000000000..6e461b4abc --- /dev/null +++ b/test/integration/targets/win_chocolatey/tasks/main.yml @@ -0,0 +1,61 @@ +# test code for the win_chocolatey module +# (c) 2017, Dag Wieers + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +- name: install sysinternals + win_chocolatey: + name: sysinternals + state: present + register: install_sysinternals + +- name: verify install sysinternals + assert: + that: + - 'install_sysinternals.changed == true' + +- name: install sysinternals again + win_chocolatey: + name: sysinternals + state: present + register: install_sysinternals_again + +- name: verify install sysinternals again + assert: + that: + - 'install_sysinternals_again.changed == false' + +- name: remove sysinternals + win_chocolatey: + name: sysinternals + state: absent + register: remove_sysinternals + +- name: verify remove sysinternals + assert: + that: + - 'remove_sysinternals.changed == true' + +- name: remove sysinternals again + win_chocolatey: + name: sysinternals + state: absent + register: remove_sysinternals_again + +- name: verify remove sysinternals again + assert: + that: + - 'remove_sysinternals_again.changed == false'