testserver

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package testserver configures and creates a Fleetspeak server instance suitable for unit tests. It also provides utility methods for directly adjusting the server state in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeCommunicator

type FakeCommunicator struct {
	Dest *Server
}

FakeCommunicator implements comms.Communicator to do nothing by save the comms.Context to a Server. Most users should simply call Make, but this is exposed in order to support more flexible setup of test servers.

func (FakeCommunicator) Setup

func (c FakeCommunicator) Setup(cc comms.Context) error

func (FakeCommunicator) Start

func (c FakeCommunicator) Start() error

func (FakeCommunicator) Stop

func (c FakeCommunicator) Stop()

type Server

type Server struct {
	S  *server.Server
	DS *sqlite.Datastore
	CC comms.Context
}

Server is a test server, with related structures and interfaces to allow tests to manipulate it.

func Make

func Make(t *testing.T, testName, caseName string, comms []comms.Communicator) Server

Make creates a server.Server using the provided communicators. It creates and attaches it to an sqlite datastore based on the test and test case names.

func MakeWithService

func MakeWithService(t *testing.T, testName, caseName string, serviceInstance service.Service) Server

MakeWithService creates a server.Server using the provided service. Like in Make(), a sqlite datastore is created for the provided test-case.

func (Server) AddClient

func (s Server) AddClient() (crypto.PublicKey, error)

AddClient adds a new client with a random id to a server.

func (Server) GetMessage

func (s Server) GetMessage(ctx context.Context, id common.MessageID) *fspb.Message

GetMessage retrieves a single message from the datastore, or dies trying.

func (Server) ProcessMessageFromClient

func (s Server) ProcessMessageFromClient(k crypto.PublicKey, msg *fspb.Message) error

ProcessMessageFromClient delivers a message to a server, simulating that it was provided by a client. It then waits up to 30 seconds for it to be processed.

func (Server) SimulateContactFromClient

func (s Server) SimulateContactFromClient(ctx context.Context, key crypto.PublicKey, msgs []*fspb.Message) ([]*fspb.Message, error)

SimulateContactFromClient accepts zero or more messages as if they came from a client, and returns any messages pending for delivery to the client.

Jump to

Keyboard shortcuts

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