diff --git a/ansible-lint/test/TestAPTRepositoryCacheUpdateRule.py b/ansible-lint/test/TestAPTRepositoryCacheUpdateRule.py new file mode 100644 index 00000000..f2aa1e01 --- /dev/null +++ b/ansible-lint/test/TestAPTRepositoryCacheUpdateRule.py @@ -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)) diff --git a/ansible-lint/test/__init__.py b/ansible-lint/test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ansible-lint/test/apt-repository-cache-update-failure.yml b/ansible-lint/test/apt-repository-cache-update-failure.yml new file mode 100644 index 00000000..c68474ce --- /dev/null +++ b/ansible-lint/test/apt-repository-cache-update-failure.yml @@ -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 diff --git a/ansible-lint/test/apt-repository-cache-update-success.yml b/ansible-lint/test/apt-repository-cache-update-success.yml new file mode 100644 index 00000000..f108f151 --- /dev/null +++ b/ansible-lint/test/apt-repository-cache-update-success.yml @@ -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 diff --git a/test-ansible-lint.sh b/test-ansible-lint.sh index 4c6cb6ad..cb8cfbf3 100755 --- a/test-ansible-lint.sh +++ b/test-ansible-lint.sh @@ -41,6 +41,9 @@ echo "ANSIBLE_LINT_PARAMS: ${ANSIBLE_LINT_PARAMS}" # Ensure that the Ansible environment is properly prepared 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 # in $HOME/.ansible/roles since we only care about the role we are currently # testing.