canonical / canonical/operator

Add support mocking file metadata for tests

Open
#2,708 2 comments 0 reactions 0 assignees View on GitHub
27.04 roadmap
Dominant language
Python
Stars
267
Forks
136
Avg merge
1d 22h
Merged PRs (30d)
28

Description

It would be quite useful for tests if `_TestingPebbleClient`'s mocked file operations also saved a map of the intended metadata and returned the intended metadata for operations that request it.

In particular, it would be helpful for testing cases where metadata such as file ownership or permissions matter and are being checked, as we otherwise need to mock it ourselves.

To give a more concrete example, if we have behavior dependent on the return from `charmlibs.pathops`'s `ensure_contents`, and we want to ensure a file with a particular user/group/set of permissions, in unit test scenarios, it will never match because we are otherwise checking against the metadata from the host file system.

Contributor guide

Open the contributing guide

Research direction

Start with the `_TestingPebbleClient` mocked file operations and trace how metadata is currently handled. Review the `charmlibs.pathops` `ensure_contents` behavior described in the issue, then add or update tests showing that intended file metadata is saved and returned for metadata requests. Done means tests can exercise ownership, group, and permissions without relying on host filesystem metadata.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.