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 27, 2018
1 parent 8f4807e commit fb650ad
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.retry
tests/test.sh
*/__pycache__
*.pyc
24 changes: 17 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
---
language: python
services: docker

env:
- distro: centos7
- distro: ubuntu1604
global:
- ROLE_NAME: dotfiles
matrix:
- MOLECULE_DISTRO: centos7
- MOLECULE_DISTRO: ubuntu1804

script:
# Download test shim.
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
- chmod +x ${PWD}/tests/test.sh
install:
# Install test dependencies.
- pip install molecule docker

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
- molecule test

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Available variables are listed below, along with default values (see `defaults/m

The git repository to use for retrieving dotfiles. Dotfiles should generally be laid out within the root directory of the repository.

dotfiles_repo_accept_hostkey: no
dotfiles_repo_accept_hostkey: false

Add the hostkey for the repo url if not already added. If ssh_opts contains "-o StrictHostKeyChecking=no", this parameter is ignored.

Expand Down
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
dotfiles_repo: "https://github.com/geerlingguy/dotfiles.git"
dotfiles_repo_accept_hostkey: no
dotfiles_repo_accept_hostkey: false
dotfiles_repo_local_destination: "~/Documents/dotfiles"

dotfiles_home: "~"
Expand Down
26 changes: 14 additions & 12 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ galaxy_info:
license: "license (BSD, MIT)"
min_ansible_version: 2.2
platforms:
- name: GenericUNIX
versions:
- all
- any
- name: GenericBSD
versions:
- all
- any
- name: GenericLinux
versions:
- all
- any
- name: GenericUNIX
versions:
- all
- any
- name: GenericBSD
versions:
- all
- any
- name: GenericLinux
versions:
- all
- any
galaxy_tags:
- development
- system
- dotfiles
- configuration
27 changes: 27 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 5 additions & 3 deletions tests/test.yml → molecule/default/playbook.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
- hosts: all
- name: Converge
hosts: all
become: true

pre_tasks:
- name: Update apt cache.
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'

roles:
- geerlingguy.git
- role_under_test
- role: geerlingguy.git
- role: geerlingguy.dotfiles
File renamed without changes.
14 changes: 14 additions & 0 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
extends: default
rules:
line-length:
max: 120
level: warning
6 changes: 3 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
repo: "{{ dotfiles_repo }}"
dest: "{{ dotfiles_repo_local_destination }}"
accept_hostkey: "{{ dotfiles_repo_accept_hostkey }}"
become: no
become: false

- name: Ensure all configured dotfiles are links.
shell: "ls -F {{ dotfiles_home }}/{{ item }}"
register: existing_dotfile_info
failed_when: false
check_mode: no
check_mode: false
changed_when: false
with_items: "{{ dotfiles_files }}"

Expand All @@ -26,5 +26,5 @@
src: "{{ dotfiles_repo_local_destination }}/{{ item }}"
dest: "{{ dotfiles_home }}/{{ item }}"
state: link
become: no
become: false
with_items: "{{ dotfiles_files }}"
11 changes: 0 additions & 11 deletions tests/README.md

This file was deleted.

0 comments on commit fb650ad

Please sign in to comment.