Skip to content

Commit 2997196

Browse files
committedSep 11, 2024·
Add test
1 parent 7043c64 commit 2997196

File tree

11 files changed

+311
-14
lines changed

11 files changed

+311
-14
lines changed
 

‎.ansible-lint

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
3+
profile: production
4+
5+
exclude_paths:
6+
- .github
7+
- .manala

‎.github/workflows/lint.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
lint:
9+
name: Lint
10+
runs-on: ubuntu-24.04
11+
steps:
12+
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Set up system
17+
uses: ./.manala/github/system/setup
18+
19+
- name: Lint
20+
run: |
21+
make lint VERBOSE=1

‎.github/workflows/test.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
test:
9+
name: Test
10+
runs-on: ubuntu-24.04
11+
steps:
12+
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Set up system
17+
uses: ./.manala/github/system/setup
18+
19+
- name: Sanity
20+
run: |
21+
make test.sanity VERBOSE=1
22+
23+
- name: Units
24+
run: |
25+
make test.units VERBOSE=1 COVERAGE=1
26+
27+
- name: Integration
28+
run: |
29+
make test.integration VERBOSE=1 COVERAGE=1
30+
31+
- name: Coverage
32+
run: |
33+
make test.coverage VERBOSE=1
34+
35+
- name: Codecov
36+
uses: codecov/codecov-action@v2
37+
with:
38+
fail_ci_if_error: false

‎CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
11+
### Added
12+
13+
- Initial release
14+

‎Makefile

+69-13
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,72 @@
22

33
include .manala/Makefile
44

5-
#########
6-
# Setup #
7-
#########
8-
9-
# ## Project - Setup
10-
# setup: setup.ansible
11-
12-
# ## Project - Setup ansible
13-
# setup.ansible: SHELL := $(MANALA_DOCKER_SHELL)
14-
# setup.ansible:
15-
# ansible-galaxy install \
16-
# --verbose \
17-
# -r requirements.yaml
5+
########
6+
# Lint #
7+
########
8+
9+
## Lint - Lint collection [VERBOSE]
10+
lint:
11+
$(call manala_docker_shell, ansible-lint \
12+
$(if $(VERBOSE), -v) \
13+
--force-color \
14+
)
15+
.PHONY: lint
16+
17+
########
18+
# Test #
19+
########
20+
21+
## Test - Run all tests (but coverage)
22+
test: test.sanity test.units test.integration
23+
.PHONY: test
24+
25+
## Test - Run sanity tests [VERBOSE]
26+
test.sanity:
27+
$(call manala_docker_shell, ansible-test sanity \
28+
--requirements \
29+
--venv \
30+
--python 3.11 \
31+
$(if $(VERBOSE), --verbose) \
32+
--color yes \
33+
--exclude .github/ \
34+
--exclude .manala/ \
35+
)
36+
.PHONY: test.sanity
37+
38+
## Test - Run units tests [VERBOSE|COVERAGE]
39+
test.units:
40+
$(call manala_docker_shell, ansible-test units \
41+
--requirements \
42+
--venv \
43+
--python 3.11 \
44+
$(if $(VERBOSE), --verbose) \
45+
$(if $(COVERAGE), --coverage) \
46+
--color yes \
47+
)
48+
.PHONY: test.units
49+
50+
## Test - Run integration tests [VERBOSE|COVERAGE]
51+
test.integration:
52+
$(call manala_docker_shell, ansible-test integration \
53+
--requirements \
54+
--venv \
55+
--python 3.11 \
56+
$(if $(VERBOSE), --verbose) \
57+
$(if $(COVERAGE), --coverage) \
58+
--color yes \
59+
)
60+
.PHONY: test.integration
61+
62+
## Test - Run coverage [VERBOSE]
63+
test.coverage:
64+
$(call manala_docker_shell, ansible-test coverage xml \
65+
--requirements \
66+
--venv \
67+
--python 3.11 \
68+
--group-by command \
69+
--group-by version \
70+
$(if $(VERBOSE), --verbose) \
71+
--color yes \
72+
)
73+
.PHONY: test.coverage

‎plugins/modules/path.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
description:
1313
- Handle path
1414
author:
15-
- Manala (contact@manala.io)
15+
- Manala (@manala)
1616
'''
1717

1818
EXAMPLES = '''

‎tests/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__
2+
/output

