forked from containers/ansible-podman-collections
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unittests for Ansible Podman modules (containers#504)
Signed-off-by: Sagi Shnaidman <[email protected]>
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Unittests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
schedule: | ||
- cron: 3 0 * * * # Run daily at 0:03 UTC | ||
|
||
jobs: | ||
build-collection-artifact: | ||
name: Test | ||
runs-on: ${{ matrix.runner-os }} | ||
strategy: | ||
matrix: | ||
runner-os: | ||
- ubuntu-22.04 | ||
# ansible-version: | ||
# - git+https://github.com/ansible/[email protected] | ||
runner-python-version: | ||
- 3.9 | ||
steps: | ||
|
||
- name: Check out ${{ github.repository }} on disk | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python ${{ matrix.runner-python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.runner-python-version }} | ||
|
||
- name: Set up pip cache | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('tests/sanity/requirements.txt') }}-${{ hashFiles('tests/unit/requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
${{ runner.os }}- | ||
- name: Install requirements for tests | ||
run: >- | ||
python -m pip install --user -r test-requirements.txt | ||
- name: Build a collection tarball | ||
run: >- | ||
~/.local/bin/ansible-galaxy collection build --output-path | ||
"${GITHUB_WORKSPACE}/.cache/collection-tarballs" | ||
- name: Install the collection tarball | ||
run: >- | ||
~/.local/bin/ansible-galaxy collection install ${GITHUB_WORKSPACE}/.cache/collection-tarballs/*.tar.gz | ||
- name: Run collection unit tests | ||
run: >- | ||
~/.local/bin/ansible-test units | ||
--python "${{ matrix.runner-python-version }}" -vvv | ||
tests/unit/plugins/modules/ | ||
working-directory: >- | ||
/home/runner/.ansible/collections/ansible_collections/containers/podman |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ansible-core | ||
pytest | ||
pytest-forked | ||
pytest-xdist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
import pytest | ||
|
||
from ansible_collections.containers.podman.plugins.module_utils.podman.common import ( | ||
lower_keys, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize('test_input, expected', [ | ||
(["AAA", "BBB"], ["AAA", "BBB"]), | ||
("AAQQ", "AAQQ"), | ||
({"AAA": "AaaAa", "11": 22, "AbCdEf": None, "bbb": "aaaAA"}, | ||
{"aaa": "AaaAa", "11": 22, "abcdef": None, "bbb": "aaaAA"}) | ||
]) | ||
def test_lower_keys(test_input, expected): | ||
print(lower_keys.__code__.co_filename) | ||
assert lower_keys(test_input) == expected |