Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wasi-http/tests/all/p2/async_.rs
3141 views
1
use super::*;
2
use test_programs_artifacts::*;
3
use wasmtime_wasi::p2::bindings::Command;
4
5
foreach_p2_http!(assert_test_exists);
6
7
async fn run(path: &str, server: &Server) -> Result<()> {
8
let engine = test_programs_artifacts::engine(|config| {
9
config.wasm_backtrace_details(wasmtime::WasmBacktraceDetails::Enable);
10
});
11
let component = Component::from_file(&engine, path)?;
12
let mut store = store(&engine, server);
13
let mut linker = Linker::new(&engine);
14
wasmtime_wasi::p2::add_to_linker_async(&mut linker)?;
15
wasmtime_wasi_http::add_only_http_to_linker_async(&mut linker)?;
16
let command = Command::instantiate_async(&mut store, &component, &linker).await?;
17
let result = command.wasi_cli_run().call_run(&mut store).await?;
18
result.map_err(|()| wasmtime::format_err!("run returned an error"))
19
}
20
21
#[test_log::test(tokio::test(flavor = "multi_thread"))]
22
async fn p2_http_outbound_request_get() -> Result<()> {
23
let server = Server::http1(1)?;
24
run(P2_HTTP_OUTBOUND_REQUEST_GET_COMPONENT, &server).await
25
}
26
27
#[test_log::test(tokio::test(flavor = "multi_thread"))]
28
async fn p2_http_outbound_request_timeout() -> Result<()> {
29
let server = Server::http1(1)?;
30
run(P2_HTTP_OUTBOUND_REQUEST_TIMEOUT_COMPONENT, &server).await
31
}
32
33
#[test_log::test(tokio::test(flavor = "multi_thread"))]
34
async fn p2_http_outbound_request_post() -> Result<()> {
35
let server = Server::http1(1)?;
36
run(P2_HTTP_OUTBOUND_REQUEST_POST_COMPONENT, &server).await
37
}
38
39
#[test_log::test(tokio::test(flavor = "multi_thread"))]
40
async fn p2_http_outbound_request_large_post() -> Result<()> {
41
let server = Server::http1(1)?;
42
run(P2_HTTP_OUTBOUND_REQUEST_LARGE_POST_COMPONENT, &server).await
43
}
44
45
#[test_log::test(tokio::test(flavor = "multi_thread"))]
46
async fn p2_http_outbound_request_put() -> Result<()> {
47
let server = Server::http1(1)?;
48
run(P2_HTTP_OUTBOUND_REQUEST_PUT_COMPONENT, &server).await
49
}
50
51
#[test_log::test(tokio::test(flavor = "multi_thread"))]
52
async fn p2_http_outbound_request_invalid_version() -> Result<()> {
53
let server = Server::http2(1)?;
54
run(P2_HTTP_OUTBOUND_REQUEST_INVALID_VERSION_COMPONENT, &server).await
55
}
56
57
#[test_log::test(tokio::test(flavor = "multi_thread"))]
58
async fn p2_http_outbound_request_invalid_header() -> Result<()> {
59
let server = Server::http2(1)?;
60
run(P2_HTTP_OUTBOUND_REQUEST_INVALID_HEADER_COMPONENT, &server).await
61
}
62
63
#[test_log::test(tokio::test(flavor = "multi_thread"))]
64
async fn p2_http_outbound_request_unknown_method() -> Result<()> {
65
let server = Server::http1(1)?;
66
run(P2_HTTP_OUTBOUND_REQUEST_UNKNOWN_METHOD_COMPONENT, &server).await
67
}
68
69
#[test_log::test(tokio::test(flavor = "multi_thread"))]
70
async fn p2_http_outbound_request_unsupported_scheme() -> Result<()> {
71
let server = Server::http1(1)?;
72
run(
73
P2_HTTP_OUTBOUND_REQUEST_UNSUPPORTED_SCHEME_COMPONENT,
74
&server,
75
)
76
.await
77
}
78
79
#[test_log::test(tokio::test(flavor = "multi_thread"))]
80
async fn p2_http_outbound_request_invalid_port() -> Result<()> {
81
let server = Server::http1(1)?;
82
run(P2_HTTP_OUTBOUND_REQUEST_INVALID_PORT_COMPONENT, &server).await
83
}
84
85
#[test_log::test(tokio::test(flavor = "multi_thread"))]
86
async fn p2_http_outbound_request_invalid_dnsname() -> Result<()> {
87
let server = Server::http1(1)?;
88
run(P2_HTTP_OUTBOUND_REQUEST_INVALID_DNSNAME_COMPONENT, &server).await
89
}
90
91
#[test_log::test(tokio::test(flavor = "multi_thread"))]
92
async fn p2_http_outbound_request_response_build() -> Result<()> {
93
let server = Server::http1(1)?;
94
run(P2_HTTP_OUTBOUND_REQUEST_RESPONSE_BUILD_COMPONENT, &server).await
95
}
96
97
#[test_log::test(tokio::test(flavor = "multi_thread"))]
98
async fn p2_http_outbound_request_content_length() -> Result<()> {
99
let server = Server::http1(1)?;
100
run(P2_HTTP_OUTBOUND_REQUEST_CONTENT_LENGTH_COMPONENT, &server).await
101
}
102
103
#[test_log::test(tokio::test(flavor = "multi_thread"))]
104
async fn p2_http_outbound_request_missing_path_and_query() -> Result<()> {
105
let server = Server::http1(1)?;
106
run(
107
P2_HTTP_OUTBOUND_REQUEST_MISSING_PATH_AND_QUERY_COMPONENT,
108
&server,
109
)
110
.await
111
}
112
113