Skip to content

Commit

Permalink
Merge pull request #18 from wtsi-hgi/feature/testing
Browse files Browse the repository at this point in the history
Adds tests
  • Loading branch information
jiffyclub authored Aug 29, 2017
2 parents fcce089 + 370e6b7 commit d4d544f
Show file tree
Hide file tree
Showing 18 changed files with 243 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---

sudo: required

services:
- docker

install:
- docker build -t test-runner -f Dockerfile.test .

script:
- docker run --rm -t -v $PWD:/ansible-conda test-runner
28 changes: 28 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ubuntu

ENV DATA_DIRECTORY=/ansible-conda

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
python \
python-pip \
python-apt \
python-dev \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*

RUN pip install setuptools wheel
RUN pip install ansible==2.3.2.0

ADD tests/requirements.yml /tmp/requirements.yml
RUN ansible-galaxy install -r /tmp/requirements.yml

ADD tests/requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt

VOLUME "${DATA_DIRECTORY}"

CMD ansible-galaxy install -r "${DATA_DIRECTORY}/tests/requirements.yml" \
&& pip install -r "${DATA_DIRECTORY}/tests/requirements.txt" \
&& ansible-playbook -vvv -e ansible_python_interpreter=$(which python) -c local "${DATA_DIRECTORY}/tests/site.yml"
6 changes: 6 additions & 0 deletions tests/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

conda_tests_python_version: 2
conda_tests_anaconda_version: 4.4.0
conda_tests_anaconda_installation_location: /tmp/install/anaconda
conda_tests_conda_executable: "{{ conda_tests_anaconda_installation_location }}/bin/conda"
1 change: 1 addition & 0 deletions tests/library/conda.py
10 changes: 10 additions & 0 deletions tests/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

dependencies:
- role: anaconda
vars:
anaconda_python_ver: "{{ conda_tests_python_version }}"
anaconda_ver: "{{ conda_tests_anaconda_version }}"
anaconda_pkg_update: no
anaconda_parent_dir: "{{ conda_tests_anaconda_installation_location | dirname }}"
anaconda_link_subdir: "{{ conda_tests_anaconda_installation_location | basename }}"
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jmespath
5 changes: 5 additions & 0 deletions tests/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

- name: anaconda
src: https://github.com/wtsi-hgi/ansible-anaconda.git
version: 60ac57016facaf8658437ca4700f4037b60be42e
1 change: 1 addition & 0 deletions tests/site.retry
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
5 changes: 5 additions & 0 deletions tests/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

- hosts: localhost
roles:
- ../
9 changes: 9 additions & 0 deletions tests/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- name: install apt prerequisites
apt:
name: python-pip

- name: install Python prerequisites
pip:
name: jmespath
24 changes: 24 additions & 0 deletions tests/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---

- include: install.yml
- include: tear-down.yml

- block:
- include: test-install-latest.yml
always:
- include: tear-down.yml

- block:
- include: test-install-fixed-version.yml
always:
- include: tear-down.yml

- block:
- include: test-upgrade.yml
always:
- include: tear-down.yml

- block:
- include: test-downgrade.yml
always:
- include: tear-down.yml
20 changes: 20 additions & 0 deletions tests/tasks/set-install-facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

- name: find installed Conda matching packages
shell: "{{ conda_tests_conda_executable }} search --json ^{{ conda_tests_install_example }}$"
no_log: True
register: installed_raw

- name: filter output
set_fact:
installed: "{{ (installed_raw.stdout | from_json | json_query('%s[?installed]' % conda_tests_install_example)) }}"

- name: ensure expected environment
assert:
that: installed | length <= 1

- name: set install facts
set_fact:
example_package:
installed: "{{ installed | length != 0 }}"
version: "{{ installed[0].version if installed | length > 0 else False }}"
13 changes: 13 additions & 0 deletions tests/tasks/tear-down.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---

- name: uninstall package via Conda
conda:
name: "{{ conda_tests_install_example }}"
state: absent
executable: "{{ conda_tests_conda_executable }}"

- include: set-install-facts.yml

- name: verify package not installed
assert:
that: not example_package.installed
23 changes: 23 additions & 0 deletions tests/tasks/test-downgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

- name: install latest package via conda
conda:
name: "{{ conda_tests_install_example }}"
state: latest
executable: "{{ conda_tests_conda_executable }}"

- name: install old package via conda
conda:
name: "{{ conda_tests_install_example }}"
version: "{{ conda_tests_old_version }}"
state: present
executable: "{{ conda_tests_conda_executable }}"
register: second_install

- include: set-install-facts.yml

- name: verify installed
assert:
that: second_install.changed
that: example_package.installed
that: example_package.version | version_compare(conda_tests_old_version, '=')
29 changes: 29 additions & 0 deletions tests/tasks/test-install-fixed-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---

- name: install package via conda
conda:
name: "{{ conda_tests_install_example }}"
version: "{{ conda_tests_old_version }}"
state: present
executable: "{{ conda_tests_conda_executable }}"
register: first_install

- include: set-install-facts.yml

- name: verify installed
assert:
that: first_install.changed
that: example_package.installed
that: example_package.version | version_compare(conda_tests_old_version, '=')

- name: install package via conda (again)
conda:
name: "{{ conda_tests_install_example }}"
version: "{{ conda_tests_old_version }}"
state: present
executable: "{{ conda_tests_conda_executable }}"
register: second_install

- name: verify idempotence
assert:
that: not second_install.changed
27 changes: 27 additions & 0 deletions tests/tasks/test-install-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---

- name: install package via conda
conda:
name: "{{ conda_tests_install_example }}"
state: latest
executable: "{{ conda_tests_conda_executable }}"
register: first_install

- include: set-install-facts.yml

- name: verify installed
assert:
that: first_install.changed
that: example_package.installed
that: example_package.version | version_compare(conda_tests_minimum_latest_version, '>=')

- name: install package via conda (again)
conda:
name: "{{ conda_tests_install_example }}"
state: latest
executable: "{{ conda_tests_conda_executable }}"
register: second_install

- name: verify idempotence
assert:
that: not second_install.changed
23 changes: 23 additions & 0 deletions tests/tasks/test-upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

- name: install old package via conda
conda:
name: "{{ conda_tests_install_example }}"
version: "{{ conda_tests_old_version }}"
state: present
executable: "{{ conda_tests_conda_executable }}"

- name: install latest package via conda
conda:
name: "{{ conda_tests_install_example }}"
state: latest
executable: "{{ conda_tests_conda_executable }}"
register: second_install

- include: set-install-facts.yml

- name: verify installed
assert:
that: second_install.changed
that: example_package.installed
that: example_package.version | version_compare(conda_tests_minimum_latest_version, '>=')
6 changes: 6 additions & 0 deletions tests/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

# XXX: better to hit local package repository with dummy package
conda_tests_install_example: translationstring
conda_tests_minimum_latest_version: "1.3"
conda_tests_old_version: "1.1"

0 comments on commit d4d544f

Please sign in to comment.