Add tests for APTRepositoryCacheUpdateRule

The custom ansible-lint rule APTRepositoryCacheUpdateRule was added in
67bfc90703, this change adds tests to
validate its functionality.

Change-Id: Ie0642cc41c016fc016b2bc6fc6d04b6afdf2be2c
Partial-bug: 1750656
This commit is contained in:
git-harry 2018-03-09 10:22:47 +00:00
parent 1f78260615
commit cb435cea45
5 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,22 @@
import unittest
from ansiblelint import RulesCollection, Runner
from APTRepositoryCacheUpdateRule import APTRepositoryCacheUpdateRule
class TestAPTRepositoryCacheUpdateRule(unittest.TestCase):
collection = RulesCollection()
def setUp(self):
self.collection.register(APTRepositoryCacheUpdateRule())
def test_file_positive(self):
success = 'ansible-lint/test/apt-repository-cache-update-success.yml'
good_runner = Runner(self.collection, success, [], [], [])
self.assertEqual([], good_runner.run())
def test_file_negative(self):
failure = 'ansible-lint/test/apt-repository-cache-update-failure.yml'
bad_runner = Runner(self.collection, failure, [], [], [])
errs = bad_runner.run()
self.assertEqual(4, len(errs))

View File

View File

@ -0,0 +1,23 @@
- tasks:
- name: APT cache updates implicitly enabled
apt_repository:
repo: "deb https://example.com/foo/ bar baz"
- name: APT cache updates explicitly enabled
apt_repository:
repo: "deb https://example.com/foo/ bar baz"
update_cache: true
- name: APT cache updates implicitly enabled and retries
apt_repository:
repo: "deb https://example.com/foo/ bar baz"
register: add_repo
until: add_repo|success
- name: APT cache updates explicitly enabled and retries
apt_repository:
repo: "deb https://example.com/foo/ bar baz"
update_cache: true
register: add_repo
until: add_repo|success

View File

@ -0,0 +1,13 @@
- tasks:
- name: Apt cache update disabled
apt_repository:
repo: "deb https://example.com/foo/ bar baz"
update_cache: false
- name: Apt cache update disabled with retries
apt_repository:
repo: "deb https://example.com/foo/ bar baz"
update_cache: false
register: add_repo
until: add_repo|success

View File

@ -41,6 +41,9 @@ echo "ANSIBLE_LINT_PARAMS: ${ANSIBLE_LINT_PARAMS}"
# Ensure that the Ansible environment is properly prepared # Ensure that the Ansible environment is properly prepared
source "${COMMON_TESTS_PATH}/test-ansible-env-prep.sh" source "${COMMON_TESTS_PATH}/test-ansible-env-prep.sh"
# Run unit tests for OSA ansible-lint rules
python -m unittest discover -s "${WORKING_DIR}/ansible-lint" -p 'Test*.py'
# Execute ansible-lint. We do not want to test dependent roles located # Execute ansible-lint. We do not want to test dependent roles located
# in $HOME/.ansible/roles since we only care about the role we are currently # in $HOME/.ansible/roles since we only care about the role we are currently
# testing. # testing.