diff options
author | Matt Clay <matt@mystile.com> | 2016-10-13 10:03:19 -0700 |
---|---|---|
committer | John R Barker <john@johnrbarker.com> | 2016-10-13 18:03:19 +0100 |
commit | c2ec86cb78f3c43bc5f2484d1888571e27225702 (patch) | |
tree | 43602995d1b5b009de1e1d4a7bc1a835f60204b7 /test/integration/targets/win_command | |
parent | 9182619fef4151d04d28b30b8a6f33e469560f5f (diff) | |
download | ansible-c2ec86cb78f3c43bc5f2484d1888571e27225702.tar.gz |
Migrate Windows CI roles to test targets. (#18005)
Diffstat (limited to 'test/integration/targets/win_command')
-rw-r--r-- | test/integration/targets/win_command/tasks/main.yml | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/test/integration/targets/win_command/tasks/main.yml b/test/integration/targets/win_command/tasks/main.yml new file mode 100644 index 0000000000..98f39b3c27 --- /dev/null +++ b/test/integration/targets/win_command/tasks/main.yml @@ -0,0 +1,134 @@ +- name: execute a command + win_command: whoami /groups + register: cmdout + +- name: validate result + assert: + that: + - cmdout|success + - cmdout|changed + - cmdout.cmd == 'whoami /groups' + - cmdout.delta is match('^\d:(\d){2}:(\d){2}.(\d){6}$') + - cmdout.end is match('^(\d){4}\-(\d){2}\-(\d){2} (\d){2}:(\d){2}:(\d){2}.(\d){6}$') + - cmdout.rc == 0 + - cmdout.start is match('^(\d){4}\-(\d){2}\-(\d){2} (\d){2}:(\d){2}:(\d){2}.(\d){6}$') + - cmdout.stderr == "" + - cmdout.stdout is search('GROUP INFORMATION') + - '"GROUP INFORMATION" in cmdout.stdout_lines' + - cmdout.warnings == [] + +- name: execute something nonexistent + win_command: bogus_command1234 + register: cmdout + ignore_errors: true + +- name: validate result + assert: + that: + - cmdout|failed + - not cmdout|changed + - cmdout.cmd == 'bogus_command1234' + - cmdout.rc == 2 + - cmdout.msg is search('cannot find the file specified') + +- name: execute something with error output + win_command: cmd /c "echo some output & echo some error 1>&2" + register: cmdout + +- name: validate result + assert: + that: + - cmdout|success + - cmdout|changed + - cmdout.cmd == 'cmd /c "echo some output & echo some error 1>&2"' + - cmdout.delta is match('^\d:(\d){2}:(\d){2}.(\d){6}$') + - cmdout.end is match('^(\d){4}\-(\d){2}\-(\d){2} (\d){2}:(\d){2}:(\d){2}.(\d){6}$') + - cmdout.rc == 0 + - cmdout.start is match('^(\d){4}\-(\d){2}\-(\d){2} (\d){2}:(\d){2}:(\d){2}.(\d){6}$') + - cmdout.stderr is search('some error') + - cmdout.stdout == "some output \r\n" + - cmdout.stdout_lines == ["some output "] + - cmdout.warnings == [] + +- name: ensure test file is absent + win_file: + path: c:\testfile.txt + state: absent + +- name: run with creates, should create + win_command: cmd /c "echo $null >> c:\testfile.txt" + args: + creates: c:\testfile.txt + register: cmdout + +- name: validate result + assert: + that: + - cmdout|success + - cmdout|changed + +- name: run again with creates, should skip + win_command: cmd /c "echo $null >> c:\testfile.txt" + args: + creates: c:\testfile.txt + register: cmdout + +- name: validate result + assert: + that: + - cmdout|skipped + - cmdout.msg is search('exists') + +- name: ensure testfile is still present + win_stat: + path: c:\testfile.txt + register: statout + +- name: validate result + assert: + that: + - statout.stat.exists == true + +- name: run with removes, should remove + win_command: cmd /c "del c:\testfile.txt" + args: + removes: c:\testfile.txt + register: cmdout + +- name: validate result + assert: + that: + - cmdout|success + - cmdout|changed + +- name: run again with removes, should skip + win_command: cmd /c "del c:\testfile.txt" + args: + removes: c:\testfile.txt + register: cmdout + +- name: validate result + assert: + that: + - cmdout|skipped + - cmdout.msg is search('does not exist') + +- name: run something with known nonzero exit code + win_command: cmd /c "exit 254" + register: cmdout + ignore_errors: true + +- name: validate result + assert: + that: + - cmdout|failed + - cmdout.rc == 254 + +- name: write large buffer to stdout + win_command: powershell /c "$ba = New-Object byte[] 16384; (New-Object System.Random 32).NextBytes($ba); [Convert]::ToBase64String($ba) | Write-Output" + register: cmdout + +# TODO: fix small buffer deadlock on large write to stderr before stdout has been consumed +#- name: write large buffer to stderr +# win_shell: $ba = New-Object byte[] 16384; (New-Object System.Random 32).NextBytes($ba); [Convert]::ToBase64String($ba) | Write-Error; Write-Output test +# register: cmdout
\ No newline at end of file |