|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require_relative '../spec_helper' |
| 4 | +require OctocatalogDiff::Spec.require_path('/api/v1') |
4 | 5 | require OctocatalogDiff::Spec.require_path('/catalog-util/enc') |
5 | 6 |
|
6 | 7 | describe OctocatalogDiff::CatalogUtil::ENC do |
|
127 | 128 | end |
128 | 129 | end |
129 | 130 |
|
| 131 | + describe '#override_enc_parameters' do |
| 132 | + before(:each) do |
| 133 | + @logger, @logger_str = OctocatalogDiff::Spec.setup_logger |
| 134 | + end |
| 135 | + |
| 136 | + it 'should make no changes if no overrides are specified' do |
| 137 | + subject = described_class.allocate |
| 138 | + subject.instance_variable_set('@options', {}) |
| 139 | + subject.instance_variable_set('@content', "--- {}\n") |
| 140 | + subject.send(:override_enc_parameters, @logger) |
| 141 | + expect(subject.instance_variable_get('@content')).to eq("--- {}\n") |
| 142 | + expect(@logger_str.string).to eq('') |
| 143 | + end |
| 144 | + |
| 145 | + it 'should update @content based on override' do |
| 146 | + options = { |
| 147 | + enc_override: [OctocatalogDiff::API::V1::Override.create_from_input('foo=(string)bar')] |
| 148 | + } |
| 149 | + subject = described_class.allocate |
| 150 | + subject.instance_variable_set('@options', options) |
| 151 | + subject.instance_variable_set('@content', "--- {}\n") |
| 152 | + subject.send(:override_enc_parameters, @logger) |
| 153 | + expect(subject.instance_variable_get('@content')).to eq("---\nfoo: bar\n") |
| 154 | + logs = @logger_str.string.split(/\n/).compact.map { |x| OctocatalogDiff::Spec.strip_log_message(x) } |
| 155 | + expect(logs).to include('DEBUG - ENC override: foo = "bar"') |
| 156 | + end |
| 157 | + end |
| 158 | + |
130 | 159 | describe '#merge_enc_param' do |
131 | 160 | before(:each) do |
132 | 161 | @logger, @logger_str = OctocatalogDiff::Spec.setup_logger |
|
155 | 184 | expect(struct['stuffs']).to eq('baz4') |
156 | 185 | end |
157 | 186 |
|
| 187 | + it 'should add a multi-depth parameter at the top level' do |
| 188 | + struct = { |
| 189 | + 'parameters' => { |
| 190 | + 'foo' => 'bar', |
| 191 | + 'baz' => 'fuzz' |
| 192 | + } |
| 193 | + } |
| 194 | + @subject.send(:merge_enc_param, struct, 'stuffs::morestuffs', 'baz4') |
| 195 | + expect(struct['stuffs']['morestuffs']).to eq('baz4') |
| 196 | + end |
| 197 | + |
158 | 198 | it 'should remove a parameter at the top level' do |
159 | 199 | struct = { |
160 | 200 | 'parameters' => { |
|
0 commit comments