Crate wasmcloud_test_util

source
Expand description

This crate contains utilities for testing wasmCloud, a universal application platform powered by WebAssembly.

You can use this crate to start the wasmCloud host, test both wasmCloud 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:

use wasmcloud_test_util::{assert_config_put, assert_scale_component, WasmCloudTestHost};
use wasmcloud_test_util::control_interface::ClientBuilder;


// 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(),
)
.await?;

// ...

Ok(())

You can find examples of this crate in use in the wasmCloud repository tests folder.

Re-exports§

Modules§

  • Component management utilities for use during testing
  • Utilities for managing wasmCloud hosts locally or remotely via the lattice
  • Utilities for lattice management during testing
  • Provider management utilities for use during testing