Skip to main content

Crate watermelon_testkit

Crate watermelon_testkit 

Source
Expand description

Run tests against isolated, disposable nats-server instances

Every test gets its own NatsServer, bound to random ports on 127.0.0.1 and backed by a private temporary directory, so tests can run in parallel without sharing any state.

use watermelon_testkit::NatsServer;

let Some(server) = NatsServer::builder().jetstream().start().await else {
    // nats-server isn't installed: skip the test
    return;
};
println!("connect to {}", server.client_url());

§Locating nats-server

The binary is taken from the NATS_SERVER_BIN environment variable when it points to an existing file, otherwise it’s looked up in PATH.

When no binary can be found NatsServerBuilder::start returns None, so that the test can be skipped. If the CI environment variable is set it panics instead, so that a misconfigured CI can’t silently skip tests.

§Debugging failures

The server runs with trace logging enabled. When a test panics while a NatsServer is alive, the tail of the server log is printed and the server’s temporary directory, containing the configuration and the full log, is kept.

Structs§

NatsServer
A nats-server process owned by a single test
NatsServerBuilder
Configuration for a NatsServer

Traits§

TimeoutExt
Bound how long a test is willing to wait on a future

Functions§

eventually
Poll condition until it returns true, panicking after timeout