Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
serverhiccups committed Jan 21, 2020
1 parent b4f13e2 commit f737a75
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
36 changes: 34 additions & 2 deletions cli/js/fetch_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {
fail
} from "./test_util.ts";

import {
Response
} from "./fetch.ts";

testPerm({ net: true }, async function fetchConnectionError(): Promise<void> {
let err;
try {
Expand Down Expand Up @@ -362,7 +366,7 @@ testPerm({ net: true }, async function fetchPostBodyTypedArray():Promise<void> {
});
*/

testPerm({ net: true }, async function fetchWithRedirection(): Promise<void> {
testPerm({ net: true }, async function fetchWithManualRedirection(): Promise<void> {
const response = await fetch("http://localhost:4546/", {
redirect: "manual"
}); // will redirect to http://localhost:4545/
Expand All @@ -373,9 +377,37 @@ testPerm({ net: true }, async function fetchWithRedirection(): Promise<void> {
try {
await response.text();
fail(
"Reponse.text() on a filtered response without a body (opaqueredirect)"
"Reponse.text() didn't throw on a filtered response without a body (type opaqueredirect)"
);
} catch (e) {
return;
}
});

testPerm({ net: true }, async function fetchWithErrorRedirection(): Promise<void> {
const response = await fetch("http://localhost:4546/", {
redirect: "error"
}); // will redirect to http://localhost:4545/
assertEquals(response.status, 0);
assertEquals(response.statusText, "");
assertEquals(response.url, "");
assertEquals(response.type, "error");
try {
await response.text();
fail(
"Reponse.text() didn't on a filtered response without a body (type error)"
);
} catch (e) {
return;
}
});

test(function responseRedirect(): void {
const response = new Response("example.com/beforeredirect", 200, "OK", [["This-Should", "Disappear"]], -1, false, null);
const redir = response.redirect("example.com/newLocation", 301);
assertEquals(redir.status, 0);
assertEquals(redir.statusText, "");
assertEquals(redir.url, "");
assertEquals(redir.headers.get("Location"), "example.com/newLocation");
assertEquals(redir.type, "default");
});
4 changes: 2 additions & 2 deletions tools/hyper_hello/hyper_hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
// `service_fn` is a helper to convert a function that
// returns a Response into a `Service`.
async {
Just::Ok(service_fn(|_req| {
async { Just::Ok(Response::new(Body::from(&b"Hello World!"[..]))) }
Just::Ok(service_fn(|_req| async {
Just::Ok(Response::new(Body::from(&b"Hello World!"[..])))
}))
}
});
Expand Down

0 comments on commit f737a75

Please sign in to comment.