testutils

package
v0.0.0-...-34ffbed Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package testutils provides utility functions and behaviors for testing.

Package testutils provides utility functions and behaviors for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupPrivateBuses

func CleanupPrivateBuses()

CleanupPrivateBuses cleans up the private buses created for testing.

func ExportAccountsMock

func ExportAccountsMock(conn *dbus.Conn) error

ExportAccountsMock exports the accounts mock to the system bus.

func ExportGdmMock

func ExportGdmMock(conn *dbus.Conn) error

ExportGdmMock exports a mock GDM Manager on the system bus.

func ExportHostnameMock

func ExportHostnameMock(conn *dbus.Conn) error

ExportHostnameMock exports the hostname mock to the system bus.

func ExportLocaleMock

func ExportLocaleMock(conn *dbus.Conn) error

ExportLocaleMock exports the locale mock to the system bus.

func ExportTimedateMock

func ExportTimedateMock(conn *dbus.Conn) error

ExportTimedateMock exports the locale mock to the system bus.

func ExportUserMock

func ExportUserMock(conn *dbus.Conn) error

ExportUserMock exports the user mock to the system bus.

func GetSystemBusConnection

func GetSystemBusConnection() (*dbus.Conn, error)

GetSystemBusConnection returns a connection to the system bus with a safety check to avoid mistakenly connecting to the actual system bus.

func GoldenPath

func GoldenPath(t *testing.T) string

GoldenPath returns the golden path for the provided test.

func InstallUpdateFlag

func InstallUpdateFlag()

InstallUpdateFlag install an update flag referenced in this package. The flags need to be parsed before running the tests.

func LoadWithUpdateFromGolden

func LoadWithUpdateFromGolden(t *testing.T, data string, opts ...GoldenOption) string

LoadWithUpdateFromGolden loads the element from a plaintext golden file. It will update the file if the update flag is used prior to loading it.

func LoadWithUpdateFromGoldenYAML

func LoadWithUpdateFromGoldenYAML[E any](t *testing.T, got E, opts ...GoldenOption) E

LoadWithUpdateFromGoldenYAML load the generic element from a YAML serialized golden file. It will update the file if the update flag is used prior to deserializing it.

func NewDbusConn

func NewDbusConn(t *testing.T) *dbus.Conn

NewDbusConn returns a system dbus connection which automatically close on test shutdown.

func NormalizeGoldenName

func NormalizeGoldenName(t *testing.T, name string) string

NormalizeGoldenName returns the name of the golden file with illegal Windows characters replaced or removed.

func ReadActionFromFile

func ReadActionFromFile(opts ...Option) (string, error)

ReadActionFromFile reads the action from a file, compared against goldenfiles to test the correct actions are being called.

func StartLocalSystemBus

func StartLocalSystemBus() func()

StartLocalSystemBus allows to start and set environment variable to a local bus, preventing polluting system ones.

func TestFamilyPath

func TestFamilyPath(t *testing.T) string

TestFamilyPath returns the path of the dir for storing fixtures and other files related to the test.

func Update

func Update() bool

Update returns true if the update flag was set, false otherwise.

func WriteActionToFile

func WriteActionToFile(action string, opts ...Option)

WriteActionToFile writes the action to a file, compared against goldenfiles to test the correct actions are being called.

Types

type GoldenOption

type GoldenOption func(*goldenOptions)

GoldenOption is a supported option reference to change the golden files comparison.

func WithGoldenPath

func WithGoldenPath(path string) GoldenOption

WithGoldenPath overrides the default path for golden files used.

type Option

type Option func(*options)

Option defines the type for functional options.

func WithFilePath

func WithFilePath(filePath string) Option

WithFilePath configures a custom file path for WriteActionToFile.

Jump to

Keyboard shortcuts

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