Skip to content

Commit 3cb74c7

Browse files
author
Kevin Paulisse
committed
Add unit test coverage of ENC override
1 parent 5514192 commit 3cb74c7

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

spec/octocatalog-diff/tests/catalog-util/enc_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require_relative '../spec_helper'
4+
require OctocatalogDiff::Spec.require_path('/api/v1')
45
require OctocatalogDiff::Spec.require_path('/catalog-util/enc')
56

67
describe OctocatalogDiff::CatalogUtil::ENC do
@@ -127,6 +128,34 @@
127128
end
128129
end
129130

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+
130159
describe '#merge_enc_param' do
131160
before(:each) do
132161
@logger, @logger_str = OctocatalogDiff::Spec.setup_logger
@@ -155,6 +184,17 @@
155184
expect(struct['stuffs']).to eq('baz4')
156185
end
157186

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+
158198
it 'should remove a parameter at the top level' do
159199
struct = {
160200
'parameters' => {

0 commit comments

Comments
 (0)