integration_support

package
v1.1.1913 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NATS_SERVER_IMAGE_URL_ENV_VAR_NAME is the name of the env var containing the nats image URL
	NATS_SERVER_IMAGE_URL_ENV_VAR_NAME = "NATS_SERVER_IMAGE_URL"
	// SHAR_SERVER_IMAGE_URL_ENV_VAR_NAME is the name of the env var containing the shar server image URL
	SHAR_SERVER_IMAGE_URL_ENV_VAR_NAME = "SHAR_SERVER_IMAGE_URL"
	// NATS_PERSIST_ENV_VAR_NAME is the name of the env var containing the flag determining whether nats data is persisted between tests
	NATS_PERSIST_ENV_VAR_NAME = "NATS_PERSIST"
)
View Source
const DefaultWait = 40 * time.Second

DefaultWait is the minimum time to wait for a test area to complete.

Variables

This section is empty.

Functions

func GetPackageName

func GetPackageName(packageNameStruct any) string

GetPackageName retrieves the name of a package a particular struct is declared in

func IsNatsContainerised

func IsNatsContainerised() bool

IsNatsContainerised determines whether tests are running against containerised nats server

func IsNatsPersist

func IsNatsPersist() bool

IsNatsPersist determines whether tests are persist nats data between executions

func IsSharContainerised

func IsSharContainerised() bool

IsSharContainerised determines whether tests are running against containerised shar server

func ListenForMsg added in v1.1.1484

func ListenForMsg(expectedMessage ExpectedMessage)

ListenForMsg subscribes to the subject and proto message described by expectedMessage

func RegisterTaskYamlFile

func RegisterTaskYamlFile(ctx context.Context, cl *client.Client, filename string, fn task2.ServiceFn) (string, error)

RegisterTaskYamlFile is used by integration tests to register a service task and function from a YAML file. It first loads and registers the task using taskutil.LoadTaskFromYamlFile, and then registers the task function using taskutil.RegisterTaskFunctionFromYamlFile. It is not recommended to call the functions in succession in real world scenarios as it will cause a task version race condition. Instead, call taskutil.LoadTaskFromYamlFile from an external application, and use taskutil.RegisterTaskFunctionFromYamlFile inside the service task to register the function

func WaitForChan

func WaitForChan[T any](t *testing.T, c chan T, d time.Duration, assertions ...func(ele T))

WaitForChan waits for a chan T with a duration timeout and runs the provided assertion functions.

func WaitForExpectedCompletions

func WaitForExpectedCompletions(t *testing.T, expectedCompletions int, completion chan struct{}, timeout time.Duration)

WaitForExpectedCompletions will wait up to timeout for expectedCompletions on the completion channel

Types

type ExecutionWatch added in v1.1.1913

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

ExecutionWatch contains the context and jetstream for watching execution complete events.

func (*ExecutionWatch) Close added in v1.1.1913

func (w *ExecutionWatch) Close(t *testing.T)

Close shuts down the execution watch.

type ExpectedMessage added in v1.1.1484

type ExpectedMessage struct {
	T             *testing.T
	NatsUrl       string
	Subject       string
	CreateModelFn func() proto.Message
	MsgReceived   chan struct{}
}

ExpectedMessage desribes a subject to listen to, the proto message type to deser into and a ch signalling a message has arrived

type Integration

type Integration struct {
	FinalVars model.Vars
	Mx        sync.Mutex
	Cooldown  time.Duration

	WithTrace bool

	NatsURL      string // NatsURL is the default testing URL for the NATS host.
	TestRunnable func() (bool, string)
	// contains filtered or unexported fields
}

Integration - the integration test support framework.

func NewIntegration

func NewIntegration(trace bool, packageName string, spanExporter server2.Exporter) *Integration

NewIntegration is used to construct an instance of Integration support used from the context of a package

func NewIntegrationT

func NewIntegrationT(t *testing.T, authZFn authz.APIFunc, authNFn authn.Check, trace bool, testRunnableFn func() (bool, string), spanExporter server2.Exporter) *Integration

NewIntegrationT is used to construct an instance of Integration support used from the context of a test

func NewIntegrationWithAuth added in v1.1.1687

func NewIntegrationWithAuth(trace bool, packageName string, authZFn authz.APIFunc, authNFn authn.Check, spanExporter server2.Exporter) *Integration

NewIntegrationWithAuth is used to construct an instance of Integration support used from the context of a package

func (*Integration) AssertCleanKV

func (s *Integration) AssertCleanKV(namespce string, t *testing.T, cooldown time.Duration)

AssertCleanKV - ensures SHAR has cleans up after itself, and there are no records left in the KV.

func (*Integration) AssertExpectedKVKey added in v1.1.1377

func (s *Integration) AssertExpectedKVKey(namespace string, kvName string, key string, timeout time.Duration, t *testing.T)

AssertExpectedKVKey waits for timeout for the existence of the expected key in the given kv and namespace.

func (*Integration) CreateContext added in v1.1.1687

func (s *Integration) CreateContext(ctx context.Context, t *testing.T) (context.Context, *TestContext)

CreateContext initializes a context and a trace span with testing attributes for integration tests.

func (*Integration) GetJetstream

func (s *Integration) GetJetstream() (jetstream.JetStream, error)

GetJetstream - fetches the test framework jetstream server for making test calls.

func (*Integration) GetNats

func (s *Integration) GetNats() (*nats.Conn, error)

GetNats - fetches the test framework NATS server for making test calls.

func (*Integration) RegisterExecutionComplete added in v1.1.1913

func (s *Integration) RegisterExecutionComplete(t *testing.T, namespace string, name string, memoryStorage bool, fn func(state *model.WorkflowState, vars model.Vars) error) *ExecutionWatch

RegisterExecutionComplete registers a callback for execution complete events.

func (*Integration) Setup

func (s *Integration) Setup()

Setup - sets up the test NATS and SHAR servers.

func (*Integration) Teardown

func (s *Integration) Teardown()

Teardown - resposible for shutting down the integration test framework.

func (*Integration) Wiretap added in v1.1.1687

func (s *Integration) Wiretap(t *testing.T, ns string, sharSubject string) *Wiretap

Wiretap creates a new message capture

type TestContext added in v1.1.1687

type TestContext struct {
	Span trace.Span
	// contains filtered or unexported fields
}

TestContext provides a container for a trace.Span used to manage tracing within a testing context.

func (*TestContext) End added in v1.1.1687

func (tc *TestContext) End(options ...trace.SpanEndOption)

End terminates the current trace span associated with the TestContext, applying the provided options.

type Wiretap added in v1.1.1687

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

Wiretap waits for a specific message type to be received

func (*Wiretap) AwaitReceived added in v1.1.1687

func (w *Wiretap) AwaitReceived(duration time.Duration) *model.WorkflowState

AwaitReceived waits for a message on the wiretap,

func (*Wiretap) Close added in v1.1.1687

func (w *Wiretap) Close()

Close shuts down a wiretap

Jump to

Keyboard shortcuts

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