1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

Merge std_tests.rs into integration_tests.rs.rs (#5228)

* Remove usage of url_to_filename from integration_tests
* Make test ports not conflict with each other
This commit is contained in:
Ryan Dahl 2020-05-11 14:49:19 -04:00 committed by GitHub
parent b2da8f3d4e
commit fb7d7f40ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 83 deletions

View file

@ -7,10 +7,10 @@ import {
} from "./test_util.ts";
unitTest({ perms: { net: true } }, function netTcpListenClose(): void {
const listener = Deno.listen({ hostname: "127.0.0.1", port: 4500 });
const listener = Deno.listen({ hostname: "127.0.0.1", port: 3500 });
assert(listener.addr.transport === "tcp");
assertEquals(listener.addr.hostname, "127.0.0.1");
assertEquals(listener.addr.port, 4500);
assertEquals(listener.addr.port, 3500);
listener.close();
});
@ -23,12 +23,12 @@ unitTest(
function netUdpListenClose(): void {
const socket = Deno.listenDatagram({
hostname: "127.0.0.1",
port: 4500,
port: 3500,
transport: "udp",
});
assert(socket.addr.transport === "udp");
assertEquals(socket.addr.hostname, "127.0.0.1");
assertEquals(socket.addr.port, 4500);
assertEquals(socket.addr.port, 3500);
socket.close();
}
);
@ -154,22 +154,22 @@ unitTest(
unitTest({ perms: { net: true } }, async function netTcpDialListen(): Promise<
void
> {
const listener = Deno.listen({ port: 4500 });
const listener = Deno.listen({ port: 3500 });
listener.accept().then(
async (conn): Promise<void> => {
assert(conn.remoteAddr != null);
assert(conn.localAddr.transport === "tcp");
assertEquals(conn.localAddr.hostname, "127.0.0.1");
assertEquals(conn.localAddr.port, 4500);
assertEquals(conn.localAddr.port, 3500);
await conn.write(new Uint8Array([1, 2, 3]));
conn.close();
}
);
const conn = await Deno.connect({ hostname: "127.0.0.1", port: 4500 });
const conn = await Deno.connect({ hostname: "127.0.0.1", port: 3500 });
assert(conn.remoteAddr.transport === "tcp");
assertEquals(conn.remoteAddr.hostname, "127.0.0.1");
assertEquals(conn.remoteAddr.port, 4500);
assertEquals(conn.remoteAddr.port, 3500);
assert(conn.localAddr != null);
const buf = new Uint8Array(1024);
const readResult = await conn.read(buf);
@ -227,9 +227,9 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { net: true } },
async function netUdpSendReceive(): Promise<void> {
const alice = Deno.listenDatagram({ port: 4500, transport: "udp" });
const alice = Deno.listenDatagram({ port: 3500, transport: "udp" });
assert(alice.addr.transport === "udp");
assertEquals(alice.addr.port, 4500);
assertEquals(alice.addr.port, 3500);
assertEquals(alice.addr.hostname, "127.0.0.1");
const bob = Deno.listenDatagram({ port: 4501, transport: "udp" });
@ -242,7 +242,7 @@ unitTest(
const [recvd, remote] = await bob.receive();
assert(remote.transport === "udp");
assertEquals(remote.port, 4500);
assertEquals(remote.port, 3500);
assertEquals(recvd.length, 3);
assertEquals(1, recvd[0]);
assertEquals(2, recvd[1]);
@ -385,7 +385,7 @@ unitTest(
perms: { net: true },
},
async function netListenAsyncIterator(): Promise<void> {
const addr = { hostname: "127.0.0.1", port: 4500 };
const addr = { hostname: "127.0.0.1", port: 3500 };
const listener = Deno.listen(addr);
const runAsyncIterator = async (): Promise<void> => {
for await (const conn of listener) {
@ -420,7 +420,7 @@ unitTest(
perms: { net: true },
},
async function netCloseWriteSuccess() {
const addr = { hostname: "127.0.0.1", port: 4500 };
const addr = { hostname: "127.0.0.1", port: 3500 };
const listener = Deno.listen(addr);
const closeDeferred = createResolvable();
listener.accept().then(async (conn) => {
@ -459,7 +459,7 @@ unitTest(
perms: { net: true },
},
async function netDoubleCloseWrite() {
const addr = { hostname: "127.0.0.1", port: 4500 };
const addr = { hostname: "127.0.0.1", port: 3500 };
const listener = Deno.listen(addr);
const closeDeferred = createResolvable();
listener.accept().then(async (conn) => {
@ -512,7 +512,7 @@ unitTest(
resolvable.resolve();
}
const addr = { hostname: "127.0.0.1", port: 4500 };
const addr = { hostname: "127.0.0.1", port: 3500 };
const listener = Deno.listen(addr);
iteratorReq(listener);
const conn = await Deno.connect(addr);

View file

@ -43,7 +43,7 @@ unitTest(
let err;
const options = {
hostname: "localhost",
port: 4500,
port: 3500,
certFile: "cli/tests/tls/localhost.crt",
keyFile: "cli/tests/tls/localhost.key",
};
@ -75,7 +75,7 @@ unitTest({ perms: { net: true } }, function listenTLSNoReadPerm(): void {
try {
Deno.listenTls({
hostname: "localhost",
port: 4500,
port: 3500,
certFile: "cli/tests/tls/localhost.crt",
keyFile: "cli/tests/tls/localhost.key",
});
@ -94,7 +94,7 @@ unitTest(
let err;
const options = {
hostname: "localhost",
port: 4500,
port: 3500,
certFile: "cli/tests/tls/localhost.crt",
keyFile: "cli/tests/tls/localhost.key",
};
@ -123,7 +123,7 @@ unitTest(
let err;
const options = {
hostname: "localhost",
port: 4500,
port: 3500,
certFile: "cli/tests/tls/localhost.crt",
keyFile: "cli/tests/tls/localhost.key",
};
@ -151,7 +151,7 @@ unitTest(
async function dialAndListenTLS(): Promise<void> {
const resolvable = createResolvable();
const hostname = "localhost";
const port = 4500;
const port = 3500;
const listener = Deno.listenTls({
hostname,

View file

@ -12,6 +12,27 @@ use std::io::BufRead;
use std::process::Command;
use tempfile::TempDir;
#[test]
fn std_tests() {
let dir = TempDir::new().expect("tempdir fail");
let mut deno_cmd = Command::new(util::deno_exe_path());
deno_cmd.env("DENO_DIR", dir.path());
let mut cwd = util::root_path();
cwd.push("std");
let mut deno = deno_cmd
.current_dir(cwd) // note: std tests expect to run from "std" dir
.arg("test")
.arg("--unstable")
.arg("--seed=86") // Some tests rely on specific random numbers.
.arg("-A")
// .arg("-Ldebug")
.spawn()
.expect("failed to spawn script");
let status = deno.wait().expect("failed to wait for the child process");
assert!(status.success());
}
#[test]
fn x_deno_warning() {
let g = util::http_server();
@ -134,35 +155,24 @@ fn deno_dir_test() {
}
#[test]
fn fetch_test() {
use deno::http_cache::url_to_filename;
pub use deno::test_util::*;
use url::Url;
fn cache_test() {
let g = util::http_server();
let deno_dir = TempDir::new().expect("tempdir fail");
let module_url =
Url::parse("http://localhost:4545/cli/tests/006_url_imports.ts").unwrap();
let output = Command::new(deno_exe_path())
url::Url::parse("http://localhost:4545/cli/tests/006_url_imports.ts")
.unwrap();
let output = Command::new(util::deno_exe_path())
.env("DENO_DIR", deno_dir.path())
.current_dir(util::root_path())
.arg("cache")
.arg(module_url.to_string())
.output()
.expect("Failed to spawn script");
assert!(output.status.success());
let out = std::str::from_utf8(&output.stdout).unwrap();
assert_eq!(out, "");
let expected_path = deno_dir
.path()
.join("deps")
.join(url_to_filename(&module_url));
assert_eq!(expected_path.exists(), true);
// TODO(ry) Is there some way to check that the file was actually cached in
// DENO_DIR?
drop(g);
}
@ -1696,18 +1706,14 @@ itest!(proto_exploit {
#[test]
fn cafile_fetch() {
use deno::http_cache::url_to_filename;
pub use deno::test_util::*;
use url::Url;
let g = util::http_server();
let deno_dir = TempDir::new().expect("tempdir fail");
let module_url =
Url::parse("http://localhost:4545/cli/tests/cafile_url_imports.ts")
.unwrap();
let cafile = util::root_path().join("cli/tests/tls/RootCA.pem");
let output = Command::new(deno_exe_path())
let output = Command::new(util::deno_exe_path())
.env("DENO_DIR", deno_dir.path())
.current_dir(util::root_path())
.arg("cache")
@ -1716,19 +1722,9 @@ fn cafile_fetch() {
.arg(module_url.to_string())
.output()
.expect("Failed to spawn script");
let code = output.status.code();
assert!(output.status.success());
let out = std::str::from_utf8(&output.stdout).unwrap();
assert_eq!(Some(0), code);
assert_eq!(out, "");
let expected_path = deno_dir
.path()
.join("deps")
.join(url_to_filename(&module_url));
assert_eq!(expected_path.exists(), true);
drop(g);
}

View file

@ -1,30 +0,0 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
mod tests {
extern crate lazy_static;
extern crate tempfile;
use deno::test_util::*;
use std::process::Command;
use tempfile::TempDir;
#[test]
fn std_tests() {
let dir = TempDir::new().expect("tempdir fail");
let mut deno_cmd = Command::new(deno_exe_path());
deno_cmd.env("DENO_DIR", dir.path());
let mut cwd = root_path();
cwd.push("std");
let mut deno = deno_cmd
.current_dir(cwd) // note: std tests expect to run from "std" dir
.arg("test")
.arg("--unstable")
.arg("--seed=86") // Some tests rely on specific random numbers.
.arg("-A")
// .arg("-Ldebug")
.spawn()
.expect("failed to spawn script");
let status = deno.wait().expect("failed to wait for the child process");
assert!(status.success());
}
}