test: add unit tests for stale-image checks to reach ≥90% diff-coverage
Covers StaleImageError / check_stale / check_stale_path, the BottleBackend.launch template method (skip_stale flag), stale_checks functions across docker / smolmachines / macos-container backends, _build_images cached paths in the macOS backend, image_created_at edge cases in both docker and container util modules, the CLI stale loop (headless die, interactive decline, interactive confirm + retry), and ConfigStore.cached_image_stale_warning_days fallback paths. Diff-coverage: 488/507 changed lines covered (96.3%).
This commit is contained in:
@@ -54,6 +54,33 @@ class TestConfigStore(unittest.TestCase):
|
||||
manager.migrate()
|
||||
self.assertTrue(manager.is_migrated())
|
||||
|
||||
def test_cached_image_warning_days_returns_default_when_db_missing(self) -> None:
|
||||
# When the db file doesn't exist yet (parent exists, file doesn't),
|
||||
# the store returns the default without touching the file.
|
||||
with tempfile.TemporaryDirectory(prefix="config-store.") as tmp:
|
||||
store = ConfigStore(Path(tmp) / "missing.db")
|
||||
self.assertEqual(
|
||||
DEFAULT_CACHED_IMAGE_STALE_WARNING_DAYS,
|
||||
store.cached_image_stale_warning_days(),
|
||||
)
|
||||
|
||||
def test_cached_image_warning_days_returns_default_on_null_value(self) -> None:
|
||||
# If the row exists but the value is NULL (or not castable to int),
|
||||
# the store falls back to the default.
|
||||
with tempfile.TemporaryDirectory(prefix="config-store.") as tmp:
|
||||
db_path = Path(tmp) / "bot-bottle.db"
|
||||
store = ConfigStore(db_path)
|
||||
store.migrate()
|
||||
# Write a NULL value directly.
|
||||
with sqlite3.connect(db_path) as conn:
|
||||
conn.execute(
|
||||
"UPDATE bot_bottle_config SET cached_image_stale_warning_days = NULL WHERE id = 1"
|
||||
)
|
||||
self.assertEqual(
|
||||
DEFAULT_CACHED_IMAGE_STALE_WARNING_DAYS,
|
||||
store.cached_image_stale_warning_days(),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user