1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/integration/targets/expect/tasks/main.yml
Toshio Kuratomi 6a41a4f311 Expand the result from pwd to make the test more robust
Sometimes MacOSX's pwd doesn't return an expanded path.  Not sure why
but this test is still valid if we expand it via a playbook filter so
go ahead and do that.
2017-07-21 12:20:30 -07:00

100 lines
2.5 KiB
YAML

# test code for the ping module
# (c) 2014, James Cammarata <jcammarata@ansible.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: Install test requirements
pip:
name: pexpect
state: present
- name: record the test_command file
set_fact: test_command_file={{output_dir | expanduser}}/test_command.py
- name: copy script into output directory
copy: src=test_command.py dest={{test_command_file}} mode=0444
- name: record the output file
set_fact: output_file={{output_dir}}/foo.txt
- copy:
content: "foo"
dest: "{{output_file}}"
- name: test expect
expect:
command: "{{ansible_python_interpreter}} {{test_command_file}}"
responses:
foo: bar
register: expect_result
- name: assert expect worked
assert:
that:
- "expect_result.changed == true"
- "expect_result.stdout == 'foobar'"
- name: test creates option
expect:
command: "echo"
responses:
foo: bar
creates: "{{output_file}}"
register: creates_result
- name: assert when creates is provided command is not run
assert:
that:
- "creates_result.changed == false"
- name: test chdir
expect:
command: "pwd"
chdir: "{{output_dir}}"
responses:
foo: bar
register: chdir_result
- name: assert chdir works
assert:
that:
- "'{{chdir_result.stdout |expanduser | realpath }}' == '{{output_dir | expanduser | realpath}}'"
- name: test timeout option
expect:
command: "sleep 10"
responses:
foo: bar
timeout: 1
ignore_errors: true
register: timeout_result
- name: assert failure message when timeout
assert:
that:
- "timeout_result.msg == 'command exceeded timeout'"
- name: test echo option
expect:
command: "{{ansible_python_interpreter}} {{test_command_file}}"
responses:
foo: bar
echo: true
register: echo_result
- name: assert echo works
assert:
that:
- "'bar' in echo_result.stdout_lines"