This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
/
options.go
67 lines (55 loc) · 2.02 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
package temporaltest
import (
"testing"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/worker"
"github.com/temporalio/temporalite"
)
type TestServerOption interface {
apply(*TestServer)
}
// 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.
func WithT(t *testing.T) TestServerOption {
return newApplyFuncContainer(func(server *TestServer) {
server.t = t
})
}
// WithBaseClientOptions configures options for the default clients and workers connected to the test server.
func WithBaseClientOptions(o client.Options) TestServerOption {
return newApplyFuncContainer(func(server *TestServer) {
server.defaultClientOptions = o
})
}
// With WithBaseWorkerOptions configures default options for workers connected to the test server.
//
// WorkflowPanicPolicy is always set to worker.FailWorkflow so that workflow executions
// fail fast when workflow code panics or detects non-determinism.
func WithBaseWorkerOptions(o worker.Options) TestServerOption {
o.WorkflowPanicPolicy = worker.FailWorkflow
return newApplyFuncContainer(func(server *TestServer) {
server.defaultWorkerOptions = o
})
}
// WithTemporaliteOptions provides the ability to use additional Temporalite options, including temporalite.WithUpstreamOptions.
func WithTemporaliteOptions(options ...temporalite.ServerOption) TestServerOption {
return newApplyFuncContainer(func(server *TestServer) {
server.serverOptions = append(server.serverOptions, options...)
})
}
type applyFuncContainer struct {
applyInternal func(*TestServer)
}
func (fso *applyFuncContainer) apply(ts *TestServer) {
fso.applyInternal(ts)
}
func newApplyFuncContainer(apply func(*TestServer)) *applyFuncContainer {
return &applyFuncContainer{
applyInternal: apply,
}
}