sertesting

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: 8 Imported by: 0

Documentation

Overview

Package sertesting contains utilities useful for testing the fleetspeak server and server components.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetClientCacheMaxAge

func SetClientCacheMaxAge(d time.Duration) func()

SetClientCacheMaxAge adjusts the maximum age that cached client data is considered valid for. This can be used to make tests run faster.

func SetClientRetryTime

func SetClientRetryTime(f func() time.Time) func()

SetClientRetryTime changes db.ClientRetryTime method used by datastores to decide when to retry requests to clients. It returns a closure which returns the system to the previous state.

This function and the returned closure are not thread safe. In particular, they should be called at the start and end of tests when no Fleetspeak component is started.

func SetServerRetryTime

func SetServerRetryTime(f func(uint32) time.Time) func()

SetServerRetryTime changes the db.ServerRetryTime used by the Fleetspeak server to decide when to retry requests to clients. It returns a closure which returns the system to the previous state.

This function and the returned closure are not thread safe. In particular, they should be called at the start and end of tests when no Fleetspeak component is started.

Types

type FakeContext

type FakeContext struct {
	SentMessages chan *fspb.Message
	ClientData   map[common.ClientID]*db.ClientData
}

A FakeContext is a fake service.Context, suitable for unit testing services.

func (*FakeContext) GetClientData

func (c *FakeContext) GetClientData(_ context.Context, id common.ClientID) (*db.ClientData, error)

func (*FakeContext) Send

func (c *FakeContext) Send(ctx context.Context, m *fspb.Message) error

type FakeTime

type FakeTime struct {
	// contains filtered or unexported fields
}

FakeTime represents a fake time which can control the time seen by the fleetspeak system during unit tests.

func FakeNow

func FakeNow(start int64) *FakeTime

FakeNow changes the implementation of Now used by the fleetspeak system. It returns a FakeTime which controls the time that the system sees until Revert is called.

Note that this function, and FakeTime.Revert are not thread safe. In particular it they should be called at the start and end of tests when no Fleetspeak component is started.

func (*FakeTime) AddSeconds

func (t *FakeTime) AddSeconds(s int64)

AddSeconds adds s seconds to the fake time.

func (*FakeTime) Get

func (t *FakeTime) Get() time.Time

Get returns the current fake time.

func (*FakeTime) Revert

func (t *FakeTime) Revert()

Revert returns the time seen by the fleetspeak system to what it was previously.

func (*FakeTime) SetSeconds

func (t *FakeTime) SetSeconds(s int64)

SetSeconds sets the current fake time to s seconds since epoch.

Jump to

Keyboard shortcuts

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