Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Use cookiecutter via tox to clone verify playbook
Browse files Browse the repository at this point in the history
The verify playbook for the functional tests was manually copied to each
dir. This change attempts to DRY out the setup of the tests by using
cookiecutter to clone the default playbook.
  • Loading branch information
abtreece committed Jan 1, 2021
1 parent ed175da commit cb2fca6
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
---
# This is an example playbook to execute goss tests.
# Tests need distributed to the appropriate ansible host/groups
# prior to execution by `goss validate`.

{% raw -%}
- name: Verify
hosts: all
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Molecule managed

---
file:
/etc/hosts:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
file:
/usr/local/bin/goss:
exists: true
owner: root
group: root
mode: "0755"
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
---
# This is an example playbook to execute goss tests.
# Tests need distributed to the appropriate ansible host/groups
# prior to execution by `goss validate`.

- name: Verify
hosts: all
become: true
vars:
goss_version: v0.3.7
goss_version: v0.3.13
goss_arch: amd64
goss_bin: /usr/local/bin/goss
goss_sha256sum: 357f5c7f2e7949b412bce44349cd32ab19eb3947255a8ac805f884cc2c326059.
goss_sha256sum: eb3522ff9682736ff61e2ad114de227de98debcf8a03ca66fcda3917577313e0.
goss_test_directory: /tmp/molecule/goss
goss_format: documentation
tasks:
Expand All @@ -21,7 +17,7 @@
sha256sum: "{{ goss_sha256sum }}"
mode: 0755

- name: Create Molecule directory for test files
- name: Create Molecule directory for test files # noqa 208
file:
path: "{{ goss_test_directory }}"
state: directory
Expand All @@ -45,19 +41,19 @@
msg: "{{ test_files.files }}"
verbosity: 3

- name: Copy Goss tests to remote
- name: Copy Goss tests to remote # noqa 208
copy:
src: "{{ item.path }}"
dest: "{{ goss_test_directory }}/{{ item.path | basename }}"
with_items:
- "{{ test_files.files }}"

- name: Register test files
shell: "ls {{ goss_test_directory }}/test_*.yml"
shell: "ls {{ goss_test_directory }}/test_*.yml" # noqa 301
register: test_files

- name: Execute Goss tests
command: "{{ goss_bin }} -g {{ item }} validate --format {{ goss_format }}"
command: "{{ goss_bin }} -g {{ item }} validate --format {{ goss_format }}" # noqa 301
register: test_results
with_items: "{{ test_files.stdout_lines }}"
failed_when: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Molecule managed

---
file:
/etc/hosts:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
file:
/usr/local/bin/goss:
exists: true
owner: root
group: root
mode: "0755"
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
---
# This is an example playbook to execute goss tests.
# Tests need distributed to the appropriate ansible host/groups
# prior to execution by `goss validate`.

- name: Verify
hosts: all
become: true
vars:
goss_version: v0.3.7
goss_version: v0.3.13
goss_arch: amd64
goss_bin: /usr/local/bin/goss
goss_sha256sum: 357f5c7f2e7949b412bce44349cd32ab19eb3947255a8ac805f884cc2c326059.
goss_sha256sum: eb3522ff9682736ff61e2ad114de227de98debcf8a03ca66fcda3917577313e0.
goss_test_directory: /tmp/molecule/goss
goss_format: documentation
tasks:
Expand All @@ -21,7 +17,7 @@
sha256sum: "{{ goss_sha256sum }}"
mode: 0755

- name: Create Molecule directory for test files
- name: Create Molecule directory for test files # noqa 208
file:
path: "{{ goss_test_directory }}"
state: directory
Expand All @@ -45,19 +41,19 @@
msg: "{{ test_files.files }}"
verbosity: 3

- name: Copy Goss tests to remote
- name: Copy Goss tests to remote # noqa 208
copy:
src: "{{ item.path }}"
dest: "{{ goss_test_directory }}/{{ item.path | basename }}"
with_items:
- "{{ test_files.files }}"

- name: Register test files
shell: "ls {{ goss_test_directory }}/test_*.yml"
shell: "ls {{ goss_test_directory }}/test_*.yml" # noqa 301
register: test_files

- name: Execute Goss tests
command: "{{ goss_bin }} -g {{ item }} validate --format {{ goss_format }}"
command: "{{ goss_bin }} -g {{ item }} validate --format {{ goss_format }}" # noqa 301
register: test_results
with_items: "{{ test_files.stdout_lines }}"
failed_when: false
Expand Down
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ commands =
ansibledevel: ansible-galaxy install git+https://github.com/ansible-collections/community.general.git
# failsafe as pip may install incompatible dependencies
pip check
# use cookiecutter to deploy the functional test verify playbooks
cookiecutter -f molecule_goss/cookiecutter/ --output-dir molecule_goss/test/scenarios/docker/centos7/ --no-input
cookiecutter -f molecule_goss/cookiecutter/ --output-dir molecule_goss/test/scenarios/docker/ubuntu18.04/ --no-input
# failsafe for preventing changes that may break pytest collection
python -m pytest -p no:cov --collect-only
python -m pytest {posargs:-l}
Expand All @@ -49,6 +52,7 @@ deps =
py{36,37,38,39}: molecule[test]
py{36,37,38,39}-{devel}: git+https://github.com/ansible-community/molecule.git@master#egg=molecule[test]
dockerfile: ansible>=2.9.12
cookiecutter
molecule-docker
docker>=4.3.1
passenv =
Expand Down

0 comments on commit cb2fca6

Please sign in to comment.