Skip to content

Commit c018457

Browse files
committed
Pass full options hashes from component.add_source
Prior to this commit, the `add_source` method of the would accept any number of keyword arguments, but silently ignored any that were not `ref` or `sum`. The Git and Http sources accept many options, critically `sum_type` which allows checksums other than MD5 to be used. This commit updates the logic in `lib/vanagon/component.rb` to ensure all options are passed to the source constructor. Signed-off-by: Charlie Sharpsteen <charlie@overlookinfratech.com>
1 parent 626cdfb commit c018457

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

lib/vanagon/component.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,14 @@ def get_dependency_hash
360360
# @param workdir [String] working directory to put the source into
361361
def get_sources(workdir) # rubocop:disable Metrics/AbcSize
362362
sources.each do |source|
363-
src = Vanagon::Component::Source.source(
364-
source.url, workdir: workdir, ref: source.ref, sum: source.sum
365-
)
363+
options = source.to_h # Convert OpenStruct to hash.
364+
url = options.delete(:url)
365+
erb = options.delete(:erb)
366+
options[:workdir] = workdir
367+
src = Vanagon::Component::Source.source(url, **options)
366368
src.fetch
367369
src.verify
368-
if source.erb
370+
if erb
369371
erb_file(src.file, File.join(File.dirname(src.file), File.basename(src.file, ".erb")), true)
370372
end
371373
# set src.file to only be populated with the basename instead of entire file path

lib/vanagon/component/dsl.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,9 @@ def dirname(path)
406406
# This will add a source to the project and put it in the workdir alongside the other sources
407407
#
408408
# @param uri [String] uri of the source
409-
# @param [Hash] options optional keyword arguments used to instatiate a new source
410-
# @option opts [String] :sum
411-
# @option opts [String] :ref
409+
# @param [Hash] options optional keyword arguments used to instatiate a new source.
410+
# See {Vanagon::Component::Source::Local}, {Vanagon::Component::Source::Git},
411+
# and {Vanagon::Component::Source::Http} for details.
412412
# @option opts [Bool] :erb set to 'true' to specify that the source file should be
413413
# translated by erb
414414
def add_source(uri, options = {})

spec/lib/vanagon/component_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,28 @@
217217
expect(subject).to_not receive(:erb_file)
218218
subject.get_sources(@workdir)
219219
end
220+
221+
it "Allows checksum types to be specified" do
222+
plat = Vanagon::Platform::DSL.new('el-10-x86_64')
223+
plat.instance_eval("platform 'el-10-x86_64' do |plat| end")
224+
@platform = plat._platform
225+
226+
comp = Vanagon::Component::DSL.new('build-dir-test', {}, @platform)
227+
comp.add_source @fake_file,
228+
# Checksum of spec/fixtures/files/fake_file.txt
229+
sum: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
230+
sum_type: 'sha256'
231+
subject = comp._component
232+
233+
# Not the best test as local files don't execute verification logic.
234+
# However, properly mocking the download logic of a HTTP source would
235+
# require a re-write of the class.
236+
expect(Vanagon::Component::Source).to receive(:source)
237+
.with(anything, hash_including(sum_type: 'sha256'))
238+
.and_call_original
239+
240+
subject.get_sources(@workdir)
241+
end
220242
end
221243

222244
describe "#get_patches" do

0 commit comments

Comments
 (0)