-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathworkflows_test.go
70 lines (54 loc) · 2.32 KB
/
workflows_test.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
68
69
70
package caller_test
import (
"context"
"testing"
"github.com/nexus-rpc/sdk-go/nexus"
"github.com/stretchr/testify/require"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/temporalnexus"
"go.temporal.io/sdk/testsuite"
"go.temporal.io/sdk/workflow"
"github.com/temporalio/samples-go/nexus/caller"
"github.com/temporalio/samples-go/nexus/service"
)
var EchoOperation = temporalnexus.NewSyncOperation(service.EchoOperationName, func(ctx context.Context, c client.Client, input service.EchoInput, options nexus.StartOperationOptions) (service.EchoOutput, error) {
// NOTE: the provided client is not usable in the test environment.
return service.EchoOutput(input), nil
})
var HelloOperation = temporalnexus.NewWorkflowRunOperation(service.HelloOperationName, FakeHelloHandlerWorkflow, func(ctx context.Context, input service.HelloInput, options nexus.StartOperationOptions) (client.StartWorkflowOptions, error) {
return client.StartWorkflowOptions{
ID: options.RequestID,
}, nil
})
func FakeHelloHandlerWorkflow(_ workflow.Context, input service.HelloInput) (service.HelloOutput, error) {
return service.HelloOutput{Message: "fake:" + string(input.Language) + ":" + input.Name}, nil
}
func Test_Echo(t *testing.T) {
testSuite := &testsuite.WorkflowTestSuite{}
env := testSuite.NewTestWorkflowEnvironment()
env.RegisterWorkflow(caller.EchoCallerWorkflow)
s := nexus.NewService(service.HelloServiceName)
require.NoError(t, s.Register(EchoOperation))
env.RegisterNexusService(s)
env.ExecuteWorkflow(caller.EchoCallerWorkflow, "hey")
require.True(t, env.IsWorkflowCompleted())
require.NoError(t, env.GetWorkflowError())
var result string
require.NoError(t, env.GetWorkflowResult(&result))
require.Equal(t, "hey", result)
}
func Test_Hello(t *testing.T) {
testSuite := &testsuite.WorkflowTestSuite{}
env := testSuite.NewTestWorkflowEnvironment()
env.RegisterWorkflow(caller.HelloCallerWorkflow)
env.RegisterWorkflow(FakeHelloHandlerWorkflow)
s := nexus.NewService(service.HelloServiceName)
require.NoError(t, s.Register(HelloOperation))
env.RegisterNexusService(s)
env.ExecuteWorkflow(caller.HelloCallerWorkflow, "test", service.DE)
require.True(t, env.IsWorkflowCompleted())
require.NoError(t, env.GetWorkflowError())
var result string
require.NoError(t, env.GetWorkflowResult(&result))
require.Equal(t, "fake:de:test", result)
}