ansible/test/integration/targets/win_path/tasks/main.yml
Matt Martz 4fe08441be Deprecate tests used as filters (#32361)
* Warn on tests used as filters

* Update docs, add aliases for tests that fit more gramatically with test syntax

* Fix rst formatting

* Add successful filter, alias of success

* Remove renamed_deprecation, it was overkill

* Make directory alias for is_dir

* Update tests to use proper jinja test syntax

* Update additional documentation, living outside of YAML files, to reflect proper jinja test syntax

* Add conversion script, porting guide updates, and changelog updates

* Update newly added uses of tests as filters

* No underscore variable

* Convert recent tests as filter changes to win_stat

* Fix some changes related to rebasing a few integration tests

* Make tests_as_filters_warning explicitly accept the name of the test, instead of inferring the name

* Add test for tests_as_filters_warning

* Update tests as filters in newly added/modified tests

* Address recent changes to several integration tests

* Address recent changes in cs_vpc
2017-11-27 17:58:08 -05:00

183 lines
5.5 KiB
YAML

- set_fact:
varname: WINPATH_TEST
- name: Remove {{ varname }} vars from user and machine scope
raw: '[Environment]::SetEnvironmentVariable("{{ varname }}", $null, "User"); [Environment]::SetEnvironmentVariable("{{ varname }}", $null, "Machine")'
- name: Set a var at the machine and user levels
win_path:
name: "{{ varname }}"
elements: C:\{{ item }}Path
scope: "{{ item }}"
with_items:
- machine
- user
register: pathout
- name: Get path value from machine and user levels
raw: '[Environment]::GetEnvironmentVariable("{{ varname }}","{{ item.item }}")'
with_items: "{{ pathout.results }}"
register: varout
- name: Ensure output
assert:
that:
- item.0 is changed
- item.0.path_value == "C:\\" + item.0.item + "Path"
- item.1.stdout_lines[0] == 'C:\\' + item.0.item + 'Path'
with_together:
- "{{ pathout.results }}"
- "{{ varout.results }}"
- name: Remove {{ varname }} vars from user and machine scope
raw: '[Environment]::SetEnvironmentVariable("{{ varname }}", $null, "User"); [Environment]::SetEnvironmentVariable("{{ varname }}", $null, "Machine")'
- name: Create multi-element path
win_path:
name: "{{ varname }}"
elements:
- C:\PathZ
- C:\PathA
register: multiout
- name: Get path value
raw: $env:{{ varname }}
register: varout
- name: Ensure output
assert:
that:
- multiout is changed
- multiout.path_value == "C:\\PathZ;C:\\PathA"
- varout.stdout_lines[0] == "C:\\PathZ;C:\\PathA"
- name: Add value to middle and end
win_path:
name: "{{ varname }}"
elements:
- C:\NewPath
- C:\PathA
- 'C:\PathWithTrailingBackslash\' # store with a trailing backslash
- '"C:\Quoted;With;Semicolons"' # embedded semicolon, wrapped in quotes
- '%SystemRoot%\stuff'
register: addout
- name: Get path value
raw: $env:{{ varname }}
register: varout
- name: Test idempotence- retry values to middle and end, test case-insensitive comparison, backslash canonicalization
win_path:
name: "{{ varname }}"
elements:
- c:\nEwPaTh
- c:\patha
- C:\pathwithtrailingbackslash # no trailing backslash, should be the same
- '"C:\Quoted;With;Semicolons"'
- '%SystemRoot%\stuff'
register: idemout
- name: Get path value
raw: $env:{{ varname }}
register: idemvarout
- name: Ensure output
assert:
that:
- addout is changed
- addout.path_value == 'C:\\PathZ;C:\\NewPath;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";%SystemRoot%\stuff'
- varout.stdout_lines[0] == ('C:\\PathZ;C:\\NewPath;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";C:\Windows\stuff')
- idemout is not changed
- idemout.path_value == 'C:\\PathZ;C:\\NewPath;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";%SystemRoot%\stuff'
- idemvarout.stdout_lines[0] == ('C:\\PathZ;C:\\NewPath;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";C:\Windows\stuff')
- name: Remove single element
win_path:
name: "{{ varname }}"
elements: C:\NewPath
state: absent
register: removeout
- name: Get path value
raw: $env:{{ varname }}
register: varout
- name: Test idempotence- retry remove single element
win_path:
name: "{{ varname }}"
elements: C:\NewPath
state: absent
register: idemremoveout
- name: Get path value
raw: $env:{{ varname }}
register: idemvarout
- name: Ensure output
assert:
that:
- removeout is changed
- removeout.path_value == 'C:\\PathZ;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";%SystemRoot%\stuff'
- varout.stdout_lines[0] == 'C:\\PathZ;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";C:\Windows\stuff'
- idemremoveout is not changed
- idemremoveout.path_value == 'C:\\PathZ;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";%SystemRoot%\stuff'
- idemvarout.stdout_lines[0] == 'C:\\PathZ;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";C:\Windows\stuff'
- name: Remove multiple elements
win_path:
name: "{{ varname }}"
elements:
- C:\PathWithTrailingBackslash # no trailing backslash
- c:\pathz
- '"C:\Quoted;With;Semicolons"'
- '%SystemRoot%\stuff\' # add trailing backslash
state: absent
register: removeout
- name: Get path value
raw: $env:{{ varname }}
register: varout
- name: Ensure output
assert:
that:
- removeout is changed
- removeout.path_value == "C:\\PathA"
- varout.stdout_lines[0] == "C:\\PathA"
- name: Test check mode add
check_mode: yes
win_path:
name: "{{ varname }}"
elements:
- C:\MissingPath
register: checkadd
- name: Get path value
raw: $env:{{ varname }}
register: checkaddvarout
- name: Test check mode remove
check_mode: yes
win_path:
name: "{{ varname }}"
elements: C:\PathA
state: absent
register: checkremove
- name: Get path value
raw: $env:{{ varname }}
register: checkremovevarout
- name: Ensure output
assert:
that:
- checkadd is changed
- checkadd.path_value == "C:\\PathA;C:\\MissingPath"
- checkaddvarout.stdout_lines[0] == "C:\\PathA" # shouldn't have actually changed the value
- checkremove is changed
- checkremove.path_value == ""
- checkremovevarout.stdout_lines[0] == "C:\\PathA" # shouldn't have actually changed the value
- name: Remove {{ varname }} vars from user and machine scope
raw: '[Environment]::SetEnvironmentVariable("{{ varname }}", $null, "User"); [Environment]::SetEnvironmentVariable("{{ varname }}", $null, "Machine")'