Skip to content

Commit ccb1fec

Browse files
authored
chore(samples): Adding a test to make sure snippets are up-to-date (#243)
* chore(samples): Adding a test to make sure snippets are up-to-date
1 parent 0adb8b6 commit ccb1fec

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

compute/compute/sgs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def __repr__(self):
9090
re.compile(r".*requirements-test\.txt$"),
9191
re.compile(r".*?/tests/.*"),
9292
re.compile(r".*?/__pycache__/.*"),
93+
re.compile(r".*?sponge_log.xml.*"),
9394
)
9495

9596

compute/compute/snippets/instances/create_start_instance/create_with_existing_disks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030

3131
def get_disk(project_id: str, zone: str, disk_name: str) -> compute_v1.Disk:
3232
"""
33-
Deletes a disk from a project.
33+
Gets a disk from a project.
3434
3535
Args:
3636
project_id: project ID or project number of the Cloud project you want to use.
37-
zone: name of the zone in which is the disk you want to delete.
37+
zone: name of the zone where the disk exists.
3838
disk_name: name of the disk you want to retrieve.
3939
"""
4040
disk_client = compute_v1.DisksClient()

compute/compute/test_sgs.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from pathlib import Path
1717
import tempfile
1818

19+
import pytest
20+
1921
from . import sgs
2022

2123
FIXTURE_INGREDIENTS = Path("sgs_test_fixtures/ingredients")
@@ -30,3 +32,26 @@ def test_sgs_generate():
3032
for test_file in map(Path, glob.glob(f"{tmp_dir}/**")):
3133
match_file = FIXTURE_OUTPUT / test_file.relative_to(tmp_dir)
3234
assert test_file.read_bytes() == match_file.read_bytes()
35+
36+
37+
def test_snippets_freshness():
38+
"""
39+
Make sure that the snippets/ folder is up-to-date and matches
40+
ingredients/ and recipes/. This test will generate SGS output
41+
in a temporary directory and compare it to the content of
42+
snippets/ folder.
43+
"""
44+
with tempfile.TemporaryDirectory() as tmp_dir:
45+
args = Namespace(output_dir=tmp_dir)
46+
sgs.generate(args, Path("ingredients/").absolute(), Path("recipes/").absolute())
47+
print(list(map(Path, glob.glob(f"{tmp_dir}/**"))))
48+
for test_file in map(Path, glob.glob(f"{tmp_dir}/**", recursive=True)):
49+
match_file = Path("snippets/") / test_file.relative_to(tmp_dir)
50+
if test_file.is_file():
51+
if test_file.read_bytes() != match_file.read_bytes():
52+
pytest.fail(
53+
f"This test fails because file {match_file} seems to be outdated. Please run "
54+
f"`python sgs.py generate` to update your snippets."
55+
)
56+
elif test_file.is_dir():
57+
assert match_file.is_dir()

0 commit comments

Comments
 (0)