Skip to content

Commit af0129f

Browse files
test: clean-up policy downloader tests
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
1 parent f9cd46b commit af0129f

File tree

1 file changed

+22
-51
lines changed

1 file changed

+22
-51
lines changed

src/policy_downloader.rs

+22-51
Original file line numberDiff line numberDiff line change
@@ -261,21 +261,10 @@ async fn create_verifier(
261261
#[cfg(test)]
262262
mod tests {
263263
use super::*;
264-
use lazy_static::lazy_static;
265264
use tempfile::TempDir;
266-
use tokio::{runtime::Runtime, sync::Mutex};
267-
268-
lazy_static! {
269-
// Allocate the DOWNLOADER once, this is needed to reduce the execution time
270-
// of the unit tests
271-
static ref DOWNLOADER: Mutex<Downloader> = Mutex::new({
272-
let rt = Runtime::new().unwrap();
273-
rt.block_on(async { Downloader::new(None, true, None).await.unwrap() })
274-
});
275-
}
276265

277-
#[test]
278-
fn verify_success() {
266+
#[tokio::test]
267+
async fn verify_success() {
279268
let verification_cfg_yml = r#"---
280269
allOf:
281270
- kind: pubKey
@@ -314,24 +303,15 @@ mod tests {
314303

315304
let policy_download_dir = TempDir::new().expect("Cannot create temp dir");
316305

317-
// This is required to have lazy_static create the object right now,
318-
// outside of the tokio runtime. Creating the object inside of the tokio
319-
// rutime causes a panic because sigstore-rs' code invokes a `block_on` too
320-
let downloader = DOWNLOADER.lock();
321-
drop(downloader);
322-
323-
let rt = Runtime::new().unwrap();
324-
let fetched_policies = rt.block_on(async {
325-
DOWNLOADER
326-
.lock()
327-
.await
328-
.download_policies(
329-
&policies,
330-
policy_download_dir.path().to_str().unwrap(),
331-
Some(&verification_config),
332-
)
333-
.await
334-
});
306+
let mut downloader = Downloader::new(None, true, None).await.unwrap();
307+
308+
let fetched_policies = downloader
309+
.download_policies(
310+
&policies,
311+
policy_download_dir.path().to_str().unwrap(),
312+
Some(&verification_config),
313+
)
314+
.await;
335315

336316
// There are 2 policies defined, but they both reference the same
337317
// WebAssembly module. Hence, just one `.wasm` file is going to be
@@ -344,8 +324,8 @@ mod tests {
344324
.is_ok());
345325
}
346326

347-
#[test]
348-
fn verify_error() {
327+
#[tokio::test]
328+
async fn verify_error() {
349329
let verification_cfg_yml = r#"---
350330
allOf:
351331
- kind: githubAction
@@ -365,24 +345,15 @@ mod tests {
365345

366346
let policy_download_dir = TempDir::new().expect("Cannot create temp dir");
367347

368-
// This is required to have lazy_static create the object right now,
369-
// outside of the tokio runtime. Creating the object inside of the tokio
370-
// rutime causes a panic because sigstore-rs' code invokes a `block_on` too
371-
let downloader = DOWNLOADER.lock();
372-
drop(downloader);
373-
374-
let rt = Runtime::new().unwrap();
375-
let fetched_policies = rt.block_on(async {
376-
DOWNLOADER
377-
.lock()
378-
.await
379-
.download_policies(
380-
&policies,
381-
policy_download_dir.path().to_str().unwrap(),
382-
Some(&verification_config),
383-
)
384-
.await
385-
});
348+
let mut downloader = Downloader::new(None, true, None).await.unwrap();
349+
350+
let fetched_policies = downloader
351+
.download_policies(
352+
&policies,
353+
policy_download_dir.path().to_str().unwrap(),
354+
Some(&verification_config),
355+
)
356+
.await;
386357

387358
// There are 2 policies defined, but they both reference the same
388359
// WebAssembly module. Hence, just one `.wasm` file is going to be

0 commit comments

Comments
 (0)