workflowtest

package
v0.6.99 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 24 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 and routes somewhere else than the service's task queue in the namespace.

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. The worker is a component of the harness tree: it starts with Start and stops with the tree. Call it after declaring and before Start.

When the service declares hooks, a Nexus endpoint named after the service routes workflows.CallHook to its task queue, answered by backplanetest.Answer of the harness whose worker takes the call. The endpoint belongs to the test, not to one harness: a Worker joins one that already routes to the same queue, and the endpoint is deleted when the test ends. Replicas of one service (harnesses of the same name in one test) therefore share the queue and the endpoint as in production: one stops, the others take its workflows and hook calls. Answer the hooks on every replica.

Endpoints are cluster-wide: separate tests that run at once on one cluster need distinct service names (backplanetest.Name), or they share one queue. An endpoint of the name that routes elsewhere 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