Skip to main content

create_nats_account_for_test

Function create_nats_account_for_test 

Source
pub async fn create_nats_account_for_test(
    url: &str,
) -> Result<NatsCredentials, Box<dyn Error>>
Expand description

Creates a new NATS account to ensure that unit tests can run concurrently without interfering with each other.

It is assumed that the server is started using the provided nats-server-test.conf

The following stuff is set up:

  • an account is created and signed with the operator’s private key. The account is the entity representing the namespace / tenant.
  • a connection to NATS is established and authenticated using the system user
  • the account is then registered with the server (by publishing to a special topic)
  • a user is created and signed with the account’s private key
  • a JWT is created and signed with the user’s private key
  • a new connection to NATS is established and authenticated using the newly created JWT