Skip to content

Commit 072cefa

Browse files
committed
Update TESTING guide
Signed-off-by: Webster Mudge <wmudge@cloudera.com>
1 parent a72feaa commit 072cefa

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

TESTING.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Testing cloudera.cluster
2+
3+
This project uses [Hatch](https://hatch.pypa.io/dev/) to manage the project dependencies, testing environments, common utilities and scripts, and other activities. It also makes heavy use of [pytest](https://pytest.org). We also use [pre-commit](https://pre-commit.com/), [antsibull-docs](https://ansible.readthedocs.io/projects/antsibull-docs/), and [ansible-lint](https://ansible.readthedocs.io/projects/lint/) for linting and hygiene.
4+
5+
To set up a development and test environment for the collection, you need to:
6+
7+
1. Set up the Hatch build system
8+
1. Set up the Ansible Collection and Role paths
9+
1. Configure the PYTHONPATH to use the correct location of the collections code
10+
11+
## Hatch Build System
12+
13+
You should install `hatch` as [per its documentation](https://hatch.pypa.io/dev/install/#installers). `hatch` should be able to handle all dependencies, including Python versions and virtual environments.
14+
15+
> [!danger] OSX `dirs.data` default!
16+
> The [default data directory](https://hatch.pypa.io/1.13/config/hatch/#data) for `hatch` is `~/Library/Application Support/hatch`, which causes trouble for `molecule`! You might need to change this location to a path with spaces!
17+
18+
## Ansible Collection and Role Paths
19+
20+
You have to install your Ansible collections, both the collection under test and its dependencies, into the `ansible_collections/<namespace>/<name>` folder structure. For the collection under test, run the following _in the parent directory of your choosing_:
21+
22+
```bash
23+
git clone https://github.com/cloudera-labs/cloudera.cluster.git ansible_collections/cloudera/cluster
24+
```
25+
26+
Then create the `roles` directory in this _parent directory_:
27+
28+
```bash
29+
mkdir roles
30+
```
31+
32+
Lastly, set the Ansible [COLLECTION](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#envvar-ANSIBLE_COLLECTIONS_PATH) and [ROLE](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#envvar-ANSIBLE_ROLES_PATH) configurations for these two locations:
33+
34+
```bash
35+
export ANSIBLE_COLLECTIONS_PATH=$(pwd)
36+
export ANSIBLE_ROLES_PATH="$(pwd)/roles"
37+
```
38+
39+
## PYTHONPATH
40+
41+
Make sure to include the `ANSIBLE_COLLECTIONS_PATH` variable to the `PYTHONPATH` to allow module imports.
42+
43+
```bash
44+
export PYTHONPATH="${ANSIBLE_COLLECTIONS_PATH}":"${PYTHONPATH}"
45+
```
46+
47+
# Linting and Commits
48+
49+
The `pre-commit` Python application is used to manage linting and other housekeeping functions. The application is installed as a `git` hook and as a Github workflow check.
50+
51+
Commits and pull requests will fail if your contributions do not pass the `pre-commit` checks. You can check your work-in-progress code by running the following:
52+
53+
```bash
54+
hatch run lint
55+
```
56+
57+
Or manually:
58+
59+
```bash
60+
pre-commit run -a
61+
```
62+
63+
# pytest Testing
64+
65+
> [!warning] Integration test instructions
66+
> The vast majority of tests require an existing Cloudera on premise deployment as the target. Currently, these instructions are not yet complete!
67+
68+
To see what tests (unit and integration) are available, run the following from the `ANSIBLE_COLLECTIONS_PATH` directory:
69+
70+
```bash
71+
pushd ${ANSIBLE_COLLECTIONS_PATH};
72+
pytest ansible_collections/cloudera/cluster --collect-only;
73+
popd;
74+
```
75+
76+
You should see something like:
77+
78+
```
79+
platform darwin -- Python 3.12.8, pytest-8.4.1, pluggy-1.6.0
80+
rootdir: /Users/wmudge/Devel/collections/ansible_collections/cloudera/cluster
81+
configfile: pyproject.toml
82+
plugins: mock-3.14.1
83+
collected 475 items
84+
85+
<Dir cluster>
86+
<Dir tests>
87+
<Package unit>
88+
<Dir plugins>
89+
<Dir actions>
90+
<Dir assemble_cluster_template>
91+
<Module test_assemble_cluster_template_action.py>
92+
<Function test_empty_parameters>
93+
<Function test_missing_src>
94+
<Function test_missing_dest>
95+
<Function test_remote_src>
96+
<Function test_src_not_found>
97+
<Function test_src_not_directory>
98+
<Function test_invalid_regexp>
99+
<Function test_assemble_fragments>
100+
<Function test_assemble_fragments_regexp>
101+
<Function test_assemble_fragments_malformed>
102+
<Dir modules>
103+
<Dir assemble_cluster_template>
104+
<Module test_assemble_cluster_template_module.py>
105+
<Function test_missing_required>
106+
<Function test_missing_dest>
107+
```
108+
109+
To run all of the tests:
110+
111+
```bash
112+
pushd ${ANSIBLE_COLLECTIONS_PATH};
113+
pytest ansible_collections/cloudera/cluster;
114+
popd;
115+
```
116+
117+
To run a selected test, execute with a regex:
118+
119+
```bash
120+
pushd ${ANSIBLE_COLLECTIONS_PATH};
121+
pytest ansible_collections/cloudera/cluster -k "test_assemble_cluster_template_module"
122+
popd;
123+
```

0 commit comments

Comments
 (0)