1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
use super::*;
use test_programs_artifacts::*;
use wasmtime_wasi::bindings::Command;
foreach_http!(assert_test_exists);
async fn run(path: &str, server: &Server) -> Result<()> {
let engine = test_programs_artifacts::engine(|config| {
config.wasm_backtrace_details(wasmtime::WasmBacktraceDetails::Enable);
config.async_support(true);
});
let component = Component::from_file(&engine, path)?;
let mut store = store(&engine, server);
let mut linker = Linker::new(&engine);
wasmtime_wasi::add_to_linker_async(&mut linker)?;
wasmtime_wasi_http::add_only_http_to_linker_async(&mut linker)?;
let command = Command::instantiate_async(&mut store, &component, &linker).await?;
let result = command.wasi_cli_run().call_run(&mut store).await?;
result.map_err(|()| anyhow::anyhow!("run returned an error"))
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_get() -> Result<()> {
let server = Server::http1()?;
run(HTTP_OUTBOUND_REQUEST_GET_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_timeout() -> Result<()> {
let server = Server::http1()?;
run(HTTP_OUTBOUND_REQUEST_TIMEOUT_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_post() -> Result<()> {
let server = Server::http1()?;
run(HTTP_OUTBOUND_REQUEST_POST_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_large_post() -> Result<()> {
let server = Server::http1()?;
run(HTTP_OUTBOUND_REQUEST_LARGE_POST_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_put() -> Result<()> {
let server = Server::http1()?;
run(HTTP_OUTBOUND_REQUEST_PUT_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_invalid_version() -> Result<()> {
let server = Server::http2()?;
run(HTTP_OUTBOUND_REQUEST_INVALID_VERSION_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_invalid_header() -> Result<()> {
let server = Server::http2()?;
run(HTTP_OUTBOUND_REQUEST_INVALID_HEADER_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_unknown_method() -> Result<()> {
let server = Server::http1()?;
run(HTTP_OUTBOUND_REQUEST_UNKNOWN_METHOD_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_unsupported_scheme() -> Result<()> {
let server = Server::http1()?;
run(HTTP_OUTBOUND_REQUEST_UNSUPPORTED_SCHEME_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_invalid_port() -> Result<()> {
let server = Server::http1()?;
run(HTTP_OUTBOUND_REQUEST_INVALID_PORT_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_invalid_dnsname() -> Result<()> {
let server = Server::http1()?;
run(HTTP_OUTBOUND_REQUEST_INVALID_DNSNAME_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_response_build() -> Result<()> {
let server = Server::http1()?;
run(HTTP_OUTBOUND_REQUEST_RESPONSE_BUILD_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_content_length() -> Result<()> {
let server = Server::http1()?;
run(HTTP_OUTBOUND_REQUEST_CONTENT_LENGTH_COMPONENT, &server).await
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn http_outbound_request_missing_path_and_query() -> Result<()> {
let server = Server::http1()?;
run(
HTTP_OUTBOUND_REQUEST_MISSING_PATH_AND_QUERY_COMPONENT,
&server,
)
.await
}
|