From 4a1864765bd654ac27323564d1406e38a15abd86 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Fri, 14 Jul 2017 19:24:54 +0200 Subject: [PATCH] Windows: Path integration tests (#26490) These integration tests were used for testing the exact behaviour of Ansible for YAML-style syntax and key=value syntax. This includes fixes to win_shortcut (as `src` can be a URL too) --- lib/ansible/module_utils/powershell.ps1 | 2 +- .../integration/targets/windows-paths/aliases | 1 + .../targets/windows-paths/tasks/main.yml | 191 ++++++++++++++++++ 3 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/windows-paths/aliases create mode 100644 test/integration/targets/windows-paths/tasks/main.yml diff --git a/lib/ansible/module_utils/powershell.ps1 b/lib/ansible/module_utils/powershell.ps1 index 6bf0c27734f..49ee868f391 100644 --- a/lib/ansible/module_utils/powershell.ps1 +++ b/lib/ansible/module_utils/powershell.ps1 @@ -228,7 +228,7 @@ Function Get-AnsibleParam($obj, $name, $default = $null, $resultobj = @{}, $fail # Convert string type to real Powershell array $value = $value.Split(",").Trim() } else { - Fail-Json -obj $resultobj -message "Get-AnsibleParam: Parameter $name is not a YAML list." + Fail-Json -obj $resultobj -message "Get-AnsibleParam: Parameter '$name' is not a YAML list." } } } diff --git a/test/integration/targets/windows-paths/aliases b/test/integration/targets/windows-paths/aliases new file mode 100644 index 00000000000..10e03fc2bf7 --- /dev/null +++ b/test/integration/targets/windows-paths/aliases @@ -0,0 +1 @@ +windows/ci/group1 diff --git a/test/integration/targets/windows-paths/tasks/main.yml b/test/integration/targets/windows-paths/tasks/main.yml new file mode 100644 index 00000000000..075428980ca --- /dev/null +++ b/test/integration/targets/windows-paths/tasks/main.yml @@ -0,0 +1,191 @@ +- name: Set variables in YAML syntax + set_fact: + no_quotes_single: C:\Windows\Temp + single_quotes_single: 'C:\Windows\Temp' +# double_quotes_single: "C:\Windows\Temp" + no_quotes_double: C:\\Windows\\Temp + single_quotes_double: 'C:\\Windows\\Temp' + double_quotes_double: "C:\\Windows\\Temp" + no_quotes_slash: C:/Windows/Temp + no_quotes_trailing: C:\Windows\Temp\ + single_quotes_trailing: 'C:\Windows\Temp\' +# double_quotes_trailing: "C:\Windows\Temp\" + good: C:\Windows\Temp + works1: C:\\Windows\\Temp + works2: C:/Windows/Temp +# fail: "C:\Windows\Temp" + trailing: C:\Windows\Temp\ + register: yaml_syntax + +- assert: + that: + - no_quotes_single == good + - single_quotes_single == good +# - double_quotes_single == fail + - no_quotes_double == works1 + - single_quotes_double == works1 + - double_quotes_double == good + - no_quotes_slash == works2 + - no_quotes_trailing == trailing + - single_quotes_trailing == trailing +# - double_quotes_trailing == fail + - good != works1 + - good != works2 + - good != trailing + - works1 != works2 + - works1 != trailing + - works2 != trailing + +- name: Test good path {{ good }} + win_stat: + path: '{{ good }}' + register: good_result + +- assert: + that: + - good_result|success + - good_result.stat.attributes == 'Directory' + - good_result.stat.exists == true + - good_result.stat.path == good + +- name: Test works1 path {{ works1 }} + win_stat: + path: '{{ works1 }}' + register: works1_result + +- assert: + that: + - works1_result|success + - works1_result.stat.attributes == 'Directory' + - works1_result.stat.exists == true + - works1_result.stat.path == good + +- name: Test works2 path {{ works2 }} + win_stat: + path: '{{ works2 }}' + register: works2_result + +- assert: + that: + - works2_result|success + - works2_result.stat.attributes == 'Directory' + - works2_result.stat.exists == true + - works2_result.stat.path == good + +- name: Test trailing path {{ trailing }} + win_stat: + path: '{{ trailing }}' + register: trailing_result + +- assert: + that: + - trailing_result|success + - trailing_result.stat.attributes == 'Directory' + - trailing_result.stat.exists == true + - trailing_result.stat.path == trailing + +- name: Set variables in key=value syntax + set_fact: + no_quotes_single=C:\Windows\Temp + single_quotes_single='C:\Windows\Temp' + double_quotes_single="C:\Windows\Temp" + no_quotes_single_tab=C:\Windows\temp + single_quotes_single_tab='C:\Windows\temp' + double_quotes_single_tab="C:\Windows\temp" + no_quotes_double=C:\\Windows\\Temp + single_quotes_double='C:\\Windows\\Temp' + double_quotes_double="C:\\Windows\\Temp" + no_quotes_slash=C:/Windows/Temp + no_quotes_trailing=C:\Windows\Temp\ + good=C:\Windows\Temp + works1=C:\\Windows\\Temp + works2=C:/Windows/Temp + fail="C:\Windows\Temp" + trailing=C:\Windows\Temp\ + tab=C:\Windows\x09emp + eof=foobar +# single_quotes_trailing='C:\Windows\Temp\' +# double_quotes_trailing="C:\Windows\Temp\" + register: legacy_syntax + +- assert: + that: + - no_quotes_single == good + - single_quotes_single == good + - double_quotes_single == good + - no_quotes_double == works1 + - single_quotes_double == works1 + - double_quotes_double == works1 + - no_quotes_slash == works2 + - no_quotes_single_tab == tab + - single_quotes_single_tab == tab + - double_quotes_single_tab == tab + - no_quotes_trailing == trailing + - good == works1 + - good != works2 + - good != tab + - good != trailing + - works1 != works2 + - works1 != tab + - works1 != trailing + - works2 != tab + - works2 != trailing + - tab != trailing + +- name: Test good path {{ good }} + win_stat: + path: '{{ good }}' + register: good_result + +- assert: + that: + - good_result|success + - good_result.stat.attributes == 'Directory' + - good_result.stat.exists == true + - good_result.stat.path == good + +- name: Test works1 path {{ works1 }} + win_stat: + path: '{{ works1 }}' + register: works1_result + +- assert: + that: + - works1_result|success + - works1_result.stat.attributes == 'Directory' + - works1_result.stat.exists == true + - works1_result.stat.path == good + +- name: Test works2 path {{ works2 }} + win_stat: + path: '{{ works2 }}' + register: works2_result + +- assert: + that: + - works2_result|success + - works2_result.stat.attributes == 'Directory' + - works2_result.stat.exists == true + - works2_result.stat.path == good + +- name: Test trailing path {{ trailing }} + win_stat: + path: '{{ trailing }}' + register: trailing_result + +- assert: + that: + - trailing_result|success + - trailing_result.stat.attributes == 'Directory' + - trailing_result.stat.exists == true + - trailing_result.stat.path == trailing + +- name: Test tab path {{ tab }} + win_stat: + path: '{{ tab }}' + register: tab_result + ignore_errors: yes + +- assert: + that: + - tab_result|failed