Commit graph

10 commits

Author SHA1 Message Date
Denis Laxalde 903b83e211 Use fake HTTP server for the Patroni API in tests
We introduce a patroni_api fixture, defined in tests/conftest.py, which
sets up an HTTP server serving files in a temporary directory. The
server is itself defined by the PatroniAPI class; it has a 'routes()'
context manager method to be used in actual tests to setup expected
responses based on specified JSON files.

We set up some logging in order to improve debugging.

The direct advantage of this is that PatroniResource.rest_api() method
is now covered by the test suite.

Coverage before this commit:

  Name                        Stmts   Miss  Cover
  -----------------------------------------------
  check_patroni/__init__.py       3      0   100%
  check_patroni/cli.py          193     18    91%
  check_patroni/cluster.py      113      0   100%
  check_patroni/convert.py       23      5    78%
  check_patroni/node.py         146      1    99%
  check_patroni/types.py         50     23    54%
  -----------------------------------------------
  TOTAL                         528     47    91%

and after this commit:

  Name                        Stmts   Miss  Cover
  -----------------------------------------------
  check_patroni/__init__.py       3      0   100%
  check_patroni/cli.py          193     18    91%
  check_patroni/cluster.py      113      0   100%
  check_patroni/convert.py       23      5    78%
  check_patroni/node.py         146      1    99%
  check_patroni/types.py         50      9    82%
  -----------------------------------------------
  TOTAL                         528     33    94%

In actual test functions, we either invoke patroni_api.routes() to
configure which JSON file(s) should be served for each endpoint, or we
define dedicated fixtures (e.g. cluster_config_has_changed()) to
configure this for several test functions or the whole module.

The 'old_replica_state' parametrized fixture is used when needed to
adjust such fixtures, e.g. in cluster_has_replica_ok(), to modify the
JSON content using cluster_api_set_replica_running() (previously in
tests/tools.py, now in tests/__init__.py).

The dependency on pytest-mock is no longer needed.
2023-10-06 10:40:29 +02:00
Denis Laxalde 2d2c389bdb Configure coverage
To be run with 'pytest --cov --cov-report=html'.
2023-10-06 10:33:04 +02:00
Denis Laxalde 34f576ea0f Turn --use-old-replica-state into a parametrized fixture
Instead of requiring the user to run the test suite with and without the
--use-old-replica-state flag, we introduce an 'old_replica_state()'
parametrized fixture that is used only when needed (i.e. in
test_cluster_{has_replica,node_count}.py).
2023-10-06 10:33:04 +02:00
benoit 82e0af8a9e Update README CONTRIBUTING RELEASE
* README: add information pertaining to shell completion;
* CONTRIBUTING: remove release information;
* RELEASE: create a dedicated file with all the relevant release
  information.
2023-08-30 10:19:18 +02:00
benoit f0c2a243f0 Moving things around in README.md and CONTRIBUTING.md 2023-08-28 11:59:59 +02:00
benoit c18fa67a09 Tox updates, setup.py fixes and CONTRIBUTING.md 2022-07-13 16:04:49 +02:00
benoit 8519416c11 Rename test to tests 2022-07-11 12:42:59 +02:00
benoit 1e3da856cc Rename doc to docs 2022-07-11 12:42:55 +02:00
benoit 77f07b105e Move vagrant to / 2022-07-11 12:38:39 +02:00
Étienne BERSAC 3ac8570748
Review README, extracting CONTRIBUTING 2022-07-11 12:12:55 +02:00