Path: blob/main/crates/wasi-tls-openssl/tests/main.rs
3090 views
use wasmtime::{1Result, Store,2component::{Component, Linker, ResourceTable},3format_err,4};5use wasmtime_wasi::{WasiCtx, WasiCtxView, WasiView, p2::bindings::Command};6use wasmtime_wasi_tls::{LinkOptions, WasiTls, WasiTlsCtx, WasiTlsCtxBuilder};78struct Ctx {9table: ResourceTable,10wasi_ctx: WasiCtx,11wasi_tls_ctx: WasiTlsCtx,12}1314impl WasiView for Ctx {15fn ctx(&mut self) -> WasiCtxView<'_> {16WasiCtxView {17ctx: &mut self.wasi_ctx,18table: &mut self.table,19}20}21}2223async fn run_test(path: &str) -> Result<()> {24let provider = Box::new(wasmtime_wasi_tls_openssl::OpenSslProvider::default());25let ctx = Ctx {26table: ResourceTable::new(),27wasi_ctx: WasiCtx::builder()28.inherit_stderr()29.inherit_network()30.allow_ip_name_lookup(true)31.build(),32wasi_tls_ctx: WasiTlsCtxBuilder::new().provider(provider).build(),33};3435let engine = test_programs_artifacts::engine(|_config| {});36let mut store = Store::new(&engine, ctx);37let component = Component::from_file(&engine, path)?;3839let mut linker = Linker::new(&engine);40wasmtime_wasi::p2::add_to_linker_async(&mut linker)?;41let mut opts = LinkOptions::default();42opts.tls(true);43wasmtime_wasi_tls::add_to_linker(&mut linker, &mut opts, |h: &mut Ctx| {44WasiTls::new(&h.wasi_tls_ctx, &mut h.table)45})?;4647let command = Command::instantiate_async(&mut store, &component, &linker).await?;48command49.wasi_cli_run()50.call_run(&mut store)51.await?52.map_err(|()| format_err!("command returned with failing exit status"))53}5455macro_rules! assert_test_exists {56($name:ident) => {57#[expect(unused_imports, reason = "just here to assert it exists")]58use self::$name as _;59};60}6162test_programs_artifacts::foreach_tls!(assert_test_exists);6364#[tokio::test(flavor = "multi_thread")]65async fn tls_sample_application() -> Result<()> {66run_test(test_programs_artifacts::TLS_SAMPLE_APPLICATION_COMPONENT).await67}686970