workflowtest

package
v0.6.69 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEndpointTaken = errors.New("nexus endpoint taken")

ErrEndpointTaken: the Nexus endpoint named after the service exists already — another harness of the same service runs on the cluster, or a killed test left it behind.

Functions

func New

New creates a Temporal test environment (go.temporal.io/sdk/ testsuite) set up as the service's worker is: every activity declared with activity.Handle or workflows.HandleActivity (by name, over the envelope), every workflow of workflows.Declare and workflows.Activity, and what workflows.Register registers. The service's hooks are a Nexus service of the environment answered by Answer, so workflows.CallHook works in workflow code; an unanswered hook fails with hook.ErrNoBinding, a failing answer with its message. Declare everything first; Start the harness first when the handlers use dependencies. An environment runs one workflow: call New again for the next.

w := workflowtest.New(t, h)
w.ExecuteWorkflow("Welcome", in)
err := w.GetWorkflowResult(&out)

func Worker added in v0.6.69

func Worker(tb testing.TB, h *backplanetest.Harness, c client.Client, opts ...WorkerOption)

Worker runs the service's worker on a real Temporal server through c: the service's task queue (its name) serves what New registers — every activity, the workflows of workflows.Declare, workflows.Activity and workflows.Register — so workflows the service starts run as in production. When the service declares hooks, a Nexus endpoint named after the service routes workflows.CallHook to the same worker, answered by backplanetest.Answer as in New. The worker is a component of the harness tree: it starts with Start and stops with the tree, deleting the endpoint. Call it after declaring and before Start.

The queue and the endpoint are named after the service, and endpoints are cluster-wide: harnesses running at once on one cluster need distinct service names (backplanetest.Name); a taken endpoint fails the start with ErrEndpointTaken.

workflowtest.Worker(t, h, c)
h.Start()
run, _ := c.ExecuteWorkflow(ctx, client.StartWorkflowOptions{TaskQueue: h.Service()}, "Ship", in)

func WorkflowActivity

func WorkflowActivity[Req, Res any](w *testsuite.TestWorkflowEnvironment, name string, in Req) (Res, error)

WorkflowActivity runs the workflow-backed activity name (workflows.Activity) in w as a binding step would start it, and returns its result. w is from New; it runs this one workflow.

Types

type WorkerOption added in v0.6.69

type WorkerOption func(o *workerOptions)

WorkerOption tunes Worker.

func Namespace added in v0.6.69

func Namespace(ns string) WorkerOption

Namespace is the namespace c is connected to ("default" by default): the Nexus endpoint of the hooks targets it.

Jump to

Keyboard shortcuts

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