-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmy_workflow_test.rb
40 lines (36 loc) · 1.16 KB
/
my_workflow_test.rb
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
# frozen_string_literal: true
require 'test'
require 'activity_simple/my_workflow'
require 'securerandom'
require 'temporalio/testing'
require 'temporalio/worker'
module ActivitySimple
class ActivitySimpleTest < Test
# Demonstrates mocking out activities
class MockSelectFromDatabase < Temporalio::Activity::Definition
activity_name :SelectFromDatabase
def execute(table)
"mocked value from #{table}"
end
end
def test_workflow
# Run test server until completion of the block
Temporalio::Testing::WorkflowEnvironment.start_local do |env|
# Run worker until completion of the block
worker = Temporalio::Worker.new(
client: env.client,
task_queue: "tq-#{SecureRandom.uuid}",
activities: [MockSelectFromDatabase, MyActivities::AppendSuffix],
workflows: [MyWorkflow]
)
worker.run do
# Run workflow
assert_equal(
'mocked value from some-db-table <appended-value>',
env.client.execute_workflow(MyWorkflow, id: "wf-#{SecureRandom.uuid}", task_queue: worker.task_queue)
)
end
end
end
end
end