diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2021-08-11 10:20:47 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-11 10:20:47 -0400 |
commit | 15a763152f9d392cb80692262f8de5ef8ae15495 (patch) | |
tree | fcd1a59777f95920bf3502519983d6cc0d882a9a /test_util/src/lib.rs | |
parent | a0285e2eb88f6254f6494b0ecd1878db3a3b2a58 (diff) |
chore: move test files to testdata directory (#11601)
Diffstat (limited to 'test_util/src/lib.rs')
-rw-r--r-- | test_util/src/lib.rs | 85 |
1 files changed, 42 insertions, 43 deletions
diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index 93a02c98e..d0067b15f 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -92,6 +92,10 @@ pub fn tests_path() -> PathBuf { root_path().join("cli").join("tests") } +pub fn testdata_path() -> PathBuf { + tests_path().join("testdata") +} + pub fn third_party_path() -> PathBuf { root_path().join("third_party") } @@ -200,7 +204,7 @@ async fn inf_redirects(req: Request<Body>) -> hyper::Result<Response<Body>> { async fn another_redirect(req: Request<Body>) -> hyper::Result<Response<Body>> { let p = req.uri().path(); assert_eq!(&p[0..1], "/"); - let url = format!("http://localhost:{}/cli/tests/subdir{}", PORT, p); + let url = format!("http://localhost:{}/subdir{}", PORT, p); Ok(redirect_resp(url)) } @@ -265,12 +269,9 @@ async fn get_tls_config( key: &str, ca: &str, ) -> io::Result<Arc<rustls::ServerConfig>> { - let mut cert_path = root_path(); - let mut key_path = root_path(); - let mut ca_path = root_path(); - cert_path.push(cert); - key_path.push(key); - ca_path.push(ca); + let cert_path = testdata_path().join(cert); + let key_path = testdata_path().join(key); + let ca_path = testdata_path().join(ca); let cert_file = std::fs::File::open(cert_path)?; let key_file = std::fs::File::open(key_path)?; @@ -323,9 +324,9 @@ async fn get_tls_config( } async fn run_wss_server(addr: &SocketAddr) { - let cert_file = "cli/tests/tls/localhost.crt"; - let key_file = "cli/tests/tls/localhost.key"; - let ca_cert_file = "cli/tests/tls/RootCA.pem"; + let cert_file = "tls/localhost.crt"; + let key_file = "tls/localhost.key"; + let ca_cert_file = "tls/RootCA.pem"; let tls_config = get_tls_config(cert_file, key_file, ca_cert_file) .await @@ -362,13 +363,13 @@ async fn run_wss_server(addr: &SocketAddr) { /// This server responds with 'PASS' if client authentication was successful. Try it by running /// test_server and -/// curl --key cli/tests/tls/localhost.key \ -/// --cert cli/tests/tls/localhost.crt \ -/// --cacert cli/tests/tls/RootCA.crt https://localhost:4552/ +/// curl --key cli/tests/testdata/tls/localhost.key \ +/// --cert cli/tests/testsdata/tls/localhost.crt \ +/// --cacert cli/tests/testdata/tls/RootCA.crt https://localhost:4552/ async fn run_tls_client_auth_server() { - let cert_file = "cli/tests/tls/localhost.crt"; - let key_file = "cli/tests/tls/localhost.key"; - let ca_cert_file = "cli/tests/tls/RootCA.pem"; + let cert_file = "tls/localhost.crt"; + let key_file = "tls/localhost.key"; + let ca_cert_file = "tls/RootCA.pem"; let tls_config = get_tls_config(cert_file, key_file, ca_cert_file) .await .unwrap(); @@ -444,7 +445,7 @@ async fn absolute_redirect( } } - let mut file_path = root_path(); + let mut file_path = testdata_path(); file_path.push(&req.uri().path()[1..]); if file_path.is_dir() || !file_path.exists() { let mut not_found_resp = Response::new(Body::empty()); @@ -676,7 +677,7 @@ async fn main_server(req: Request<Body>) -> hyper::Result<Response<Body>> { ); Ok(res) } - (_, "/cli/tests/subdir/xTypeScriptTypesRedirect.d.ts") => { + (_, "/subdir/xTypeScriptTypesRedirect.d.ts") => { let mut res = Response::new(Body::from( "import './xTypeScriptTypesRedirected.d.ts';", )); @@ -686,7 +687,7 @@ async fn main_server(req: Request<Body>) -> hyper::Result<Response<Body>> { ); Ok(res) } - (_, "/cli/tests/subdir/xTypeScriptTypesRedirected.d.ts") => { + (_, "/subdir/xTypeScriptTypesRedirected.d.ts") => { let mut res = Response::new(Body::from("export const foo: 'foo';")); res.headers_mut().insert( "Content-type", @@ -702,7 +703,7 @@ async fn main_server(req: Request<Body>) -> hyper::Result<Response<Body>> { ); Ok(res) } - (_, "/cli/tests/subdir/file_with_:_in_name.ts") => { + (_, "/subdir/file_with_:_in_name.ts") => { let mut res = Response::new(Body::from( "console.log('Hello from file_with_:_in_name.ts');", )); @@ -712,7 +713,7 @@ async fn main_server(req: Request<Body>) -> hyper::Result<Response<Body>> { ); Ok(res) } - (_, "/cli/tests/subdir/no_js_ext@1.0.0") => { + (_, "/subdir/no_js_ext@1.0.0") => { let mut res = Response::new(Body::from( r#"import { printHello } from "./mod2.ts"; printHello(); @@ -725,8 +726,8 @@ async fn main_server(req: Request<Body>) -> hyper::Result<Response<Body>> { Ok(res) } (_, "/.well-known/deno-import-intellisense.json") => { - let file_path = root_path() - .join("cli/tests/lsp/registries/deno-import-intellisense.json"); + let file_path = + testdata_path().join("lsp/registries/deno-import-intellisense.json"); if let Ok(body) = tokio::fs::read(file_path).await { Ok(custom_headers( "/.well-known/deno-import-intellisense.json", @@ -737,10 +738,10 @@ async fn main_server(req: Request<Body>) -> hyper::Result<Response<Body>> { } } _ => { - let mut file_path = root_path(); + let mut file_path = testdata_path(); file_path.push(&req.uri().path()[1..]); if let Ok(file) = tokio::fs::read(file_path).await { - let file_resp = custom_headers(&req.uri().path()[1..], file); + let file_resp = custom_headers(req.uri().path(), file); return Ok(file_resp); } @@ -860,12 +861,12 @@ async fn wrap_main_server() { async fn wrap_main_https_server() { let main_server_https_addr = SocketAddr::from(([127, 0, 0, 1], HTTPS_PORT)); - let cert_file = "cli/tests/tls/localhost.crt"; - let key_file = "cli/tests/tls/localhost.key"; - let ca_cert_file = "cli/tests/tls/RootCA.pem"; + let cert_file = "tls/localhost.crt"; + let key_file = "tls/localhost.key"; + let ca_cert_file = "tls/RootCA.pem"; let tls_config = get_tls_config(cert_file, key_file, ca_cert_file) .await - .expect("Cannot get TLS config"); + .unwrap(); loop { let tcp = TcpListener::bind(&main_server_https_addr) .await @@ -957,7 +958,7 @@ pub async fn run_all_servers() { fn custom_headers(p: &str, body: Vec<u8>) -> Response<Body> { let mut response = Response::new(Body::from(body)); - if p.ends_with("cli/tests/x_deno_warning.js") { + if p.ends_with("/x_deno_warning.js") { response.headers_mut().insert( "Content-Type", HeaderValue::from_static("application/javascript"), @@ -967,7 +968,7 @@ fn custom_headers(p: &str, body: Vec<u8>) -> Response<Body> { .insert("X-Deno-Warning", HeaderValue::from_static("foobar")); return response; } - if p.ends_with("cli/tests/053_import_compression/brotli") { + if p.ends_with("/053_import_compression/brotli") { response .headers_mut() .insert("Content-Encoding", HeaderValue::from_static("br")); @@ -980,7 +981,7 @@ fn custom_headers(p: &str, body: Vec<u8>) -> Response<Body> { .insert("Content-Length", HeaderValue::from_static("26")); return response; } - if p.ends_with("cli/tests/053_import_compression/gziped") { + if p.ends_with("/053_import_compression/gziped") { response .headers_mut() .insert("Content-Encoding", HeaderValue::from_static("gzip")); @@ -994,7 +995,7 @@ fn custom_headers(p: &str, body: Vec<u8>) -> Response<Body> { return response; } - if p.contains("cli/tests/encoding/") { + if p.contains("/encoding/") { let charset = p .split_terminator('/') .last() @@ -1069,7 +1070,7 @@ impl HttpServerCount { println!("test_server starting..."); let mut test_server = Command::new(test_server_path()) - .current_dir(root_path()) + .current_dir(testdata_path()) .stdout(Stdio::piped()) .spawn() .expect("failed to execute test_server"); @@ -1251,7 +1252,7 @@ pub fn run_and_collect_output_with_args( let mut deno_process_builder = deno_cmd(); deno_process_builder .args(args) - .current_dir(&tests_path()) + .current_dir(&testdata_path()) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()); @@ -1313,7 +1314,7 @@ pub fn run_powershell_script_file( command .env("DENO_DIR", deno_dir.path()) - .current_dir(root_path()) + .current_dir(testdata_path()) .arg("-file") .arg(script_file_path); @@ -1348,9 +1349,7 @@ pub struct CheckOutputIntegrationTest { impl CheckOutputIntegrationTest { pub fn run(&self) { let args = self.args.split_whitespace(); - let root = root_path(); let deno_exe = deno_exe_path(); - println!("root path {}", root.display()); println!("deno_exe path {}", deno_exe.display()); let _http_server_guard = if self.http_server { @@ -1360,12 +1359,12 @@ impl CheckOutputIntegrationTest { }; let (mut reader, writer) = pipe().unwrap(); - let tests_dir = root.join("cli").join("tests"); + let testdata_dir = testdata_path(); let mut command = deno_cmd(); println!("deno_exe args {}", self.args); - println!("deno_exe tests path {:?}", &tests_dir); + println!("deno_exe testdata path {:?}", &testdata_dir); command.args(args); - command.current_dir(&tests_dir); + command.current_dir(&testdata_dir); command.stdin(Stdio::piped()); let writer_clone = writer.try_clone().unwrap(); command.stderr(writer_clone); @@ -1420,7 +1419,7 @@ impl CheckOutputIntegrationTest { let expected = if let Some(s) = self.output_str { s.to_owned() } else { - let output_path = tests_dir.join(self.output); + let output_path = testdata_dir.join(self.output); println!("output path {}", output_path.display()); std::fs::read_to_string(output_path).expect("cannot read output") }; @@ -1492,7 +1491,7 @@ pub fn pattern_match(pattern: &str, s: &str, wildcard: &str) -> bool { pub fn test_pty(args: &str, output_path: &str, input: &[u8]) { use pty::fork::Fork; - let tests_path = tests_path(); + let tests_path = testdata_path(); let fork = Fork::from_ptmx().unwrap(); if let Ok(mut master) = fork.is_parent() { let mut output_actual = String::new(); |