mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Migrate Windows CI roles to test targets. (#18005)
This commit is contained in:
parent
9182619fef
commit
c2ec86cb78
81 changed files with 26 additions and 26 deletions
5
test/integration/targets/win_script/defaults/main.yml
Normal file
5
test/integration/targets/win_script/defaults/main.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
|
||||
# Parameters to pass to test scripts.
|
||||
test_win_script_value: VaLuE
|
||||
test_win_script_splat: "@{This='THIS'; That='THAT'; Other='OTHER'}"
|
|
@ -0,0 +1,2 @@
|
|||
@ECHO OFF
|
||||
ECHO We can even run a batch file!
|
|
@ -0,0 +1,2 @@
|
|||
@ECHO OFF
|
||||
ECHO We can even run a batch file with cmd extension!
|
|
@ -0,0 +1,2 @@
|
|||
# Test script to make sure the Ansible script module works.
|
||||
Write-Host "Woohoo! We can run a PowerShell script via Ansible!"
|
|
@ -0,0 +1,6 @@
|
|||
Param(
|
||||
[bool]$boolvariable
|
||||
)
|
||||
|
||||
Write-Host $boolvariable.GetType()
|
||||
Write-Host $boolvariable
|
|
@ -0,0 +1,3 @@
|
|||
# Test script to create a file.
|
||||
|
||||
echo $null > $args[0]
|
|
@ -0,0 +1,3 @@
|
|||
# Test script to remove a file.
|
||||
|
||||
Remove-Item $args[0] -Force
|
|
@ -0,0 +1,7 @@
|
|||
# Test script to make sure the Ansible script module works when arguments are
|
||||
# passed to the script.
|
||||
|
||||
foreach ($i in $args)
|
||||
{
|
||||
Write-Host $i;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
# Test script to make sure we handle non-zero exit codes.
|
||||
|
||||
trap
|
||||
{
|
||||
Write-Error -ErrorRecord $_
|
||||
exit 1;
|
||||
}
|
||||
|
||||
throw "Oh noes I has an error"
|
|
@ -0,0 +1,6 @@
|
|||
# Test script to make sure the Ansible script module works when arguments are
|
||||
# passed via splatting (http://technet.microsoft.com/en-us/magazine/gg675931.aspx)
|
||||
|
||||
Write-Host $args.This
|
||||
Write-Host $args.That
|
||||
Write-Host $args.Other
|
191
test/integration/targets/win_script/tasks/main.yml
Normal file
191
test/integration/targets/win_script/tasks/main.yml
Normal file
|
@ -0,0 +1,191 @@
|
|||
# test code for the script module when using winrm connection
|
||||
# (c) 2014, Chris Church <chris@ninemoreminutes.com>
|
||||
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
- name: get tempdir path
|
||||
raw: $env:TEMP
|
||||
register: tempdir
|
||||
|
||||
- name: set script path dynamically
|
||||
set_fact:
|
||||
test_win_script_filename: "{{ tempdir.stdout_lines[0] }}/testing_win_script.txt"
|
||||
|
||||
- name: run simple test script
|
||||
script: test_script.ps1
|
||||
register: test_script_result
|
||||
|
||||
- name: check that script ran
|
||||
assert:
|
||||
that:
|
||||
- "test_script_result.rc == 0"
|
||||
- "test_script_result.stdout"
|
||||
- "'Woohoo' in test_script_result.stdout"
|
||||
- "not test_script_result.stderr"
|
||||
- "not test_script_result|failed"
|
||||
- "test_script_result|changed"
|
||||
|
||||
- name: run test script that takes arguments including a unicode char
|
||||
script: test_script_with_args.ps1 /this /that /Ӧther
|
||||
register: test_script_with_args_result
|
||||
|
||||
- name: check that script ran and received arguments and returned unicode
|
||||
assert:
|
||||
that:
|
||||
- "test_script_with_args_result.rc == 0"
|
||||
- "test_script_with_args_result.stdout"
|
||||
- "test_script_with_args_result.stdout_lines[0] == '/this'"
|
||||
- "test_script_with_args_result.stdout_lines[1] == '/that'"
|
||||
- "test_script_with_args_result.stdout_lines[2] == '/Ӧther'"
|
||||
- "not test_script_with_args_result.stderr"
|
||||
- "not test_script_with_args_result|failed"
|
||||
- "test_script_with_args_result|changed"
|
||||
|
||||
- name: run test script that takes parameters passed via splatting
|
||||
script: test_script_with_splatting.ps1 @{ This = 'this'; That = '{{ test_win_script_value }}'; Other = 'other'}
|
||||
register: test_script_with_splatting_result
|
||||
|
||||
- name: check that script ran and received parameters via splatting
|
||||
assert:
|
||||
that:
|
||||
- "test_script_with_splatting_result.rc == 0"
|
||||
- "test_script_with_splatting_result.stdout"
|
||||
- "test_script_with_splatting_result.stdout_lines[0] == 'this'"
|
||||
- "test_script_with_splatting_result.stdout_lines[1] == test_win_script_value"
|
||||
- "test_script_with_splatting_result.stdout_lines[2] == 'other'"
|
||||
- "not test_script_with_splatting_result.stderr"
|
||||
- "not test_script_with_splatting_result|failed"
|
||||
- "test_script_with_splatting_result|changed"
|
||||
|
||||
- name: run test script that takes splatted parameters from a variable
|
||||
script: test_script_with_splatting.ps1 {{ test_win_script_splat }}
|
||||
register: test_script_with_splatting2_result
|
||||
|
||||
- name: check that script ran and received parameters via splatting from a variable
|
||||
assert:
|
||||
that:
|
||||
- "test_script_with_splatting2_result.rc == 0"
|
||||
- "test_script_with_splatting2_result.stdout"
|
||||
- "test_script_with_splatting2_result.stdout_lines[0] == 'THIS'"
|
||||
- "test_script_with_splatting2_result.stdout_lines[1] == 'THAT'"
|
||||
- "test_script_with_splatting2_result.stdout_lines[2] == 'OTHER'"
|
||||
- "not test_script_with_splatting2_result.stderr"
|
||||
- "not test_script_with_splatting2_result|failed"
|
||||
- "test_script_with_splatting2_result|changed"
|
||||
|
||||
- name: run test script that has errors
|
||||
script: test_script_with_errors.ps1
|
||||
register: test_script_with_errors_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: check that script ran but failed with errors
|
||||
assert:
|
||||
that:
|
||||
- "test_script_with_errors_result.rc != 0"
|
||||
- "not test_script_with_errors_result.stdout"
|
||||
- "test_script_with_errors_result.stderr"
|
||||
- "test_script_with_errors_result|failed"
|
||||
- "test_script_with_errors_result|changed"
|
||||
|
||||
- name: cleanup test file if it exists
|
||||
raw: Remove-Item "{{test_win_script_filename}}" -Force
|
||||
ignore_errors: true
|
||||
|
||||
- name: run test script that creates a file
|
||||
script: test_script_creates_file.ps1 "{{test_win_script_filename}}" creates="{{test_win_script_filename}}"
|
||||
register: test_script_creates_file_result
|
||||
|
||||
- name: check that script ran and indicated a change
|
||||
assert:
|
||||
that:
|
||||
- "test_script_creates_file_result.rc == 0"
|
||||
- "not test_script_creates_file_result.stdout"
|
||||
- "not test_script_creates_file_result.stderr"
|
||||
- "not test_script_creates_file_result|failed"
|
||||
- "test_script_creates_file_result|changed"
|
||||
|
||||
- name: run test script that creates a file again
|
||||
script: test_script_creates_file.ps1 "{{test_win_script_filename}}" creates="{{test_win_script_filename}}"
|
||||
register: test_script_creates_file_again_result
|
||||
|
||||
- name: check that the script did not run since the remote file exists
|
||||
assert:
|
||||
that:
|
||||
- "not test_script_creates_file_again_result|failed"
|
||||
- "not test_script_creates_file_again_result|changed"
|
||||
- "test_script_creates_file_again_result|skipped"
|
||||
|
||||
- name: run test script that removes a file
|
||||
script: test_script_removes_file.ps1 "{{test_win_script_filename}}" removes="{{test_win_script_filename}}"
|
||||
register: test_script_removes_file_result
|
||||
|
||||
- name: check that the script ran since the remote file exists
|
||||
assert:
|
||||
that:
|
||||
- "test_script_removes_file_result.rc == 0"
|
||||
- "not test_script_removes_file_result.stdout"
|
||||
- "not test_script_removes_file_result.stderr"
|
||||
- "not test_script_removes_file_result|failed"
|
||||
- "test_script_removes_file_result|changed"
|
||||
|
||||
- name: run test script that removes a file again
|
||||
script: test_script_removes_file.ps1 "{{test_win_script_filename}}" removes="{{test_win_script_filename}}"
|
||||
register: test_script_removes_file_again_result
|
||||
|
||||
- name: check that the script did not run since the remote file does not exist
|
||||
assert:
|
||||
that:
|
||||
- "not test_script_removes_file_again_result|failed"
|
||||
- "not test_script_removes_file_again_result|changed"
|
||||
- "test_script_removes_file_again_result|skipped"
|
||||
|
||||
- name: run simple batch file
|
||||
script: test_script.bat
|
||||
register: test_batch_result
|
||||
|
||||
- name: check that batch file ran
|
||||
assert:
|
||||
that:
|
||||
- "test_batch_result.rc == 0"
|
||||
- "test_batch_result.stdout"
|
||||
- "'batch' in test_batch_result.stdout"
|
||||
- "not test_batch_result.stderr"
|
||||
- "not test_batch_result|failed"
|
||||
- "test_batch_result|changed"
|
||||
|
||||
- name: run simple batch file with .cmd extension
|
||||
script: test_script.cmd
|
||||
register: test_cmd_result
|
||||
|
||||
- name: check that batch file with .cmd extension ran
|
||||
assert:
|
||||
that:
|
||||
- "test_cmd_result.rc == 0"
|
||||
- "test_cmd_result.stdout"
|
||||
- "'cmd extension' in test_cmd_result.stdout"
|
||||
- "not test_cmd_result.stderr"
|
||||
- "not test_cmd_result|failed"
|
||||
- "test_cmd_result|changed"
|
||||
|
||||
- name: run test script that takes a boolean parameter
|
||||
script: test_script_bool.ps1 $true
|
||||
register: test_script_bool_result
|
||||
|
||||
- name: check that the script ran and the parameter was treated as a boolean
|
||||
assert:
|
||||
that:
|
||||
- "test_script_bool_result.stdout_lines[0] == 'System.Boolean'"
|
||||
- "test_script_bool_result.stdout_lines[1] == 'True'"
|
Loading…
Add table
Add a link
Reference in a new issue