Skip to content

Commit e7bbb3d

Browse files
committed
Add integration test for clean checkout
The engine's Git code is failing to get a clean checkout of releases under some circumstances. This resulted in the ssd1306@1.0.0 release being accepted even though the repository contains a .exe at that tag. However, the engine's checkout code fails to add the .exe when checking out this tag, leaving the repository in a dirty state that just so happens to allow it to pass validation. Although harmless in this particular situation, this could cause big problems if essential files went missing from releases, and so must be tested for.
1 parent 46b1a65 commit e7bbb3d

File tree

9 files changed

+47
-7
lines changed

9 files changed

+47
-7
lines changed

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# See: https://prettier.io/docs/en/ignore.html#ignoring-files-prettierignore
22

3-
/test/testdata/golden/logs/
3+
/test/testdata/test_all/golden/logs/

test/test_all.py

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_all(run_command, working_dir):
5858

5959
libraries_repository_engine_command = [
6060
working_dir_path.joinpath("config.json"),
61-
test_data_path.joinpath("repos.txt"),
61+
test_data_path.joinpath("test_all", "repos.txt"),
6262
]
6363

6464
# Run the engine
@@ -69,12 +69,12 @@ def test_all(run_command, working_dir):
6969
check_libraries(configuration=configuration)
7070
check_logs(
7171
configuration=configuration,
72-
golden_logs_parent_path=test_data_path.joinpath("golden", "logs", "generate"),
72+
golden_logs_parent_path=test_data_path.joinpath("test_all", "golden", "logs", "generate"),
7373
logs_subpath=pathlib.Path("github.com", "arduino-libraries", "ArduinoCloudThing", "index.html"),
7474
)
7575
check_logs(
7676
configuration=configuration,
77-
golden_logs_parent_path=test_data_path.joinpath("golden", "logs", "generate"),
77+
golden_logs_parent_path=test_data_path.joinpath("test_all", "golden", "logs", "generate"),
7878
logs_subpath=pathlib.Path("github.com", "arduino-libraries", "SpacebrewYun", "index.html"),
7979
)
8080
check_index(configuration=configuration)
@@ -87,12 +87,12 @@ def test_all(run_command, working_dir):
8787
check_libraries(configuration=configuration)
8888
check_logs(
8989
configuration=configuration,
90-
golden_logs_parent_path=test_data_path.joinpath("golden", "logs", "update"),
90+
golden_logs_parent_path=test_data_path.joinpath("test_all", "golden", "logs", "update"),
9191
logs_subpath=pathlib.Path("github.com", "arduino-libraries", "ArduinoCloudThing", "index.html"),
9292
)
9393
check_logs(
9494
configuration=configuration,
95-
golden_logs_parent_path=test_data_path.joinpath("golden", "logs", "update"),
95+
golden_logs_parent_path=test_data_path.joinpath("test_all", "golden", "logs", "update"),
9696
logs_subpath=pathlib.Path("github.com", "arduino-libraries", "SpacebrewYun", "index.html"),
9797
)
9898
check_index(configuration=configuration)
@@ -160,7 +160,9 @@ def check_index(configuration):
160160
del release["checksum"]
161161

162162
# Load golden index
163-
golden_library_index_template = test_data_path.joinpath("golden", "library_index.json").read_text(encoding="utf-8")
163+
golden_library_index_template = test_data_path.joinpath("test_all", "golden", "library_index.json").read_text(
164+
encoding="utf-8"
165+
)
164166
# Fill in mutable content
165167
golden_library_index_string = string.Template(template=golden_library_index_template).substitute(
166168
base_download_url=configuration["BaseDownloadUrl"]
@@ -173,6 +175,43 @@ def check_index(configuration):
173175
assert release in golden_library_index["libraries"]
174176

175177

178+
# The engine's Git code struggles to get a clean checkout of releases under some circumstances.
179+
def test_clean_checkout(run_command, working_dir):
180+
working_dir_path = pathlib.Path(working_dir)
181+
configuration = {
182+
"BaseDownloadUrl": "http://www.example.com/libraries/",
183+
"LibrariesFolder": working_dir_path.joinpath("libraries").as_posix(),
184+
"LogsFolder": working_dir_path.joinpath("logs").as_posix(),
185+
"LibrariesDB": working_dir_path.joinpath("libraries_db.json").as_posix(),
186+
"LibrariesIndex": working_dir_path.joinpath("libraries", "library_index.json").as_posix(),
187+
"GitClonesFolder": working_dir_path.joinpath("gitclones").as_posix(),
188+
"DoNotRunClamav": True,
189+
# Arduino Lint should be installed under PATH
190+
"ArduinoLintPath": "",
191+
}
192+
193+
# Generate configuration file
194+
with working_dir_path.joinpath("config.json").open("w", encoding="utf-8") as configuration_file:
195+
json.dump(obj=configuration, fp=configuration_file, indent=2)
196+
197+
libraries_repository_engine_command = [
198+
working_dir_path.joinpath("config.json"),
199+
test_data_path.joinpath("test_clean_checkout", "repos.txt"),
200+
]
201+
202+
# Run the engine
203+
result = run_command(cmd=libraries_repository_engine_command)
204+
assert result.ok
205+
206+
# Load generated index
207+
with pathlib.Path(configuration["LibrariesIndex"]).open(mode="r", encoding="utf-8") as library_index_file:
208+
library_index = json.load(fp=library_index_file)
209+
210+
for release in library_index["libraries"]:
211+
# ssd1306@1.0.0 contains a .exe and so should fail validation.
212+
assert not (release["name"] == "ssd1306" and release["version"] == "1.0.0")
213+
214+
176215
@pytest.fixture(scope="function")
177216
def run_command(pytestconfig, working_dir) -> typing.Callable[..., invoke.runners.Result]:
178217
"""Provide a wrapper around invoke's `run` API so that every test will work in the same temporary folder.
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/lexus2k/ssd1306.git|Contributed|ssd1306

0 commit comments

Comments
 (0)