|
126 | 126 | end |
127 | 127 | end |
128 | 128 | end |
| 129 | + |
| 130 | + describe '#merge_enc_param' do |
| 131 | + before(:each) do |
| 132 | + @logger, @logger_str = OctocatalogDiff::Spec.setup_logger |
| 133 | + @subject = described_class.allocate |
| 134 | + end |
| 135 | + |
| 136 | + it 'should replace a parameter at the top level' do |
| 137 | + struct = { |
| 138 | + 'parameters' => { |
| 139 | + 'foo' => 'bar', |
| 140 | + 'baz' => 'fuzz' |
| 141 | + } |
| 142 | + } |
| 143 | + @subject.send(:merge_enc_param, struct, 'parameters', 'baz4') |
| 144 | + expect(struct['parameters']).to eq('baz4') |
| 145 | + end |
| 146 | + |
| 147 | + it 'should add a parameter at the top level' do |
| 148 | + struct = { |
| 149 | + 'parameters' => { |
| 150 | + 'foo' => 'bar', |
| 151 | + 'baz' => 'fuzz' |
| 152 | + } |
| 153 | + } |
| 154 | + @subject.send(:merge_enc_param, struct, 'stuffs', 'baz4') |
| 155 | + expect(struct['stuffs']).to eq('baz4') |
| 156 | + end |
| 157 | + |
| 158 | + it 'should remove a parameter at the top level' do |
| 159 | + struct = { |
| 160 | + 'parameters' => { |
| 161 | + 'foo' => 'bar', |
| 162 | + 'baz' => 'fuzz' |
| 163 | + } |
| 164 | + } |
| 165 | + @subject.send(:merge_enc_param, struct, 'parameters', nil) |
| 166 | + expect(struct).to eq({}) |
| 167 | + end |
| 168 | + |
| 169 | + it 'should error if breaking the structure' do |
| 170 | + struct = { |
| 171 | + 'parameters' => { |
| 172 | + 'foo' => 'bar', |
| 173 | + 'baz' => 'fuzz' |
| 174 | + } |
| 175 | + } |
| 176 | + expect do |
| 177 | + @subject.send(:merge_enc_param, struct, 'parameters::foo::baz3', 'baz4') |
| 178 | + end.to raise_error(ArgumentError, /Attempt to override String with hash for foo::baz3/) |
| 179 | + end |
| 180 | + |
| 181 | + it 'should overwrite a key nested in a hash with same datatype' do |
| 182 | + struct = { |
| 183 | + 'parameters' => { |
| 184 | + 'foo' => 'bar', |
| 185 | + 'baz' => 'fuzz' |
| 186 | + } |
| 187 | + } |
| 188 | + @subject.send(:merge_enc_param, struct, 'parameters::foo', 'baz4') |
| 189 | + expect(struct['parameters']['foo']).to eq('baz4') |
| 190 | + end |
| 191 | + |
| 192 | + it 'should overwrite a key nested in a hash with different datatype' do |
| 193 | + struct = { |
| 194 | + 'parameters' => { |
| 195 | + 'foo' => 'bar', |
| 196 | + 'baz' => 'fuzz' |
| 197 | + } |
| 198 | + } |
| 199 | + @subject.send(:merge_enc_param, struct, 'parameters::foo', %w(kittens puppies)) |
| 200 | + expect(struct['parameters']['foo']).to eq(%w(kittens puppies)) |
| 201 | + end |
| 202 | + |
| 203 | + it 'should delete a key nested in a hash' do |
| 204 | + struct = { |
| 205 | + 'parameters' => { |
| 206 | + 'foo' => 'bar', |
| 207 | + 'baz' => 'fuzz' |
| 208 | + } |
| 209 | + } |
| 210 | + @subject.send(:merge_enc_param, struct, 'parameters::foo', nil) |
| 211 | + expect(struct['parameters'].key?('foo')).to eq(false) |
| 212 | + end |
| 213 | + |
| 214 | + it 'should overwrite a key nested deeply in a hash with same datatype' do |
| 215 | + struct = { |
| 216 | + 'parameters' => { |
| 217 | + 'foo' => { 'bar' => { 'baz' => 'chicken' } }, |
| 218 | + 'baz' => 'fuzz' |
| 219 | + } |
| 220 | + } |
| 221 | + @subject.send(:merge_enc_param, struct, 'parameters::foo::bar::baz', 'turkey') |
| 222 | + expect(struct['parameters']['foo']['bar']['baz']).to eq('turkey') |
| 223 | + end |
| 224 | + end |
129 | 225 | end |
0 commit comments