crate / crate/cratedb-toolkit

Cluster API: Add test coverage for sys.exit, time.sleep, and lru_cache in api/main.py

Open
#423 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
10
Forks
5
Avg merge
7d 5h
Merged PRs (30d)
7

Description

## Context
This issue was created based on suggestions from the CodeRabbit review on PR #81.

## Description
The PR #81 added new imports (sys, time, lru_cache) to `cratedb_toolkit/api/main.py` that aren't exercised by existing tests.

Test coverage should be added for the following locations:

- `cratedb_toolkit/api/main.py:171`: `sys.exit(1)` in the error-handling branch of `ManagedCluster.from_env` (when `CONFIG.settings_errors == "exit"`)
- `cratedb_toolkit/api/main.py:264`: `time.sleep(3.25)` in the retry/delay logic
- `cratedb_toolkit/api/main.py:350`: `@lru_cache(maxsize=1)` on the cached helper method

## Suggested tests
- Simulate a CLI/env misconfiguration to trigger the `sys.exit(1)` path (e.g. patch `CONFIG.settings_errors`).
- Monkey-patch or stub `time.sleep` to verify it is called with `3.25` seconds.
- Call the `@lru_cache`-decorated function twice with identical arguments and assert the underlying logic runs only once (cache hit).

## References
- PR: #81 (SDK and CLI for CrateDB Cloud Cluster APIs)
- [Comment link](https://github.com/crate/cratedb-toolkit/pull/81#discussion_r2061727105)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.