|
17 | 17 |
|
18 | 18 | before do |
19 | 19 | # in memory setup |
20 | | - repository.update([{name: 'foo', trafficTypeName: 'tt_name_1'}, |
21 | | - {name: 'bar', trafficTypeName: 'tt_name_2'}, |
22 | | - {name: 'baz', trafficTypeName: 'tt_name_1'}], [], -1) |
| 20 | + repository.update([{name: 'foo', trafficTypeName: 'tt_name_1', conditions: []}, |
| 21 | + {name: 'bar', trafficTypeName: 'tt_name_2', conditions: []}, |
| 22 | + {name: 'baz', trafficTypeName: 'tt_name_1', conditions: []}], [], -1) |
23 | 23 |
|
24 | 24 | # redis setup |
25 | 25 | repository.instance_variable_get(:@adapter).set_string( |
|
31 | 31 | end |
32 | 32 |
|
33 | 33 | after do |
34 | | - repository.update([], [{name: 'foo', trafficTypeName: 'tt_name_1'}, |
35 | | - {name: 'bar', trafficTypeName: 'tt_name_2'}, |
36 | | - {name: 'bar', trafficTypeName: 'tt_name_2'}, |
37 | | - {name: 'qux', trafficTypeName: 'tt_name_3'}, |
38 | | - {name: 'quux', trafficTypeName: 'tt_name_4'}, |
39 | | - {name: 'corge', trafficTypeName: 'tt_name_5'}, |
40 | | - {name: 'corge', trafficTypeName: 'tt_name_6'}], -1) |
| 34 | + repository.update([], [{name: 'foo', trafficTypeName: 'tt_name_1', conditions: []}, |
| 35 | + {name: 'bar', trafficTypeName: 'tt_name_2', conditions: []}, |
| 36 | + {name: 'bar', trafficTypeName: 'tt_name_2', conditions: []}, |
| 37 | + {name: 'qux', trafficTypeName: 'tt_name_3', conditions: []}, |
| 38 | + {name: 'quux', trafficTypeName: 'tt_name_4', conditions: []}, |
| 39 | + {name: 'corge', trafficTypeName: 'tt_name_5', conditions: []}, |
| 40 | + {name: 'corge', trafficTypeName: 'tt_name_6', conditions: []}], -1) |
41 | 41 | end |
42 | 42 |
|
43 | 43 | it 'returns splits names' do |
|
52 | 52 | expect(repository.traffic_type_exists('tt_name_1')).to be true |
53 | 53 | expect(repository.traffic_type_exists('tt_name_2')).to be true |
54 | 54 |
|
55 | | - split = { name: 'qux', trafficTypeName: 'tt_name_3' } |
| 55 | + split = { name: 'qux', trafficTypeName: 'tt_name_3', conditions: [] } |
56 | 56 |
|
57 | 57 | repository.update([split], [], -1) |
58 | 58 | repository.update([], [split], -1) |
|
61 | 61 | end |
62 | 62 |
|
63 | 63 | it 'does not increment traffic type count when adding same split twice' do |
64 | | - split = { name: 'quux', trafficTypeName: 'tt_name_4' } |
| 64 | + split = { name: 'quux', trafficTypeName: 'tt_name_4', conditions: [] } |
65 | 65 |
|
66 | 66 | repository.update([split, split], [], -1) |
67 | 67 | repository.update([], [split], -1) |
|
70 | 70 | end |
71 | 71 |
|
72 | 72 | it 'updates traffic type count accordingly when split changes traffic type' do |
73 | | - split = { name: 'corge', trafficTypeName: 'tt_name_5' } |
| 73 | + split = { name: 'corge', trafficTypeName: 'tt_name_5', conditions: [] } |
74 | 74 |
|
75 | 75 | repository.update([split], [], -1) |
76 | 76 | repository.instance_variable_get(:@adapter).set_string( |
|
79 | 79 |
|
80 | 80 | expect(repository.traffic_type_exists('tt_name_5')).to be true |
81 | 81 |
|
82 | | - split = { name: 'corge', trafficTypeName: 'tt_name_6' } |
| 82 | + split = { name: 'corge', trafficTypeName: 'tt_name_6', conditions: [] } |
83 | 83 |
|
84 | 84 | repository.update([split], [], -1) |
85 | 85 |
|
|
97 | 97 |
|
98 | 98 | it 'returns splits data' do |
99 | 99 | expect(repository.splits).to eq( |
100 | | - 'foo' => { name: 'foo', trafficTypeName: 'tt_name_1' }, |
101 | | - 'bar' => { name: 'bar', trafficTypeName: 'tt_name_2' }, |
102 | | - 'baz' => { name: 'baz', trafficTypeName: 'tt_name_1' } |
| 100 | + 'foo' => { name: 'foo', trafficTypeName: 'tt_name_1', conditions: [] }, |
| 101 | + 'bar' => { name: 'bar', trafficTypeName: 'tt_name_2', conditions: [] }, |
| 102 | + 'baz' => { name: 'baz', trafficTypeName: 'tt_name_1', conditions: [] } |
103 | 103 | ) |
104 | 104 | end |
| 105 | + |
| 106 | + it 'remove undefined matcher with template condition' do |
| 107 | + split = { name: 'corge', trafficTypeName: 'tt_name_5', conditions: [ |
| 108 | + { |
| 109 | + partitions: [ |
| 110 | + {treatment: 'on', size: 50}, |
| 111 | + {treatment: 'off', size: 50} |
| 112 | + ], |
| 113 | + contitionType: 'WHITELIST', |
| 114 | + label: 'some_label', |
| 115 | + matcherGroup: { |
| 116 | + matchers: [ |
| 117 | + { |
| 118 | + matcherType: 'UNDEFINED', |
| 119 | + whitelistMatcherData: { |
| 120 | + whitelist: ['k1', 'k2', 'k3'] |
| 121 | + }, |
| 122 | + negate: false, |
| 123 | + } |
| 124 | + ], |
| 125 | + combiner: 'AND' |
| 126 | + } |
| 127 | + }] |
| 128 | + } |
| 129 | + repository.update([split], [], -1) |
| 130 | + expect(repository.get_split('corge')[:conditions]).to eq SplitIoClient::Cache::Repositories::SplitsRepository::DEFAULT_CONDITIONS_TEMPLATE |
| 131 | + |
| 132 | + # test with multiple conditions |
| 133 | + split2 = { |
| 134 | + name: 'corge2', |
| 135 | + trafficTypeName: 'tt_name_5', |
| 136 | + conditions: [ |
| 137 | + { |
| 138 | + partitions: [ |
| 139 | + {treatment: 'on', size: 50}, |
| 140 | + {treatment: 'off', size: 50} |
| 141 | + ], |
| 142 | + contitionType: 'WHITELIST', |
| 143 | + label: 'some_label', |
| 144 | + matcherGroup: { |
| 145 | + matchers: [ |
| 146 | + { |
| 147 | + matcherType: 'UNDEFINED', |
| 148 | + whitelistMatcherData: { |
| 149 | + whitelist: ['k1', 'k2', 'k3'] |
| 150 | + }, |
| 151 | + negate: false, |
| 152 | + } |
| 153 | + ], |
| 154 | + combiner: 'AND' |
| 155 | + } |
| 156 | + }, |
| 157 | + { |
| 158 | + partitions: [ |
| 159 | + {treatment: 'on', size: 25}, |
| 160 | + {treatment: 'off', size: 75} |
| 161 | + ], |
| 162 | + contitionType: 'WHITELIST', |
| 163 | + label: 'some_other_label', |
| 164 | + matcherGroup: { |
| 165 | + matchers: [{matcherType: 'ALL_KEYS', negate: false}], |
| 166 | + combiner: 'AND' |
| 167 | + } |
| 168 | + }] |
| 169 | + } |
| 170 | + |
| 171 | + repository.update([split2], [], -1) |
| 172 | + expect(repository.get_split('corge2')[:conditions]).to eq SplitIoClient::Cache::Repositories::SplitsRepository::DEFAULT_CONDITIONS_TEMPLATE |
| 173 | + end |
105 | 174 | end |
106 | 175 |
|
107 | 176 | describe 'with Memory Adapter' do |
|
0 commit comments