testutils

package
v0.0.0-...-d1117c5 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DriverTestsuiteConnectTimeout = 30 * time.Second

Functions

func AssertAdvertisedCapabilityHasBuilder

func AssertAdvertisedCapabilityHasBuilder(t *testing.T, capability string, advertised bool, builder func() any)

AssertAdvertisedCapabilityHasBuilder checks the direction that always holds: a connection that advertises a capability has to hand out a builder for it. The converse is not asserted, because a driver may hand out a builder whose operations report "not implemented" while honestly advertising the capability as absent. Use AssertBuilderMatchesCapability for connections where both directions are supposed to hold.

func AssertBuilderMatchesCapability

func AssertBuilderMatchesCapability(t *testing.T, capability string, advertised bool, builder func() any)

AssertBuilderMatchesCapability checks that a connection hands out a request builder exactly when its metadata advertises the matching capability. An advertised capability has to produce a builder, and an unadvertised one has to refuse rather than hand out a builder that cannot work.

func CompareResults

func CompareResults(t *testing.T, actualString []byte, referenceString []byte) error

func EnrichOptionsWithOptionsForTesting

func EnrichOptionsWithOptionsForTesting(t *testing.T, _options ...options.WithOption) []options.WithOption

EnrichOptionsWithOptionsForTesting appends options useful for testing to config.WithOption s

func ExplodingGlobalLogger

func ExplodingGlobalLogger(hardExplode bool)

ExplodingGlobalLogger Useful to find unredirected logs

func ParseDriverTestsuiteXml

func ParseDriverTestsuiteXml(t *testing.T, testPath string) *xmldom.Node

func ParseParserSerializerTestSuiteXml

func ParseParserSerializerTestSuiteXml(t *testing.T, testPath string) *xmldom.Node

func ProduceTestingLogger

func ProduceTestingLogger(t TestingLog) zerolog.Logger

ProduceTestingLogger produces a logger which redirects to testing.T

func RunDriverTestsuite

func RunDriverTestsuite(t *testing.T, driver plc4go.PlcDriver, testPath string, parser XmlParser, _options ...options.WithOption)

func RunParserSerializerTestsuite

func RunParserSerializerTestsuite(t *testing.T, testPath string, parser Parser, options ...options.WithOption)

func RunParserTruncationTestsuite

func RunParserTruncationTestsuite(t *testing.T, testPath string, parser Parser, options ...options.WithOption)

RunParserTruncationTestsuite parses every prefix of every message in a parser-serializer testsuite and requires each one to fail, if it fails, as an error rather than as a panic.

The remote end decides where a message ends: a datagram can arrive short, and a stream can be closed mid-message, so every prefix of a well formed message is something a driver can be handed. Truncation is worth exercising in particular because a field read that runs out of bytes is reported as an absent optional rather than as a failure, so anything deriving a value from that field sees it unset in a case the surrounding condition says cannot happen.

The reference messages of a testsuite make a far better corpus for this than hand-written input, because they reach every type the protocol's own tests reach. Whether a prefix parses is left open - a truncated message may legitimately parse into a smaller one. Only the manner of failure is asserted.

func TestContext

func TestContext(t *testing.T) context.Context

TestContext produces a context which is getting cleaned up by testing.T

func WithRootTypeParser

func WithRootTypeParser(rootTypeParser func(utils.ReadBufferByteBased) (any, error)) config.WithOption

WithRootTypeParser can be used to output the root type of protocol for better debugging

func WithSkippedTestCases

func WithSkippedTestCases(skippedTestCases ...string) config.WithOption

WithSkippedTestCases can be used to skip test cases

Types

type ConnectionConnectAwaiter

type ConnectionConnectAwaiter interface {
	// SetAwaitSetupComplete sets a flag that the driver should await a connection completion
	SetAwaitSetupComplete(awaitComplete bool)
	// SetAwaitDisconnectComplete sets a flag that the driver should await a dis-connection completion
	SetAwaitDisconnectComplete(awaitComplete bool)
}

