Documentation
¶
Overview ¶
Package testutils provides utility functions and behaviors for testing.
Index ¶
- Constants
- func AppendCovEnv(env []string) []string
- func BuildDaemon(extraArgs ...string) (execPath string, cleanup func(), err error)
- func CanRunRustTests(coverageWanted bool) (err error)
- func CoverDirEnv() string
- func CoverDirForTests() string
- func CurrentDir() string
- func GenerateEncryptionKey(brokerName string) string
- func GenerateSessionID(username string) string
- func GetSystemBusConnection(t *testing.T) (*dbus.Conn, error)
- func IsAsan() bool
- func IsRace() bool
- func IsVerbose() bool
- func MakeReadOnly(t *testing.T, dest string)
- func ProjectRoot() string
- func RunDaemon(ctx context.Context, t *testing.T, execPath string, args ...DaemonOption) (socketPath string, stopped chan struct{})
- func SleepMultiplier() float64
- func StartBusBrokerMock(cfgDir string, brokerName string) (string, func(), error)
- func StartBusMock() (string, func(), error)
- func StartSystemBusMock() (func(), error)
- func TestFamilyPath(t *testing.T) string
- func TrackRustCoverage(t *testing.T, src string) (env []string, target string)
- type BrokerBusMock
- func (b *BrokerBusMock) CancelIsAuthenticated(sessionID string) (dbusErr *dbus.Error)
- func (b *BrokerBusMock) EndSession(sessionID string) (dbusErr *dbus.Error)
- func (b *BrokerBusMock) GetAuthenticationModes(sessionID string, supportedUILayouts []map[string]string) (authenticationModes []map[string]string, dbusErr *dbus.Error)
- func (b *BrokerBusMock) IsAuthenticated(sessionID, authenticationData string) (access, data string, dbusErr *dbus.Error)
- func (b *BrokerBusMock) NewSession(username, lang, mode string) (sessionID, encryptionKey string, dbusErr *dbus.Error)
- func (b *BrokerBusMock) SelectAuthenticationMode(sessionID, authenticationModeName string) (uiLayoutInfo map[string]string, dbusErr *dbus.Error)
- func (b *BrokerBusMock) UserPreCheck(username string) (userinfo string, dbusErr *dbus.Error)
- type DaemonOption
Constants ¶
const (
// IDSeparator is the value used to append values to the sessionID in the broker mock.
IDSeparator = "_separator_"
)
Variables ¶
This section is empty.
Functions ¶
func AppendCovEnv ¶
AppendCovEnv returns the env needed to enable coverage when running a go binary, if coverage is enabled.
func BuildDaemon ¶
BuildDaemon builds the daemon executable and returns the binary path.
func CanRunRustTests ¶
CanRunRustTests returns if we can run rust tests via cargo on this machine. It checks for code coverage report if supported.
func CoverDirEnv ¶
func CoverDirEnv() string
CoverDirEnv returns the cover dir env variable to run a go binary, if coverage is enabled.
func CoverDirForTests ¶
func CoverDirForTests() string
CoverDirForTests parses the test arguments and return the cover profile directory, if coverage is enabled.
func GenerateEncryptionKey ¶
GenerateEncryptionKey returns an encryption key that can be used in tests.
func GenerateSessionID ¶
GenerateSessionID returns a sessionID that can be used in tests.
func GetSystemBusConnection ¶
GetSystemBusConnection returns a connection to the system bus with a safety check to avoid mistakenly connecting to the actual system bus.
func IsAsan ¶
func IsAsan() bool
IsAsan returns whether the tests are running with address sanitizer.
func IsRace ¶
func IsRace() bool
IsRace returns whether the tests are running with thread sanitizer.
func IsVerbose ¶
func IsVerbose() bool
IsVerbose returns whether the tests are running in verbose mode.
func MakeReadOnly ¶
MakeReadOnly makes dest read only and restore permission on cleanup.
func ProjectRoot ¶
func ProjectRoot() string
ProjectRoot returns the absolute path to the project root.
func RunDaemon ¶
func RunDaemon(ctx context.Context, t *testing.T, execPath string, args ...DaemonOption) (socketPath string, stopped chan struct{})
RunDaemon runs the daemon in a separate process and returns the socket path and a channel that will be closed when the daemon stops.
func SleepMultiplier ¶
func SleepMultiplier() float64
SleepMultiplier returns the sleep multiplier to be used in tests.
func StartBusBrokerMock ¶
StartBusBrokerMock starts the D-Bus service and exports it on the system bus. It returns the configuration file path for the exported broker.
func StartBusMock ¶
StartBusMock starts a mock dbus daemon and returns its address and a cancel function to stop it.
func StartSystemBusMock ¶
func StartSystemBusMock() (func(), error)
StartSystemBusMock starts a mock dbus daemon and returns a cancel function to stop it.
This function uses t.Setenv to set the DBUS_SYSTEM_BUS_ADDRESS environment, so it shouldn't be used in parallel tests that rely on the mentioned variable.
func TestFamilyPath ¶
TestFamilyPath returns the path of the dir for storing fixtures and other files related to the test.
func TrackRustCoverage ¶
TrackRustCoverage returns environment variables and target directory so that following commands runs with code coverage enabled. Note that for developping purposes and avoiding keeping building the rust program dependencies, TEST_RUST_TARGET environment variable can be set to an absolute path to keep iterative build artifacts. This then allow coverage to run in parallel, as each subprocess will have its own environment. You will need to call MergeCoverages() after m.Run(). If code coverage is not enabled, it still returns an empty slice, but the target can be used.
Types ¶
type BrokerBusMock ¶
type BrokerBusMock struct {
// contains filtered or unexported fields
}
BrokerBusMock is the D-Bus object that will answer calls for the broker mock.
func (*BrokerBusMock) CancelIsAuthenticated ¶
func (b *BrokerBusMock) CancelIsAuthenticated(sessionID string) (dbusErr *dbus.Error)
CancelIsAuthenticated cancels an ongoing IsAuthenticated call if it exists.
func (*BrokerBusMock) EndSession ¶
func (b *BrokerBusMock) EndSession(sessionID string) (dbusErr *dbus.Error)
EndSession returns default values to be used in tests or an error if requested.
func (*BrokerBusMock) GetAuthenticationModes ¶
func (b *BrokerBusMock) GetAuthenticationModes(sessionID string, supportedUILayouts []map[string]string) (authenticationModes []map[string]string, dbusErr *dbus.Error)
GetAuthenticationModes returns default values to be used in tests or an error if requested.
func (*BrokerBusMock) IsAuthenticated ¶
func (b *BrokerBusMock) IsAuthenticated(sessionID, authenticationData string) (access, data string, dbusErr *dbus.Error)
IsAuthenticated returns default values to be used in tests or an error if requested.
func (*BrokerBusMock) NewSession ¶
func (b *BrokerBusMock) NewSession(username, lang, mode string) (sessionID, encryptionKey string, dbusErr *dbus.Error)
NewSession returns default values to be used in tests or an error if requested.
func (*BrokerBusMock) SelectAuthenticationMode ¶
func (b *BrokerBusMock) SelectAuthenticationMode(sessionID, authenticationModeName string) (uiLayoutInfo map[string]string, dbusErr *dbus.Error)
SelectAuthenticationMode returns default values to be used in tests or an error if requested.
func (*BrokerBusMock) UserPreCheck ¶
func (b *BrokerBusMock) UserPreCheck(username string) (userinfo string, dbusErr *dbus.Error)
UserPreCheck returns default values to be used in tests or an error if requested.
type DaemonOption ¶
type DaemonOption func(*daemonOptions)
DaemonOption represents an optional function that can be used to override some of the daemon default values.
func WithCachePath ¶
func WithCachePath(path string) DaemonOption
WithCachePath overrides the default cache path of the daemon.
func WithEnvironment ¶
func WithEnvironment(env ...string) DaemonOption
WithEnvironment overrides the default environment of the daemon.
func WithPreviousDBState ¶
func WithPreviousDBState(db string) DaemonOption
WithPreviousDBState initializes the cache of the daemon with a preexistent database.
func WithSocketPath ¶
func WithSocketPath(path string) DaemonOption
WithSocketPath overrides the default socket path of the daemon.