Skip to content

Commit

Permalink
Switch tests to use Molecule.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Sep 28, 2018
1 parent 161a83f commit 8d6238e
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
*.retry
tests/test.sh
*/__pycache__
*.pyc
33 changes: 18 additions & 15 deletions .travis.yml
@@ -1,26 +1,29 @@
---
language: python
services: docker

env:
- distro: centos7
- distro: ubuntu1604
- distro: ubuntu1404
- distro: ubuntu1204
global:
- ROLE_NAME: hereitis
matrix:
- MOLECULE_DISTRO: centos7
MOLECULE_DOCKER_COMMAND: /usr/lib/systemd/systemd
- MOLECULE_DISTRO: ubuntu1604
- MOLECULE_DISTRO: ubuntu1404

script:
# Configure test script so we can run extra tests after playbook is run.
- export container_id=$(date +%s)
- export cleanup=false
install:
# Install test dependencies.
- pip install molecule docker

# Download test shim.
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
- chmod +x ${PWD}/tests/test.sh
before_script:
# Use actual Ansible Galaxy role name for the project directory.
- cd ../
- mv ansible-role-$ROLE_NAME geerlingguy.$ROLE_NAME
- cd geerlingguy.$ROLE_NAME

script:
# Run tests.
- ${PWD}/tests/test.sh

# Check if memcached is running.
- 'docker exec --tty ${container_id} env TERM=xterm memcached -h'
- molecule test

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
19 changes: 13 additions & 6 deletions meta/main.yml
Expand Up @@ -10,16 +10,23 @@ galaxy_info:
platforms:
- name: EL
versions:
- 6
- 7
- 6
- 7
- name: Ubuntu
versions:
- precise
- trusty
- xenial
- precise
- trusty
- xenial
- bionic
- name: Debian
versions:
- all
- all
galaxy_tags:
- web
- database
- memcached
- keyvalue
- kv
- cache
- caching
- performance
27 changes: 27 additions & 0 deletions molecule/default/molecule.yml
@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
options:
config-file: molecule/default/yaml-lint.yml
platforms:
- name: instance
image: geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible
command: ${MOLECULE_DOCKER_COMMAND:-"sleep infinity"}
privileged: true
pre_build_image: true
provisioner:
name: ansible
lint:
name: ansible-lint
playbooks:
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
7 changes: 7 additions & 0 deletions molecule/default/playbook.yml
@@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
become: true

roles:
- role: geerlingguy.memcached
14 changes: 14 additions & 0 deletions molecule/default/tests/test_default.py
@@ -0,0 +1,14 @@
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_hosts_file(host):
f = host.file('/etc/hosts')

assert f.exists
assert f.user == 'root'
assert f.group == 'root'
6 changes: 6 additions & 0 deletions molecule/default/yaml-lint.yml
@@ -0,0 +1,6 @@
---
extends: default
rules:
line-length:
max: 120
level: warning
11 changes: 0 additions & 11 deletions tests/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions tests/test.yml

This file was deleted.

0 comments on commit 8d6238e

Please sign in to comment.