type DriverTestStep

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

func ParseDriverTestsuiteSteps

func ParseDriverTestsuiteSteps(t *testing.T, node xmldom.Node) ([]DriverTestStep, error)

type DriverTestcase

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

type DriverTestsuite

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

func ParseDriverTestsuite

func ParseDriverTestsuite(t *testing.T, node xmldom.Node, parser XmlParser, rootTypeParser func(utils.ReadBufferByteBased) (any, error)) *DriverTestsuite

func (DriverTestsuite) ExecuteStep

func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnection, testcase *DriverTestcase, step DriverTestStep) error

func (DriverTestsuite) LogDelimiterSection

func (DriverTestsuite) LogDelimiterSection(t *testing.T, delimiter, format string, a ...any)

func (DriverTestsuite) Run

func (m DriverTestsuite) Run(t *testing.T, driverManager plc4go.PlcDriverManager, testcase DriverTestcase) error

type ManualTestCase

type ManualTestCase struct {
	Address           string
	ExpectedReadValue any
	WriteValue        any
	UnwrappedValue    bool
}

type ManualTestSuite

type ManualTestSuite struct {
	ConnectionString string
	DriverManager    plc4go.PlcDriverManager
	TestCases        []ManualTestCase
	// contains filtered or unexported fields
}

func NewManualTestSuite

func NewManualTestSuite(t *testing.T, connectionString string, driverManager plc4go.PlcDriverManager) *ManualTestSuite

func (*ManualTestSuite) AddTestCase

func (m *ManualTestSuite) AddTestCase(address string, expectedReadValue any, testCaseOptions ...WithTestCaseOption)

func (*ManualTestSuite) Run

func (m *ManualTestSuite) Run() plc4go.PlcConnection

type Parser

type Parser interface {
	Parse(typeName string, arguments []string, io utils.ReadBuffer) (any, error)
}

type ParserSerializerTestcase

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

type ParserSerializerTestsuite

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

func ParseParserSerializerTestSuite

func ParseParserSerializerTestSuite(t *testing.T, node xmldom.Node, parser Parser, rootTypeParser func(utils.ReadBufferByteBased) (any, error)) *ParserSerializerTestsuite

func (*ParserSerializerTestsuite) Run

type StepType

type StepType uint8
const (
	StepTypeOutgoingPlcMessage StepType = 0x01
	StepTypeOutgoingPlcBytes   StepType = 0x02
	StepTypeIncomingPlcMessage StepType = 0x03
	StepTypeIncomingPlcBytes   StepType = 0x04
	StepTypeApiRequest         StepType = 0x05
	StepTypeApiResponse        StepType = 0x06
	StepTypeDelay              StepType = 0x07
	StepTypeTerminate          StepType = 0x08
)

func (StepType) String

func (i StepType) String() string

type TestTransportInstance

type TestTransportInstance interface {
	transports.TransportInstance
	FillReadBuffer(data []byte)
	GetNumDrainableBytes() uint32
	DrainWriteBuffer(numBytes uint32) []byte
}

type TestingLog

type TestingLog interface {
	Log(args ...any)
	Logf(format string, args ...any)
	Helper()
}

type WithTestCaseOption

type WithTestCaseOption func(testCase ManualTestCase)

func WithUnwrappedValue

func WithUnwrappedValue(unwrap bool) WithTestCaseOption

WithUnwrappedValue is a WithTestCaseOption which can be used to control if plc4go.PlcValue

type XmlParser

type XmlParser interface {
	Parse(typeName string, xmlString string, parserArguments ...string) (any, error)
}

Directories

Path Synopsis
Package xmldom provides a tiny DOM tree over encoding/xml for the test harness.
Package xmldom provides a tiny DOM tree over encoding/xml for the test harness.

Jump to

Keyboard shortcuts

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