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

Example testing improvements #2487

Merged
merged 7 commits into from
Aug 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update tfdoc
  • Loading branch information
juliocc committed Aug 8, 2024
commit 8a76378f63d8ead1c4a32ed13e3102d6854ec30b
20 changes: 11 additions & 9 deletions tools/tfdoc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2023 Google LLC
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,18 +45,20 @@
import string
import sys
import urllib.parse
from pathlib import Path

import click
import marko

try:
from examples.conftest import get_tftest_directive
except ImportError:
BASEDIR = Path(__file__).parents[1]
sys.path.append(str(BASEDIR / 'tests'))
from examples.conftest import get_tftest_directive

__version__ = '2.1.0'

# COUNT_TEST_RE copied from tests/examples/test_plan.py
COUNT_TEST_RE = re.compile(
r'# tftest +modules=(?P<modules>\d+) +resources=(?P<resources>\d+)' +
r'(?: +files=(?P<files>[\w@,_-]+))?' +
r'(?: +fixtures=(?P<fixtures>[\w@,_/.-]+))?' +
r'(?: +inventory=(?P<inventory>[\w\-.]+))?')
# TODO(ludomagno): decide if we want to support variables*.tf and outputs*.tf
FILE_DESC_DEFAULTS = {
'main.tf': 'Module-level locals and resources.',
Expand Down Expand Up @@ -390,8 +392,8 @@ def parse_fixtures(basepath, readme):
if isinstance(child, marko.block.FencedCode):
if child.lang == 'hcl':
code = child.children[0].children
if match := COUNT_TEST_RE.search(code):
if fixtures := match.group('fixtures'):
if directive := get_tftest_directive(code):
if fixtures := directive.kwargs.get('fixtures'):
for fixture in fixtures.split(','):
fixture_full = os.path.join(REPO_ROOT, 'tests', fixture)
if not os.path.exists(fixture_full):
Expand Down