testutils

package
v0.0.0-...-d61f662 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	WAIT_INTERVAL_MS       = 10
	WAIT_COUNT             = 300
	REC_EMPTY_WAIT_TIME_MS = 50
	REC_SKIP_TIME_MS       = 3000
	REC_ITEM_TIMEOUT_MS    = 5000
)
View Source
const (
	SAMPLE_CLIENT_ID = "11111111"
)

Variables

This section is empty.

Functions

func EnsureGotErrors

func EnsureGotErrors(t *testing.T)

func EnsureGotWarnings

func EnsureGotWarnings(t *testing.T)

func EnsureNoErrorsOrWarnings

func EnsureNoErrorsOrWarnings(t *testing.T)

func FormatMQTTMessage

func FormatMQTTMessage(message wbgo.MQTTMessage) string

func RunSuites

func RunSuites(t *testing.T, suites ...suite.TestingSuite)

RunSuites runs the specified test suites

func SetupTempDir

func SetupTempDir(t *testing.T) (string, func())

SetupTempDir creates a temporary directory to be used in tests and makes it the current directory. In case of an error, makes the test fail. Returns the path to the temporary directory and cleanup function that removes the directory and changes back to the directory that was current before SetupTempDir was called.

func SetupTestLogging

func SetupTestLogging(t *testing.T)

SetupTestLogging sets up the logging output in such way that it's only shown if the current test fails.

func WaitFor

func WaitFor(t *testing.T, pred func() bool)

WaitFor waits for the function specified by pred to return true. The test fails if it takes too long.

func WaitForErrors

func WaitForErrors(t *testing.T)

func WaitForWarnings

func WaitForWarnings(t *testing.T)

Types

type DataFileFixture

type DataFileFixture struct {
	*Fixture
	// contains filtered or unexported fields
}

func NewDataFileFixture

func NewDataFileFixture(t *testing.T) (f *DataFileFixture)

func (*DataFileFixture) CopyDataFileToTempDir

func (f *DataFileFixture) CopyDataFileToTempDir(sourceName, targetName string) (targetPath string)

func (*DataFileFixture) CopyDataFilesToTempDir

func (f *DataFileFixture) CopyDataFilesToTempDir(names ...string)

func (*DataFileFixture) CopyModifiedDataFileToTempDir

func (f *DataFileFixture) CopyModifiedDataFileToTempDir(sourceName, targetName string, edit func(string) string) (targetPath string)

func (*DataFileFixture) DataFilePath

func (f *DataFileFixture) DataFilePath(dataFile string) string

func (*DataFileFixture) DataFileTempDir

func (f *DataFileFixture) DataFileTempDir() string

func (*DataFileFixture) ReadSourceDataFile

func (f *DataFileFixture) ReadSourceDataFile(sourceName string) string

func (*DataFileFixture) RmFile

func (f *DataFileFixture) RmFile(filename string)

func (*DataFileFixture) SourceDir

func (f *DataFileFixture) SourceDir() string

func (*DataFileFixture) TearDownDataFiles

func (f *DataFileFixture) TearDownDataFiles()

func (*DataFileFixture) WriteDataFile

func (f *DataFileFixture) WriteDataFile(filename, content string) string

type FakeDev

type FakeDev interface {
	wbgo.DeviceModel
	GetValue(name string) string
	GetType(name string) string
}

type FakeDevice

type FakeDevice struct {
	wbgo.DeviceBase
	// contains filtered or unexported fields
}

func (*FakeDevice) AcceptValue

func (dev *FakeDevice) AcceptValue(name, value string)

func (*FakeDevice) GetType

func (dev *FakeDevice) GetType(name string) string

func (*FakeDevice) GetValue

func (dev *FakeDevice) GetValue(name string) string

func (*FakeDevice) ReceiveValue

func (dev *FakeDevice) ReceiveValue(name, value string)

type FakeExtDevice

type FakeExtDevice struct {
	FakeDevice
}

func (*FakeExtDevice) AcceptControlRange

func (dev *FakeExtDevice) AcceptControlRange(name string, max float64)

func (*FakeExtDevice) AcceptControlType

func (dev *FakeExtDevice) AcceptControlType(name, controlType string)

type FakeLocalDevice

type FakeLocalDevice struct {
	FakeDevice
	// contains filtered or unexported fields
}

func (*FakeLocalDevice) AcceptOnValue

func (dev *FakeLocalDevice) AcceptOnValue(name, value string) bool

func (*FakeLocalDevice) IsVirtual

func (dev *FakeLocalDevice) IsVirtual() bool

func (*FakeLocalDevice) QueryParams

