forked from coinbase/temporal-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_attributes_spec.rb
70 lines (57 loc) · 2.02 KB
/
search_attributes_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
require 'temporal/errors'
describe 'search attributes' do
let(:attribute_1) { 'Age' }
let(:attribute_2) { 'Name' }
def cleanup
custom_attributes = Temporal.list_custom_search_attributes
custom_attributes.keys.intersection([attribute_1, attribute_2]).each do |attribute|
Temporal.remove_custom_search_attributes(attribute)
end
end
before do
cleanup
end
after do
cleanup
end
# Depending on the visibility storage backend of the server, recreating a search attribute
# is either ignored so long as the tpe is the same (Elastic Search) or it raises
# an error (SQL). This function ensures consistent state upon exit.
def safe_add(attributes)
begin
Temporal.add_custom_search_attributes(attributes)
rescue => e
# This won't always throw but when it does it needs to be of this type
expect(e).to be_instance_of(Temporal::SearchAttributeAlreadyExistsFailure)
end
end
it 'add' do
safe_add({ attribute_1 => :int, attribute_2 => :keyword })
custom_attributes = Temporal.list_custom_search_attributes
expect(custom_attributes).to include(attribute_1 => :int)
expect(custom_attributes).to include(attribute_2 => :keyword)
end
it 'add duplicate fails' do
safe_add({ attribute_1 => :int })
# This, however, will always throw
expect do
Temporal.add_custom_search_attributes(
{
attribute_1 => :int
}
)
end.to raise_error(Temporal::SearchAttributeAlreadyExistsFailure)
end
it 'remove' do
safe_add({ attribute_1 => :int, attribute_2 => :keyword })
Temporal.remove_custom_search_attributes(attribute_1, attribute_2)
custom_attributes = Temporal.list_custom_search_attributes
expect(custom_attributes).not_to include(attribute_1 => :int)
expect(custom_attributes).not_to include(attribute_2 => :keyword)
end
it 'remove non-existent fails' do
expect do
Temporal.remove_custom_search_attributes(attribute_1, attribute_2)
end.to raise_error(Temporal::NotFoundFailure)
end
end