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
//! This crate contains utilities for testing [wasmCloud][wasmCloud], a universal application platform powered by [WebAssembly][wasm].
//!
//! You can use this crate to start the wasmCloud host, test both wasmCloud [components][docs-components] and [capability providers][docs-provider]s, and more.
//!
//! ## Quickstart
//!
//! When building integration tests, you can start the wasmCloud host without `wash` and directly from Rust code to test it:
//!
//! ```rust,ignore
//! use tokio::time::Duration;
//! use wasmcloud_test_util::{assert_config_put, assert_scale_component, WasmCloudTestHost};
//! use wasmcloud_test_util::control_interface::ClientBuilder;
//!
//! # async fn quickstart() -> anyhow::Result<()> {
//!
//! // Build a wasmCloud host (assuming you have a local NATS server running)
//! let nats_url = "nats://localhost:4222";
//! let lattice = "default";
//! let host = WasmCloudTestHost::start(nats_url, lattice).await?;
//!
//! // Once you have a host (AKA a single-member wasmCloud lattice), you'll want a NATS client
//! // which you can use to control the host and the lattice:
//! let nats_client = async_nats::connect(nats_url).await?;
//! let ctl_client = ClientBuilder::new(nats_client)
//! .lattice(host.lattice_name().to_string())
//! .build();
//!
//! // Now that you have a control client, you can use the `assert_*` functions to perform actions on your host:
//! assert_config_put(
//! &ctl_client,
//! "test-config",
//! [("EXAMPLE_KEY".to_string(), "EXAMPLE_VALUE".to_string())],
//! )
//! .await?;
//!
//! assert_scale_component(
//! &ctl_client,
//! &host.host_key(),
//! "ghcr.io/wasmcloud/components/http-jsonify-rust:0.1.1",
//! "example-component",
//! None,
//! 1,
//! Vec::new(),
//! Duration::from_secs(10),
//! )
//! .await?;
//!
//! // ...
//!
//! Ok(())
//! # }
//! ```
//!
//! You can find examples of this crate in use in the [wasmCloud repository `tests` folder](https://github.com/wasmCloud/wasmCloud/tree/main/tests).
//!
//! [wasmCloud]: https://wasmcloud.com
//! [wasm]: https://webassembly.org/
//! [docs-providers]: https://wasmcloud.com/docs/concepts/providers
//! [docs-components]: https://wasmcloud.com/docs/concepts/components
//!
/// Re-export of control interface for use
pub use wasmcloud_control_interface as control_interface;
pub use crateassert_scale_component;
pub use crateWasmCloudTestHost;
pub use crate;
pub use crateassert_config_put;
pub use crateassert_start_provider;