‎tests/integration/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
inventory
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
3+
###########
4+
# Present #
5+
###########
6+
7+
- name: Present
8+
tags: present
9+
vars:
10+
path: /tmp/integration/path/present
11+
block:
12+
- name: Present | Setup path
13+
ansible.builtin.file: # noqa: risky-file-permissions
14+
path: "{{ path }}"
15+
state: "{{ item }}"
16+
loop: [absent, directory]
17+
- name: Present | Converge
18+
manala.path.path:
19+
path: "{{ [path, item.path] | ansible.builtin.path_join }}"
20+
state: present
21+
loop:
22+
- path: foo
23+
- name: Present | Stats
24+
ansible.builtin.stat:
25+
path: "{{ [path, item.path] | ansible.builtin.path_join }}"
26+
register: stats
27+
loop:
28+
- path: foo
29+
- name: Present | Verify
30+
ansible.builtin.assert:
31+
that:
32+
- stats.results[0].stat.exists is true
33+
- stats.results[0].stat.isdir is true
34+
35+
##########
36+
# Absent #
37+
##########
38+
39+
- name: Absent
40+
tags: absent
41+
vars:
42+
path: /tmp/integration/path/absent
43+
block:
44+
- name: Absent | Setup path
45+
ansible.builtin.file: # noqa: risky-file-permissions
46+
path: "{{ path }}"
47+
state: "{{ item }}"
48+
loop: [absent, directory]
49+
- name: Absent | Prepare files
50+
ansible.builtin.file: # noqa: risky-file-permissions
51+
path: "{{ [path, item.path] | ansible.builtin.path_join }}"
52+
state: touch
53+
loop:
54+
- path: foo
55+
- name: Absent | Converge
56+
manala.path.path:
57+
path: "{{ [path, item.path] | ansible.builtin.path_join }}"
58+
state: absent
59+
loop:
60+
- path: foo
61+
- name: Absent | Stats
62+
ansible.builtin.stat:
63+
path: "{{ [path, item.path] | ansible.builtin.path_join }}"
64+
register: stats
65+
loop:
66+
- path: foo
67+
- name: Absent | Verify
68+
ansible.builtin.assert:
69+
that:
70+
- stats.results[0].stat.exists is false
71+
72+
###########
73+
# Content #
74+
###########
75+
76+
- name: Content
77+
tags: content
78+
vars:
79+
path: /tmp/integration/path/content
80+
block:
81+
- name: Content | Setup path
82+
ansible.builtin.file: # noqa: risky-file-permissions
83+
path: "{{ path }}"
84+
state: "{{ item }}"
85+
loop: [absent, directory]
86+
- name: Content | Converge
87+
manala.path.path:
88+
path: "{{ [path, item.path] | ansible.builtin.path_join }}"
89+
content: "{{ item.content }}"
90+
loop:
91+
- path: foo
92+
content: foo
93+
- name: Content | Stats
94+
ansible.builtin.stat:
95+
path: "{{ [path, item.path] | ansible.builtin.path_join }}"
96+
register: stats
97+
loop:
98+
- path: foo
99+
- name: Content | Contents
100+
ansible.builtin.slurp:
101+
src: "{{ [path, item.path] | ansible.builtin.path_join }}"
102+
register: contents
103+
loop:
104+
- path: foo
105+
- name: Content | Verify
106+
ansible.builtin.assert:
107+
that:
108+
- stats.results[0].stat.exists is true
109+
- contents.results[0].content | b64decode == 'foo'
110+
111+
############
112+
# Template #
113+
############
114+
115+
- name: Template
116+
tags: template
117+
vars:
118+
path: /tmp/integration/path/template
119+
block:
120+
- name: Template | Setup path
121+
ansible.builtin.file: # noqa: risky-file-permissions
122+
path: "{{ path }}"
123+
state: "{{ item }}"
124+
loop: [absent, directory]
125+
- name: Template | Converge
126+
manala.path.path:
127+
path: "{{ [path, item.path] | ansible.builtin.path_join }}"
128+
template: "{{ item.template }}"
129+
loop:
130+
- path: foo
131+
template: foo.j2
132+
- name: Template | Stats
133+
ansible.builtin.stat:
134+
path: "{{ [path, item.path] | ansible.builtin.path_join }}"
135+
register: stats
136+
loop:
137+
- path: foo
138+
- name: Template | Contents
139+
ansible.builtin.slurp:
140+
src: "{{ [path, item.path] | ansible.builtin.path_join }}"
141+
register: contents
142+
loop:
143+
- path: foo
144+
- name: Template | Verify
145+
ansible.builtin.assert:
146+
that:
147+
- stats.results[0].stat.exists is true
148+
- contents.results[0].content | b64decode == 'foo'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo

‎tests/unit/plugins/test_path.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import unittest
2+
3+
4+
class Test(unittest.TestCase):
5+
6+
def test_nothing(self):
7+
self.nothing = None
8+
self.assertIsNone(self.nothing)
9+
# To continue

0 commit comments

Comments
 (0)
Please sign in to comment.