forked from coinbase/temporal-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter_spec.rb
72 lines (58 loc) · 2.34 KB
/
converter_spec.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
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
71
72
require 'workflows/hello_world_workflow'
require 'lib/cryptconverter'
require 'grpc/errors'
describe 'Converter', :integration do
around(:each) do |example|
task_queue = Temporal.configuration.task_queue
Temporal.configure do |config|
config.task_queue = 'crypt'
config.converter = Temporal::CryptConverter.new(
payload_converter: Temporal::Configuration::DEFAULT_CONVERTER
)
end
example.run
ensure
Temporal.configure do |config|
config.task_queue = task_queue
config.converter = Temporal::Configuration::DEFAULT_CONVERTER
end
end
it 'can encrypt payloads' do
workflow_id, run_id = run_workflow(HelloWorldWorkflow, 'Tom')
begin
wait_for_workflow_completion(workflow_id, run_id)
rescue GRPC::DeadlineExceeded
raise "Encrypted-payload workflow didn't run. Make sure you run USE_ENCRYPTION=1 ./bin/worker and try again."
end
result = fetch_history(workflow_id, run_id)
events = result.history.events.group_by(&:event_type)
events[:EVENT_TYPE_WORKFLOW_EXECUTION_STARTED].map do |event|
input = event.workflow_execution_started_event_attributes.input
input.payloads.each do |payload|
expect(payload.metadata['encoding']).to eq('binary/encrypted')
end
end
events[:EVENT_TYPE_ACTIVITY_TASK_SCHEDULED].map do |event|
input = event.activity_task_scheduled_event_attributes.input
input.payloads.each do |payload|
expect(payload.metadata['encoding']).to eq('binary/encrypted')
end
end
events[:EVENT_TYPE_ACTIVITY_TASK_COMPLETED].map do |event|
result = event.activity_task_completed_event_attributes.result
result.payloads.each do |payload|
expect(payload.metadata['encoding']).to eq('binary/encrypted')
end
end
events[:EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED].map do |event|
result = event.workflow_execution_completed_event_attributes.result
result.payloads.each do |payload|
expect(payload.metadata['encoding']).to eq('binary/encrypted')
end
end
completion_event = events[:EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED].first
result = completion_event.workflow_execution_completed_event_attributes.result
converter = Temporal.configuration.converter
expect(converter.from_payloads(result)&.first).to eq('Hello World, Tom')
end
end