diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..b06b5b2 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,7 @@ +--- + +profile: production + +exclude_paths: + - .github + - .manala diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..8380664 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,21 @@ +name: Lint + +on: + pull_request: + workflow_dispatch: + +jobs: + lint: + name: Lint + runs-on: ubuntu-24.04 + steps: + + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up system + uses: ./.manala/github/system/setup + + - name: Lint + run: | + make lint VERBOSE=1 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..1607889 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,38 @@ +name: Test + +on: + pull_request: + workflow_dispatch: + +jobs: + test: + name: Test + runs-on: ubuntu-24.04 + steps: + + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up system + uses: ./.manala/github/system/setup + + - name: Sanity + run: | + make test.sanity VERBOSE=1 + + - name: Units + run: | + make test.units VERBOSE=1 COVERAGE=1 + + - name: Integration + run: | + make test.integration VERBOSE=1 COVERAGE=1 + + - name: Coverage + run: | + make test.coverage VERBOSE=1 + + - name: Codecov + uses: codecov/codecov-action@v2 + with: + fail_ci_if_error: false diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..fb63abb --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + + +### Added + +- Initial release + diff --git a/Makefile b/Makefile index 9030007..9080133 100644 --- a/Makefile +++ b/Makefile @@ -2,16 +2,72 @@ include .manala/Makefile -######### -# Setup # -######### - -# ## Project - Setup -# setup: setup.ansible - -# ## Project - Setup ansible -# setup.ansible: SHELL := $(MANALA_DOCKER_SHELL) -# setup.ansible: -# ansible-galaxy install \ -# --verbose \ -# -r requirements.yaml +######## +# Lint # +######## + +## Lint - Lint collection [VERBOSE] +lint: + $(call manala_docker_shell, ansible-lint \ + $(if $(VERBOSE), -v) \ + --force-color \ + ) +.PHONY: lint + +######## +# Test # +######## + +## Test - Run all tests (but coverage) +test: test.sanity test.units test.integration +.PHONY: test + +## Test - Run sanity tests [VERBOSE] +test.sanity: + $(call manala_docker_shell, ansible-test sanity \ + --requirements \ + --venv \ + --python 3.11 \ + $(if $(VERBOSE), --verbose) \ + --color yes \ + --exclude .github/ \ + --exclude .manala/ \ + ) +.PHONY: test.sanity + +## Test - Run units tests [VERBOSE|COVERAGE] +test.units: + $(call manala_docker_shell, ansible-test units \ + --requirements \ + --venv \ + --python 3.11 \ + $(if $(VERBOSE), --verbose) \ + $(if $(COVERAGE), --coverage) \ + --color yes \ + ) +.PHONY: test.units + +## Test - Run integration tests [VERBOSE|COVERAGE] +test.integration: + $(call manala_docker_shell, ansible-test integration \ + --requirements \ + --venv \ + --python 3.11 \ + $(if $(VERBOSE), --verbose) \ + $(if $(COVERAGE), --coverage) \ + --color yes \ + ) +.PHONY: test.integration + +## Test - Run coverage [VERBOSE] +test.coverage: + $(call manala_docker_shell, ansible-test coverage xml \ + --requirements \ + --venv \ + --python 3.11 \ + --group-by command \ + --group-by version \ + $(if $(VERBOSE), --verbose) \ + --color yes \ + ) +.PHONY: test.coverage diff --git a/plugins/modules/path.py b/plugins/modules/path.py index 49703ce..c2f36b9 100644 --- a/plugins/modules/path.py +++ b/plugins/modules/path.py @@ -12,7 +12,7 @@ description: - Handle path author: - - Manala (contact@manala.io) + - Manala (@manala) ''' EXAMPLES = ''' diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..8a5f091 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +/output diff --git a/tests/integration/.gitignore b/tests/integration/.gitignore new file mode 100644 index 0000000..e845c18 --- /dev/null +++ b/tests/integration/.gitignore @@ -0,0 +1 @@ +inventory diff --git a/tests/integration/targets/path/tasks/main.yaml b/tests/integration/targets/path/tasks/main.yaml new file mode 100644 index 0000000..703c938 --- /dev/null +++ b/tests/integration/targets/path/tasks/main.yaml @@ -0,0 +1,148 @@ +--- + +########### +# Present # +########### + +- name: Present + tags: present + vars: + path: /tmp/integration/path/present + block: + - name: Present | Setup path + ansible.builtin.file: # noqa: risky-file-permissions + path: "{{ path }}" + state: "{{ item }}" + loop: [absent, directory] + - name: Present | Converge + manala.path.path: + path: "{{ [path, item.path] | ansible.builtin.path_join }}" + state: present + loop: + - path: foo + - name: Present | Stats + ansible.builtin.stat: + path: "{{ [path, item.path] | ansible.builtin.path_join }}" + register: stats + loop: + - path: foo + - name: Present | Verify + ansible.builtin.assert: + that: + - stats.results[0].stat.exists is true + - stats.results[0].stat.isdir is true + +########## +# Absent # +########## + +- name: Absent + tags: absent + vars: + path: /tmp/integration/path/absent + block: + - name: Absent | Setup path + ansible.builtin.file: # noqa: risky-file-permissions + path: "{{ path }}" + state: "{{ item }}" + loop: [absent, directory] + - name: Absent | Prepare files + ansible.builtin.file: # noqa: risky-file-permissions + path: "{{ [path, item.path] | ansible.builtin.path_join }}" + state: touch + loop: + - path: foo + - name: Absent | Converge + manala.path.path: + path: "{{ [path, item.path] | ansible.builtin.path_join }}" + state: absent + loop: + - path: foo + - name: Absent | Stats + ansible.builtin.stat: + path: "{{ [path, item.path] | ansible.builtin.path_join }}" + register: stats + loop: + - path: foo + - name: Absent | Verify + ansible.builtin.assert: + that: + - stats.results[0].stat.exists is false + +########### +# Content # +########### + +- name: Content + tags: content + vars: + path: /tmp/integration/path/content + block: + - name: Content | Setup path + ansible.builtin.file: # noqa: risky-file-permissions + path: "{{ path }}" + state: "{{ item }}" + loop: [absent, directory] + - name: Content | Converge + manala.path.path: + path: "{{ [path, item.path] | ansible.builtin.path_join }}" + content: "{{ item.content }}" + loop: + - path: foo + content: foo + - name: Content | Stats + ansible.builtin.stat: + path: "{{ [path, item.path] | ansible.builtin.path_join }}" + register: stats + loop: + - path: foo + - name: Content | Contents + ansible.builtin.slurp: + src: "{{ [path, item.path] | ansible.builtin.path_join }}" + register: contents + loop: + - path: foo + - name: Content | Verify + ansible.builtin.assert: + that: + - stats.results[0].stat.exists is true + - contents.results[0].content | b64decode == 'foo' + +############ +# Template # +############ + +- name: Template + tags: template + vars: + path: /tmp/integration/path/template + block: + - name: Template | Setup path + ansible.builtin.file: # noqa: risky-file-permissions + path: "{{ path }}" + state: "{{ item }}" + loop: [absent, directory] + - name: Template | Converge + manala.path.path: + path: "{{ [path, item.path] | ansible.builtin.path_join }}" + template: "{{ item.template }}" + loop: + - path: foo + template: foo.j2 + - name: Template | Stats + ansible.builtin.stat: + path: "{{ [path, item.path] | ansible.builtin.path_join }}" + register: stats + loop: + - path: foo + - name: Template | Contents + ansible.builtin.slurp: + src: "{{ [path, item.path] | ansible.builtin.path_join }}" + register: contents + loop: + - path: foo + - name: Template | Verify + ansible.builtin.assert: + that: + - stats.results[0].stat.exists is true + - contents.results[0].content | b64decode == 'foo' diff --git a/tests/integration/targets/path/templates/foo.j2 b/tests/integration/targets/path/templates/foo.j2 new file mode 100644 index 0000000..1910281 --- /dev/null +++ b/tests/integration/targets/path/templates/foo.j2 @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git a/tests/unit/plugins/test_path.py b/tests/unit/plugins/test_path.py new file mode 100644 index 0000000..6d928fc --- /dev/null +++ b/tests/unit/plugins/test_path.py @@ -0,0 +1,9 @@ +import unittest + + +class Test(unittest.TestCase): + + def test_nothing(self): + self.nothing = None + self.assertIsNone(self.nothing) + # To continue