Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add integration tests for scripts in ANTA documentation #1011

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

gmuloc
Copy link
Collaborator

@gmuloc gmuloc commented Jan 15, 2025

Description

Fixes #831

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have run pre-commit for code linting and typing (pre-commit run)
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (tox -e testenv)

@gmuloc gmuloc changed the title Test: Add integration tests for scripts in ANTA documentation test: Add integration tests for scripts in ANTA documentation Jan 15, 2025
@@ -342,3 +342,33 @@ async def connect_inventory(self) -> None:
if isinstance(r, Exception):
message = "Error when refreshing inventory"
anta_log_exception(r, message, logger)

def dump(self, path: Path) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AntaCatalog class has a dump() function that has a different signature and doing different stuff.
Let's aggree on an equivalent signature for the dump(), yaml(), and json() functions.
Same for the ResultManager it is another dump() function returning a dict...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah not sure why I added this - this is a PR from a couple of months ago :p will need to re read

try:
with path.open("w", encoding="UTF-8") as file:
safe_dump(
{AntaInventory.INVENTORY_ROOT_KEY: {"hosts": [safe_load(host.model_dump_json(serialize_as_any=True, exclude_unset=True)) for host in hosts]}},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe get rid of INVENTORY_ROOT_KEY and write the right pydantic model?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Doc: Write tests for the scripts used in doc to make sure we don't break them
2 participants