From 4bf79de8a65b5bb8bddeff3d328adbd49a8dd19b Mon Sep 17 00:00:00 2001 From: PRASOON KARUNAN V <12897753+kvprasoon@users.noreply.github.com> Date: Tue, 12 Nov 2019 11:43:52 +0530 Subject: [PATCH] Add output options for win_pester (#63583) * add output options for win_pester * fix typo * correct variable name --- lib/ansible/modules/windows/win_pester.ps1 | 7 +++++++ lib/ansible/modules/windows/win_pester.py | 18 ++++++++++++++++++ .../targets/win_pester/defaults/main.yml | 1 + .../targets/win_pester/tasks/test.yml | 15 +++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/lib/ansible/modules/windows/win_pester.ps1 b/lib/ansible/modules/windows/win_pester.ps1 index 5515d0ccb9..d2dd274598 100644 --- a/lib/ansible/modules/windows/win_pester.ps1 +++ b/lib/ansible/modules/windows/win_pester.ps1 @@ -15,6 +15,8 @@ $diff_mode = Get-AnsibleParam -obj $params -name "_ansible_diff" -type "bool" -d $path = Get-AnsibleParam -obj $params -name "path" -type "str" -failifempty $true $tags = Get-AnsibleParam -obj $params -name "tags" -type "list" +$output_file = Get-AnsibleParam -obj $params -name "output_file" -type "str" +$output_format = Get-AnsibleParam -obj $params -name "output_format" -type "str" -default "NunitXML" $test_parameters = Get-AnsibleParam -obj $params -name "test_parameters" -type "dict" $minimum_version = Get-AnsibleParam -obj $params -name "minimum_version" -type "str" -failifempty $false @@ -77,6 +79,11 @@ If ($result.pester_version -ge "4.0.0") { if($tags.count){ $Parameters.Tag = $tags } + +if($output_file){ + $Parameters.OutputFile = $output_file + $Parameters.OutputFormat = $output_format +} # Run Pester tests If (Test-Path -LiteralPath $path -PathType Leaf) { $test_parameters_check_mode_msg = '' diff --git a/lib/ansible/modules/windows/win_pester.py b/lib/ansible/modules/windows/win_pester.py index 567c847509..bfbc3d0d6f 100644 --- a/lib/ansible/modules/windows/win_pester.py +++ b/lib/ansible/modules/windows/win_pester.py @@ -32,6 +32,18 @@ options: - Accepts multiple comma separated tags. type: list version_added: '2.9' + output_file: + description: + - Generates an output test report. + type: str + version_added: '2.10' + output_format: + description: + - Format of the test report to be generated. + - This parameter is to be used with output_file option. + type: str + default: NunitXML + version_added: '2.10' test_parameters: description: - Allows to specify parameters to the test script. @@ -42,6 +54,7 @@ options: - Minimum version of the pester module that has to be available on the remote host. author: - Erwan Quelin (@equelin) + - Prasoon Karunan V (@prasoonkarunan) ''' EXAMPLES = r''' @@ -76,6 +89,11 @@ EXAMPLES = r''' test_parameters: Process: lsass Service: bits + +- name: Run the pester test present in a folder and generate NunitXML test result.. + win_pester: + path: C:\Pester\test04.test.ps1 + output_file: c:\Pester\resullt\testresult.xml ''' RETURN = r''' diff --git a/test/integration/targets/win_pester/defaults/main.yml b/test/integration/targets/win_pester/defaults/main.yml index 01f2c282bb..3507a0fda9 100644 --- a/test/integration/targets/win_pester/defaults/main.yml +++ b/test/integration/targets/win_pester/defaults/main.yml @@ -1,2 +1,3 @@ --- test_win_pester_path: C:\ansible\win_pester +test_report_file: c:\ansible\win_pester\test_report.xml diff --git a/test/integration/targets/win_pester/tasks/test.yml b/test/integration/targets/win_pester/tasks/test.yml index 26addb13d1..2baf383438 100644 --- a/test/integration/targets/win_pester/tasks/test.yml +++ b/test/integration/targets/win_pester/tasks/test.yml @@ -117,3 +117,18 @@ - test_with_parameter.changed - test_with_parameter.output.PassedCount == 2 - test_with_parameter.output.TotalCount == 2 + +- name: Run Pester test(s) specifying a test file by generating test result xml + win_pester: + path: '{{test_win_pester_path}}\test03.test.ps1' + output_file: '{{test_report_file}}' + +- name: Checks if the output result file exists + win_stat: + path: '{{test_report_file}}' + register: test_output_file + +- name: Checks if the output result file exists + assert: + that: + - test_output_file.stat.exists