func (dev *FakeLocalDevice) QueryParams()

type FakeMQTTBroker

type FakeMQTTBroker struct {
	*Recorder
	sync.Mutex
	// contains filtered or unexported fields
}

func NewFakeMQTTBroker

func NewFakeMQTTBroker(t *testing.T, rec *Recorder) (broker *FakeMQTTBroker)

func (*FakeMQTTBroker) MakeClient

func (broker *FakeMQTTBroker) MakeClient(id string) (client *FakeMQTTClient)

func (*FakeMQTTBroker) Publish

func (broker *FakeMQTTBroker) Publish(origin string, message wbgo.MQTTMessage)

func (*FakeMQTTBroker) SetReady

func (broker *FakeMQTTBroker) SetReady()

func (*FakeMQTTBroker) SetWaitForRetained

func (broker *FakeMQTTBroker) SetWaitForRetained(waitForRetained bool)

func (*FakeMQTTBroker) Subscribe

func (broker *FakeMQTTBroker) Subscribe(client *FakeMQTTClient, topic string)

func (*FakeMQTTBroker) Unsubscribe

func (broker *FakeMQTTBroker) Unsubscribe(client *FakeMQTTClient, topic string)

type FakeMQTTClient

type FakeMQTTClient struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*FakeMQTTClient) Publish

func (client *FakeMQTTClient) Publish(message wbgo.MQTTMessage)

func (*FakeMQTTClient) Start

func (client *FakeMQTTClient) Start()

func (*FakeMQTTClient) Stop

func (client *FakeMQTTClient) Stop()

func (*FakeMQTTClient) Subscribe

func (client *FakeMQTTClient) Subscribe(callback wbgo.MQTTMessageHandler, topics ...string)

func (*FakeMQTTClient) Unsubscribe

func (client *FakeMQTTClient) Unsubscribe(topics ...string)

func (*FakeMQTTClient) WaitForReady

func (client *FakeMQTTClient) WaitForReady() <-chan struct{}

type FakeMQTTFixture

type FakeMQTTFixture struct {
	*Recorder
	Broker *FakeMQTTBroker
}

func NewFakeMQTTFixture

func NewFakeMQTTFixture(t *testing.T) *FakeMQTTFixture

type FakeModel

type FakeModel struct {
	*Recorder
	wbgo.ModelBase
	// contains filtered or unexported fields
}

func NewFakeModel

func NewFakeModel(t *testing.T) (model *FakeModel)

func (*FakeModel) AddExternalDevice

func (model *FakeModel) AddExternalDevice(name string) (wbgo.ExternalDeviceModel, error)

func (*FakeModel) GetDevice

func (model *FakeModel) GetDevice(name string) FakeDev

func (*FakeModel) HasDevice

func (model *FakeModel) HasDevice(name string) bool

func (*FakeModel) MakeLocalDevice

func (model *FakeModel) MakeLocalDevice(name string, title string,
	paramTypes map[string]string) (dev *FakeLocalDevice)

func (*FakeModel) MakeLocalVirtualDevice

func (model *FakeModel) MakeLocalVirtualDevice(name string, title string,
	paramTypes map[string]string) (dev *FakeLocalDevice)

func (*FakeModel) Poll

func (model *FakeModel) Poll()

func (*FakeModel) Start

func (model *FakeModel) Start() error

type FakeTimerFixture

type FakeTimerFixture struct {
	*Fixture
	// contains filtered or unexported fields
}

func NewFakeTimerFixture

func NewFakeTimerFixture(t *testing.T, rec *Recorder) *FakeTimerFixture

TBD: use Setup instead

func (*FakeTimerFixture) AdvanceTime

func (fixture *FakeTimerFixture) AdvanceTime(d time.Duration) time.Time

func (*FakeTimerFixture) ClearTimers

func (fixture *FakeTimerFixture) ClearTimers()

func (*FakeTimerFixture) CurrentTime

func (fixture *FakeTimerFixture) CurrentTime() time.Time

func (*FakeTimerFixture) FireTimer

func (fixture *FakeTimerFixture) FireTimer(id uint64, ts time.Time)

func (*FakeTimerFixture) NewFakeTicker

func (fixture *FakeTimerFixture) NewFakeTicker(d time.Duration) wbgo.Timer

func (*FakeTimerFixture) NewFakeTimer

func (fixture *FakeTimerFixture) NewFakeTimer(d time.Duration) wbgo.Timer

func (*FakeTimerFixture) NewFakeTimerOrTicker

func (fixture *FakeTimerFixture) NewFakeTimerOrTicker(id uint64, d time.Duration, periodic bool) wbgo.Timer

