From 062086260520c2a24bfd8e840295ecd0f55120af Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 24 Jun 2020 14:12:04 -0400 Subject: [PATCH] Clean up some fetch_remote_source tets (#6446) --- cli/file_fetcher.rs | 56 +++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index 4da0f8b86a..1a60e22c2d 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -1380,25 +1380,14 @@ mod tests { } #[tokio::test] - async fn test_fetch_source_2() { - let http_server_guard = test_util::http_server(); + async fn fetch_remote_source_no_ext() { + let g = test_util::http_server(); let (_temp_dir, fetcher) = test_setup(); - let fetcher_1 = fetcher.clone(); - let fetcher_2 = fetcher.clone(); let module_url = - Url::parse("http://localhost:4545/cli/tests/subdir/no_ext").unwrap(); - let module_url_2 = - Url::parse("http://localhost:4545/cli/tests/subdir/mismatch_ext.ts") - .unwrap(); - let module_url_2_ = module_url_2.clone(); - let module_url_3 = - Url::parse("http://localhost:4545/cli/tests/subdir/unknown_ext.deno") - .unwrap(); - let module_url_3_ = module_url_3.clone(); - + &Url::parse("http://localhost:4545/cli/tests/subdir/no_ext").unwrap(); let result = fetcher .fetch_remote_source( - &module_url, + module_url, false, false, 10, @@ -1409,11 +1398,21 @@ mod tests { let r = result.unwrap(); assert_eq!(r.source_code, b"export const loaded = true;\n"); assert_eq!(&(r.media_type), &msg::MediaType::TypeScript); - let (_, headers) = fetcher.http_cache.get(&module_url).unwrap(); + let (_, headers) = fetcher.http_cache.get(module_url).unwrap(); assert_eq!(headers.get("content-type").unwrap(), "text/typescript"); - let result = fetcher_1 + drop(g) + } + + #[tokio::test] + async fn fetch_remote_source_mismatch_ext() { + let g = test_util::http_server(); + let (_temp_dir, fetcher) = test_setup(); + let module_url = + &Url::parse("http://localhost:4545/cli/tests/subdir/mismatch_ext.ts") + .unwrap(); + let result = fetcher .fetch_remote_source( - &module_url_2, + module_url, false, false, 10, @@ -1424,13 +1423,21 @@ mod tests { let r2 = result.unwrap(); assert_eq!(r2.source_code, b"export const loaded = true;\n"); assert_eq!(&(r2.media_type), &msg::MediaType::JavaScript); - let (_, headers) = fetcher.http_cache.get(&module_url_2_).unwrap(); + let (_, headers) = fetcher.http_cache.get(module_url).unwrap(); assert_eq!(headers.get("content-type").unwrap(), "text/javascript"); + drop(g); + } - // test unknown extension - let result = fetcher_2 + #[tokio::test] + async fn fetch_remote_source_unknown_ext() { + let g = test_util::http_server(); + let (_temp_dir, fetcher) = test_setup(); + let module_url = + &Url::parse("http://localhost:4545/cli/tests/subdir/unknown_ext.deno") + .unwrap(); + let result = fetcher .fetch_remote_source( - &module_url_3, + module_url, false, false, 10, @@ -1441,10 +1448,9 @@ mod tests { let r3 = result.unwrap(); assert_eq!(r3.source_code, b"export const loaded = true;\n"); assert_eq!(&(r3.media_type), &msg::MediaType::TypeScript); - let (_, headers) = fetcher.http_cache.get(&module_url_3_).unwrap(); + let (_, headers) = fetcher.http_cache.get(module_url).unwrap(); assert_eq!(headers.get("content-type").unwrap(), "text/typescript"); - - drop(http_server_guard); + drop(g); } #[tokio::test]