Skip to content

Commit

Permalink
Merge std_tests.rs into integration_tests.rs.rs (denoland#5228)
Browse files Browse the repository at this point in the history
* Remove usage of url_to_filename from integration_tests
* Make test ports not conflict with each other
  • Loading branch information
ry committed May 11, 2020
1 parent b2da8f3 commit fb7d7f4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 83 deletions.
30 changes: 15 additions & 15 deletions cli/js/tests/net_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand All @@ -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();
}
);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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" });
Expand All @@ -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]);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions cli/js/tests/tls_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
Expand Down Expand Up @@ -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",
});
Expand All @@ -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",
};
Expand Down Expand Up @@ -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",
};
Expand Down Expand Up @@ -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,
Expand Down
62 changes: 29 additions & 33 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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:https://localhost:4545/cli/tests/006_url_imports.ts").unwrap();

let output = Command::new(deno_exe_path())
url::Url::parse("http:https://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);
}

Expand Down Expand Up @@ -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:https://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")
Expand All @@ -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);
}

Expand Down
30 changes: 0 additions & 30 deletions cli/tests/std_tests.rs

This file was deleted.

0 comments on commit fb7d7f4

Please sign in to comment.