type Fixture

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

func NewFixture

func NewFixture(t *testing.T) *Fixture

func (*Fixture) Ckf

func (f *Fixture) Ckf(msg string, err error)

func (*Fixture) T

func (fixture *Fixture) T() *testing.T

type RecMatcher

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

func JSONRecMatcher

func JSONRecMatcher(value objx.Map, itemRx string) *RecMatcher

JSONRecMatcher returns a matcher that matches a first group captured by regular expression rx against JSON value. If rx has no groups, the whole text matched by rx is used

func NewRecMatcher

func NewRecMatcher(text string, fn RecMatcherFunc) *RecMatcher

func RegexpCaptureMatcher

func RegexpCaptureMatcher(itemRx string, handler RegexpCaptureHandler) *RecMatcher

RegexpCaptureMatcher is the same as RegexpCaptureMatcherWithCustomText but uses itemRx as mismatch text

func RegexpCaptureMatcherWithCustomText

func RegexpCaptureMatcherWithCustomText(itemRx string, text string, handler RegexpCaptureHandler) *RecMatcher

RegexpCaptureMatcherWithCustomText returns a matcher that matches the specified regexp against the item being verified, then invokes handler with submatches slice as an argument. Succeeds only in case handler returns true. The speicified text is used in mismatch logs.

type RecMatcherFunc

type RecMatcherFunc func(item string) bool

type Recorder

type Recorder struct {
	*Fixture
	// contains filtered or unexported fields
}

func NewRecorder

func NewRecorder(t *testing.T) *Recorder

func (*Recorder) Rec

func (rec *Recorder) Rec(format string, args ...interface{})

func (*Recorder) SetEmptyWaitTime

func (rec *Recorder) SetEmptyWaitTime(duration time.Duration)

func (*Recorder) SkipTill

func (rec *Recorder) SkipTill(logItem string)

func (*Recorder) Verify

func (rec *Recorder) Verify(logs ...interface{})

func (*Recorder) VerifyEmpty

func (rec *Recorder) VerifyEmpty()

func (*Recorder) VerifyUnordered

func (rec *Recorder) VerifyUnordered(logs ...interface{})

type RegexpCaptureHandler

type RegexpCaptureHandler func(submatches []string) bool

type RpcFixture

type RpcFixture struct {
	*FakeMQTTFixture
	// contains filtered or unexported fields
}

func NewRpcFixture

func NewRpcFixture(t *testing.T, app, service, clientName string, rcvr interface{}, methods ...string) (f *RpcFixture)

func (*RpcFixture) TearDownRPC

func (f *RpcFixture) TearDownRPC()

func (*RpcFixture) VerifyRpc

func (f *RpcFixture) VerifyRpc(subtopic string, params objx.Map, expectedResult interface{})

func (*RpcFixture) VerifyRpcError

func (f *RpcFixture) VerifyRpcError(subtopic string, param objx.Map, code int, typ string, msg string)

type SubscriptionList

type SubscriptionList []*FakeMQTTClient

type SubscriptionMap

type SubscriptionMap map[string]SubscriptionList

type Suite

type Suite struct {
	suite.Suite
}

func (*Suite) Ck

func (suite *Suite) Ck(msg string, err error)

func (*Suite) EnsureGotErrors

func (suite *Suite) EnsureGotErrors()

func (*Suite) EnsureGotWarnings

func (suite *Suite) EnsureGotWarnings()

func (*Suite) EnsureNoErrorsOrWarnings

func (suite *Suite) EnsureNoErrorsOrWarnings()

func (*Suite) SetupTest

func (suite *Suite) SetupTest()

func (*Suite) TearDownTest

func (suite *Suite) TearDownTest()

func (*Suite) WaitFor

func (suite *Suite) WaitFor(pred func() bool)

func (*Suite) WaitForErrors

func (suite *Suite) WaitForErrors()

func (*Suite) WaitForWarnings

func (suite *Suite) WaitForWarnings()

type TestLog

type TestLog struct {
	sync.Mutex
	// contains filtered or unexported fields
}

TestLog makes it possible to use log module with testing's logging functions, so that the logging output is only shown when the test fails. Note that a part at the end of output that is not newline-terminated is not displayed.

func NewTestLog

func NewTestLog(t *testing.T) *TestLog

func (*TestLog) VerifyPristine

func (tl *TestLog) VerifyPristine(msg string)

func (*TestLog) VerifyUsed

func (tl *TestLog) VerifyUsed(msg string)

func (*TestLog) WaitForMessages

func (tl *TestLog) WaitForMessages()

func (*TestLog) Write

func (tl *TestLog) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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