@@ -79,6 +79,7 @@ def test_all(run_command, working_dir):
79
79
golden_logs_parent_path = test_data_path .joinpath ("test_all" , "golden" , "logs" , "generate" ),
80
80
logs_subpath = pathlib .Path ("github.com" , "arduino-libraries" , "SpacebrewYun" , "index.html" ),
81
81
)
82
+ check_db (configuration = configuration )
82
83
check_index (configuration = configuration )
83
84
84
85
# Run the engine again
@@ -97,6 +98,7 @@ def test_all(run_command, working_dir):
97
98
golden_logs_parent_path = test_data_path .joinpath ("test_all" , "golden" , "logs" , "update" ),
98
99
logs_subpath = pathlib .Path ("github.com" , "arduino-libraries" , "SpacebrewYun" , "index.html" ),
99
100
)
101
+ check_db (configuration = configuration )
100
102
check_index (configuration = configuration )
101
103
102
104
@@ -106,9 +108,9 @@ def check_libraries(configuration):
106
108
Keyword arguments:
107
109
configuration -- dictionary defining the libraries-repository-engine configuration
108
110
"""
111
+ # Check against the index
109
112
with pathlib .Path (configuration ["LibrariesIndex" ]).open (mode = "r" , encoding = "utf-8" ) as libraries_index_file :
110
113
libraries_index = json .load (fp = libraries_index_file )
111
-
112
114
for release in libraries_index ["libraries" ]:
113
115
release_archive_path = pathlib .Path (
114
116
configuration ["LibrariesFolder" ],
@@ -121,6 +123,21 @@ def check_libraries(configuration):
121
123
122
124
assert release ["checksum" ] == "SHA-256:" + hashlib .sha256 (release_archive_path .read_bytes ()).hexdigest ()
123
125
126
+ # Check against the db
127
+ with pathlib .Path (configuration ["LibrariesDB" ]).open (mode = "r" , encoding = "utf-8" ) as library_db_file :
128
+ library_db = json .load (fp = library_db_file )
129
+ for release in library_db ["Releases" ]:
130
+ release_archive_path = pathlib .Path (
131
+ configuration ["LibrariesFolder" ],
132
+ release ["URL" ].removeprefix (configuration ["BaseDownloadUrl" ]),
133
+ )
134
+
135
+ assert release_archive_path .exists ()
136
+
137
+ assert release ["Size" ] == release_archive_path .stat ().st_size
138
+
139
+ assert release ["Checksum" ] == "SHA-256:" + hashlib .sha256 (release_archive_path .read_bytes ()).hexdigest ()
140
+
124
141
125
142
def check_logs (configuration , golden_logs_parent_path , logs_subpath ):
126
143
"""Run tests to determine whether the engine's logs are as expected.
@@ -147,6 +164,62 @@ def check_logs(configuration, golden_logs_parent_path, logs_subpath):
147
164
assert logs == golden_logs
148
165
149
166
167
+ def check_db (configuration ):
168
+ """Run tests to determine whether the generated library database is as expected.
169
+
170
+ Keyword arguments:
171
+ configuration -- dictionary defining the libraries-repository-engine configuration
172
+ """
173
+ checksum_placeholder = "CHECKSUM_PLACEHOLDER"
174
+
175
+ # Load generated db
176
+ with pathlib .Path (configuration ["LibrariesDB" ]).open (mode = "r" , encoding = "utf-8" ) as db_file :
177
+ db = json .load (fp = db_file )
178
+ for release in db ["Releases" ]:
179
+ # The checksum values in the db will be different on every run, so it's necessary to replace them with a
180
+ # placeholder before comparing to the golden master
181
+ release ["Checksum" ] = checksum_placeholder
182
+
183
+ # Load golden index
184
+ golden_db_template = test_data_path .joinpath ("test_all" , "golden" , "db.json" ).read_text (encoding = "utf-8" )
185
+ # Fill in mutable content
186
+ golden_db_string = string .Template (template = golden_db_template ).substitute (
187
+ base_download_url = configuration ["BaseDownloadUrl" ],
188
+ checksum_placeholder = checksum_placeholder ,
189
+ git_clones_folder = configuration ["GitClonesFolder" ],
190
+ )
191
+ golden_db = json .loads (golden_db_string )
192
+
193
+ # Compare db against golden master
194
+ # Order of entries in the db is arbitrary so a simply equality assertion is not possible
195
+ assert len (db ["Libraries" ]) == len (golden_db ["Libraries" ])
196
+ for library in db ["Libraries" ]:
197
+ assert library in golden_db ["Libraries" ]
198
+
199
+ assert len (db ["Releases" ]) == len (golden_db ["Releases" ])
200
+ for release in db ["Releases" ]:
201
+ # Find the golden master for the release
202
+ golden_release = None
203
+ for golden_release_candidate in golden_db ["Releases" ]:
204
+ if (
205
+ golden_release_candidate ["LibraryName" ] == release ["LibraryName" ]
206
+ and golden_release_candidate ["Version" ] == release ["Version" ]
207
+ ):
208
+ golden_release = golden_release_candidate
209
+ break
210
+
211
+ assert golden_release is not None # Matching golden release was found
212
+
213
+ # Small variation in size could result from compression algorithm changes, so we allow a tolerance
214
+ assert "Size" in release
215
+ assert math .isclose (release ["Size" ], golden_release ["Size" ], rel_tol = size_comparison_tolerance )
216
+ # Remove size data so a direct comparison of the remaining data can be made against the golden master
217
+ del release ["Size" ]
218
+ del golden_release ["Size" ]
219
+
220
+ assert release == golden_release
221
+
222
+
150
223
def check_index (configuration ):
151
224
"""Run tests to determine whether the generated library index is as expected.
152
225
0 commit comments