temporaltest

package
v0.0.0-...-46b830c Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestServer

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

A TestServer is a Temporal server listening on a system-chosen port on the local loopback interface, for use in end-to-end tests.

func NewServer

func NewServer(opts ...TestServerOption) *TestServer

NewServer starts and returns a new TestServer.

If not specifying the WithT option, the caller should execute Stop when finished to close the server and release resources.

Example (TestWorker)
package main

import (
	"context"
	"fmt"
	"testing"

	"go.temporal.io/sdk/client"
	"go.temporal.io/sdk/worker"

	"github.com/evgenebruter-zoomin/temporalite/internal/examples/helloworld"
	"github.com/evgenebruter-zoomin/temporalite/temporaltest"
)

// to be used in example code
var t *testing.T

func main() {
	// Create test Temporal server and client
	ts := temporaltest.NewServer(temporaltest.WithT(t))
	c := ts.Client()

	// Register a new worker on the `hello_world` task queue
	ts.Worker("hello_world", func(registry worker.Registry) {
		helloworld.RegisterWorkflowsAndActivities(registry)
	})

	// Start test workflow
	wfr, err := c.ExecuteWorkflow(
		context.Background(),
		client.StartWorkflowOptions{TaskQueue: "hello_world"},
		helloworld.Greet,
		"world",
	)
	if err != nil {
		t.Fatal(err)
	}

	// Get workflow result
	var result string
	if err := wfr.Get(context.Background(), &result); err != nil {
		t.Fatal(err)
	}

	// Print result
	fmt.Println(result)
}
Output:

Hello world

func (*TestServer) Client

func (ts *TestServer) Client() client.Client

Client returns a Temporal client configured for making requests to the server. It is configured to use a pre-registered test namespace and will be closed on TestServer.Stop.

func (*TestServer) NewClientWithOptions

func (ts *TestServer) NewClientWithOptions(opts client.Options) client.Client

NewClientWithOptions returns a Temporal client configured for making requests to the server. If no namespace option is set it will use a pre-registered test namespace. The returned client will be closed on TestServer.Stop.

func (*TestServer) Stop

func (ts *TestServer) Stop()

Stop closes test clients and shuts down the server.

func (*TestServer) Worker

func (ts *TestServer) Worker(taskQueue string, registerFunc func(registry worker.Registry)) worker.Worker

Worker registers and starts a Temporal worker on the specified task queue.

type TestServerOption

type TestServerOption interface {
	// contains filtered or unexported methods
}

func WithSA

func WithSA(searchAttributes map[string]enums.IndexedValueType) TestServerOption

WithSA will ensure that the test server is initialized with the passed search attributes

func WithT

func WithT(t *testing.T) TestServerOption

WithT directs all worker and client logs to the test logger.

If this option is specified, then server will automatically be stopped when the test completes.

Jump to

Keyboard shortcuts

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