wash_runtime/
lib.rs

1#![doc = include_str!("../README.md")]
2
3pub mod engine;
4pub mod host;
5pub mod plugin;
6pub mod types;
7pub mod wit;
8
9#[cfg(feature = "oci")]
10pub mod oci;
11
12// Re-export wasmtime for convenience
13pub use wasmtime;
14
15// TODO: Go to the complicated things and write doctests + show usage.
16
17#[cfg(test)]
18mod test {
19    use std::collections::HashMap;
20    use std::sync::Arc;
21
22    use crate::plugin::wasi_config::RuntimeConfig;
23    use crate::plugin::wasi_http::HttpServer;
24    use crate::{
25        host::HostApi,
26        types::{Workload, WorkloadStartRequest},
27    };
28
29    use super::{engine::Engine, host::HostBuilder};
30
31    #[tokio::test]
32    #[cfg(feature = "wasi-http")]
33    async fn can_run_engine() -> anyhow::Result<()> {
34        let engine = Engine::builder().build()?;
35        let http_plugin = HttpServer::new("127.0.0.1:8080".parse()?);
36        let runtime_config_plugin = RuntimeConfig::default();
37
38        let host = HostBuilder::new()
39            .with_engine(engine)
40            .with_plugin(Arc::new(http_plugin))?
41            .with_plugin(Arc::new(runtime_config_plugin))?
42            .build()?;
43
44        let host = host.start().await?;
45
46        let req = WorkloadStartRequest {
47            workload: Workload {
48                namespace: "test".to_string(),
49                name: "test-workload".to_string(),
50                annotations: HashMap::new(),
51                service: None,
52                components: vec![],
53                host_interfaces: vec![],
54                volumes: vec![],
55            },
56        };
57        let _res = host.workload_start(req).await?;
58
59        Ok(())
60    }
61}