mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Add the start of an integration test structure using Ansible playbooks, also added an assert action plugin to make writing those easier.
This commit is contained in:
13
tests_new/integration/README.md
Normal file
13
tests_new/integration/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
Integration tests
|
||||
=================
|
||||
|
||||
The ansible integration system.
|
||||
|
||||
Tests for playbooks, by playbooks.
|
||||
|
||||
Some tests may require cloud credentials.
|
||||
|
||||
Instructions
|
||||
============
|
||||
|
||||
Pending
|
||||
6
tests_new/integration/all.yml
Normal file
6
tests_new/integration/all.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
- include: test_setup.yml
|
||||
- include: non_destructive.yml
|
||||
- include: destructive.yml
|
||||
- include: rackspace.yml
|
||||
- include: amazon.yml
|
||||
|
||||
4
tests_new/integration/amazon.yml
Normal file
4
tests_new/integration/amazon.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- hosts: testhost
|
||||
gather_facts: True
|
||||
roles: []
|
||||
|
||||
4
tests_new/integration/destructive.yml
Normal file
4
tests_new/integration/destructive.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- hosts: testhost
|
||||
gather_facts: True
|
||||
roles: []
|
||||
|
||||
2
tests_new/integration/inventory
Normal file
2
tests_new/integration/inventory
Normal file
@@ -0,0 +1,2 @@
|
||||
[local]
|
||||
testhost ansible_ssh_host=127.0.0.1 ansible_connection=local
|
||||
5
tests_new/integration/non_destructive.yml
Normal file
5
tests_new/integration/non_destructive.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
- hosts: testhost
|
||||
gather_facts: True
|
||||
roles:
|
||||
- { role: test_copy, tags: test_copy }
|
||||
|
||||
4
tests_new/integration/rackspace.yml
Normal file
4
tests_new/integration/rackspace.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- hosts: testhost
|
||||
gather_facts: True
|
||||
roles: []
|
||||
|
||||
26
tests_new/integration/roles/prepare_tests/tasks/main.yml
Normal file
26
tests_new/integration/roles/prepare_tests/tasks/main.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
# test code for the copy module and action plugin
|
||||
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.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: clean out the test directory
|
||||
file: name={{output_dir|mandatory}} state=absent
|
||||
|
||||
- name: create the test directory
|
||||
file: name={{output_dir}} state=directory
|
||||
|
||||
|
||||
1
tests_new/integration/roles/test_copy/files/foo.txt
Normal file
1
tests_new/integration/roles/test_copy/files/foo.txt
Normal file
@@ -0,0 +1 @@
|
||||
foo.txt
|
||||
1
tests_new/integration/roles/test_copy/foo.txt
Normal file
1
tests_new/integration/roles/test_copy/foo.txt
Normal file
@@ -0,0 +1 @@
|
||||
foo.txt
|
||||
3
tests_new/integration/roles/test_copy/meta/main.yml
Normal file
3
tests_new/integration/roles/test_copy/meta/main.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
dependencies:
|
||||
- prepare_tests
|
||||
|
||||
84
tests_new/integration/roles/test_copy/tasks/main.yml
Normal file
84
tests_new/integration/roles/test_copy/tasks/main.yml
Normal file
@@ -0,0 +1,84 @@
|
||||
# test code for the copy module and action plugin
|
||||
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.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/>.
|
||||
|
||||
# FIXME: replace all fail_when's with asserts
|
||||
|
||||
- set_fact: output_file={{output_dir}}/foo.txt
|
||||
|
||||
- name: initiate a basic copy
|
||||
copy: src=foo.txt dest={{output_file}}
|
||||
register: copy_result
|
||||
|
||||
- assert: { that: "'changed' in copy_result" }
|
||||
- assert: { that: "'dest' in copy_result" }
|
||||
- assert: { that: "'group' in copy_result" }
|
||||
- assert: { that: "'gid' in copy_result" }
|
||||
- assert: { that: "'md5sum' in copy_result" }
|
||||
- assert: { that: "'owner' in copy_result" }
|
||||
- assert: { that: "'size' in copy_result" }
|
||||
- assert: { that: "'src' in copy_result" }
|
||||
- assert: { that: "'state' in copy_result" }
|
||||
- assert: { that: "'uid' in copy_result" }
|
||||
|
||||
|
||||
- name: verify that the file was marked as changed
|
||||
assert: { that: "copy_result.changed == true" }
|
||||
|
||||
- name: verify that the file md5sum is correct
|
||||
assert: { that: "copy_result.md5sum == 'c47397529fe81ab62ba3f85e9f4c71f2'" }
|
||||
|
||||
- name: check the stat results of the file
|
||||
stat: path={{output_file}}
|
||||
register: stat_results
|
||||
|
||||
- debug: var=stat_results
|
||||
|
||||
- assert: { that: "stat_results.stat.exists == true" }
|
||||
- assert: { that: "stat_results.stat.isblk == false" }
|
||||
- assert: { that: "stat_results.stat.isfifo == false" }
|
||||
- assert: { that: "stat_results.stat.isreg == true" }
|
||||
- assert: { that: "stat_results.stat.issock == false" }
|
||||
- assert: { that: "stat_results.stat.md5 == 'c47397529fe81ab62ba3f85e9f4c71f2'" }
|
||||
|
||||
- name: overwrite the file via same means
|
||||
copy: src=foo.txt dest={{output_file}}
|
||||
register: copy_result2
|
||||
|
||||
- name: verify the copy was marked unchanged
|
||||
assert: { that: "not copy_result2|changed" }
|
||||
|
||||
- name: overwrite the file using the content system
|
||||
copy: content="modified" dest={{output_file}}
|
||||
register: copy_result3
|
||||
|
||||
- name: verify the copy result was marked changed
|
||||
assert: { that: "copy_result3|changed" }
|
||||
|
||||
- name: overwrite the file again using the content system
|
||||
copy: content="modified" dest={{output_file}}
|
||||
register: copy_result4
|
||||
|
||||
- name: verify the copy result was marked unchanged
|
||||
assert: { that: "not copy_result4|changed" }
|
||||
|
||||
# TODO: test recursive copy
|
||||
# TODO: test copy where destination is a directory like {{output_dir}}/
|
||||
# TODO: test that copy fails if the path does not exist
|
||||
# TODO: ...
|
||||
|
||||
|
||||
1
tests_new/integration/test.sh
Normal file
1
tests_new/integration/test.sh
Normal file
@@ -0,0 +1 @@
|
||||
ansible-playbook non_destructive.yml -i inventory -e output_dir=~/ansible_testing -v
|
||||
5
tests_new/integration/test_setup.yml
Normal file
5
tests_new/integration/test_setup.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
- hosts: testhost
|
||||
gather_facts: False
|
||||
roles:
|
||||
- test_setup
|
||||
|
||||
Reference in New Issue
Block a user