testenv

package
v0.0.0-...-147f0cf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartMqttTestServer

func StartMqttTestServer() (
	msgServer msgserver.IMsgServer,
	certBundle certs.TestCertBundle,
	err error)

StartMqttTestServer creates a MQTT test server.

func StartNatsTestServer

func StartNatsTestServer(withCallout bool) (
	hubNatsServer *service.NatsMsgServer,
	certBundle certs.TestCertBundle,
	config *natsmsgserver.NatsServerConfig,
	err error)

StartNatsTestServer generate a test configuration and starts a NKeys based nats test server A new temporary storage directory is used.

Types

type TestServer

type TestServer struct {
	Core        string
	CertBundle  certs.TestCertBundle
	MsgServer   msgserver.IMsgServer
	AuthService *authservice.AuthService
	// contains filtered or unexported fields
}

TestServer for testing application services This server provides an easy way to connect to the server by automatically creating a user and auth token when using ConnectInProc.

func StartTestServer

func StartTestServer(core string, withAuth bool) (*TestServer, error)

StartTestServer creates a NATS or MQTT test server depending on the requested type core is either "nats", or "mqtt" (default) This generates a certificate bundle for running the server, including a self signed CA.

Use Stop() to clean up. Use withAuth or run StartAuth() to start the auth service

func (*TestServer) AddClients

func (ts *TestServer) AddClients(newClients []msgserver.ClientAuthInfo) error

AddClients adds test clients to the server. This either adds them to the server directly or adds them using auth.

func (*TestServer) AddConnectClient

func (ts *TestServer) AddConnectClient(
	agentID string, clientType string, clientRole string) (*hubclient.HubClient, error)

AddConnectClient to the hub as a client type using the given clientID. This generates a key pair and auth token used to connect. Intended for easily connecting during tests to avoid a lot of auth boilerplate.

If auth has started using the TestServer then this adds the client to auth service as a service. Don't use this method if auth is started separately. Use auth directly instead.

Without auth service this applies it to the messaging server directly adding to what was set using AddClients() (don't use ApplyAuth on the message server directly)

agentID the connecting agent is required
clientType is optional. This defaults to ClientTypeUser.
clientRole is optional. This defaults to viewer.

func (*TestServer) StartAuth

func (ts *TestServer) StartAuth() (err error)

StartAuth starts the auth service

func (*TestServer) Stop

func (ts *TestServer) Stop()

Stop the test server and optionally the auth service

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL