Skip to content

Commit

Permalink
Directory restructure and added integration & unit tests (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
anagha-infoblox authored Oct 11, 2021
1 parent 7521e7c commit 4b0c9a6
Show file tree
Hide file tree
Showing 156 changed files with 3,127 additions and 314 deletions.
176 changes: 154 additions & 22 deletions .github/workflows/ansible-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,175 @@ on:
- cron: '0 2 * * 1'

jobs:
build:
name: Build collection
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ansible-version: [stable-2.10]
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8

- name: Install ansible (${{ matrix.ansible-version }})
run: pip install pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check

- name: Build a collection tarball
run: ansible-galaxy collection build --output-path "${GITHUB_WORKSPACE}/.cache/collection-tarballs"

- name: Store migrated collection artifacts
uses: actions/upload-artifact@v1
with:
name: collection
path: .cache/collection-tarballs


###
# Unit tests
#
# https://docs.ansible.com/ansible/latest/dev_guide/testing_units.html

unit:
name: Unit Tests
needs: [build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [2.7, 3.8, 3.9]
ansible-version: [stable-2.9, stable-2.10, stable-2.11, devel]
exclude:
- ansible-version: devel
python-version: 2.7
- ansible-version: stable-2.9
python-version: 3.9

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install ansible (${{ matrix.ansible-version }}) version
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check

- name: Download migrated collection artifacts
uses: actions/download-artifact@v1
with:
name: collection
path: .cache/collection-tarballs

- name: Setup Unit test Pre-requisites
run: |
ansible-galaxy collection install .cache/collection-tarballs/*.tar.gz
git clone https://github.com/ansible/ansible.git
cp -rf ansible/test/units/compat /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/
cp -rf ansible/test/units/modules/utils.py /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/
sed -i 's/units/ansible_collections.infoblox.nios_modules.tests.unit/' /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/utils.py
if [ -f /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt ]; then pip install -r /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt; fi
- name: Run Unit tests using ansible-test
run: ansible-test units -v --color --python ${{ matrix.python-version }} --coverage
working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/

- name: Generate coverage report
run: ansible-test coverage xml -v --group-by command --group-by version
working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/


###
# Integration tests
#
# https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html

integration:
name: Integration tests
needs: [build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [2.7, 3.8, 3.9]
ansible-version: [stable-2.9, stable-2.10, stable-2.11]
exclude:
- ansible-version: stable-2.9
python-version: 3.9
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Install ansible-base (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check

- name: Download migrated collection artifacts
uses: actions/download-artifact@v1
with:
name: collection
path: .cache/collection-tarball

- name: Install the collection tarball
run: ansible-galaxy collection install .cache/collection-tarball/*.tar.gz

- name: Setup Integration test Pre-requisites
run: pip install -r /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/requirements.txt

# Run the integration tests
- name: Run integration test
run: ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python-version }} --docker --coverage
working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/

# ansible-test support producing code coverage date
- name: Generate coverage report
run: ansible-test coverage xml -v --requirements --group-by command --group-by version
working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/

- uses: codecov/codecov-action@v1
with:
fail_ci_if_error: false


###
# Sanity tests (REQUIRED)
#
# https://docs.ansible.com/ansible/latest/dev_guide/testing_sanity.html

sanity:
name: Sanity (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }})
name: Sanity Tests
runs-on: ubuntu-latest
needs: [build]
strategy:
fail-fast: false
matrix:
ansible:
# It's important that Sanity is tested against all stable-X.Y branches
# Testing against `devel` may fail as new tests are added.
- stable-2.9
- stable-2.10
- stable-2.11
- devel
runs-on: ubuntu-latest
ansible-version: [stable-2.9, stable-2.10, stable-2.11, devel]

steps:
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
# it is just required to run that once as "ansible-test sanity" in the docker image
# will run on all python versions it supports.
python-version: 3.8

# ansible-test requires the collection to be in a directory in the form
# .../ansible_collections/NAMESPACE/COLLECTION_NAME/
- name: Check out code
uses: actions/checkout@v2
- name: Install ansible (${{ matrix.ansible-version }}) version
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check

- name: Set up Python ${{ matrix.ansible }}
uses: actions/setup-python@v2
- name: Download migrated collection artifacts
uses: actions/download-artifact@v1
with:
python-version: '>=3.8'
name: collection
path: .cache/collection-tarballs

# Install the head of the given branch (devel, stable-2.10)
- name: Install ansible-base (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
- name: Setup Sanity test Pre-requisites
run: ansible-galaxy collection install .cache/collection-tarballs/*.tar.gz

# run ansible-test sanity inside of Docker.
# The docker container has all the pinned dependencies that are required.
# Explicity specify the version of Python we want to test
# The docker container has all the pinned dependencies that are required
# and all python versions ansible supports.
- name: Run sanity tests
run: ansible-test sanity --docker -v --color
working-directory: ./ansible_collections/infoblox/nios_modules
working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 4b0c9a6

Please sign in to comment.