Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/vanagon/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,14 @@ def get_dependency_hash
# @param workdir [String] working directory to put the source into
def get_sources(workdir) # rubocop:disable Metrics/AbcSize
sources.each do |source|
src = Vanagon::Component::Source.source(
source.url, workdir: workdir, ref: source.ref, sum: source.sum
)
options = source.to_h # Copy OpenStruct to Hash.
url = options.delete(:url)
erb = options.delete(:erb)
options[:workdir] = workdir
src = Vanagon::Component::Source.source(url, **options)
src.fetch
src.verify
if source.erb
if erb
erb_file(src.file, File.join(File.dirname(src.file), File.basename(src.file, ".erb")), true)
end
# set src.file to only be populated with the basename instead of entire file path
Expand Down
6 changes: 3 additions & 3 deletions lib/vanagon/component/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ def dirname(path)
# This will add a source to the project and put it in the workdir alongside the other sources
#
# @param uri [String] uri of the source
# @param [Hash] options optional keyword arguments used to instatiate a new source
# @option opts [String] :sum
# @option opts [String] :ref
# @param [Hash] options optional keyword arguments used to instatiate a new source.
# See {Vanagon::Component::Source::Local}, {Vanagon::Component::Source::Git},
# and {Vanagon::Component::Source::Http} for details.
# @option opts [Bool] :erb set to 'true' to specify that the source file should be
# translated by erb
def add_source(uri, options = {})
Expand Down
22 changes: 22 additions & 0 deletions spec/lib/vanagon/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,28 @@
expect(subject).to_not receive(:erb_file)
subject.get_sources(@workdir)
end

it "Allows checksum types to be specified" do
plat = Vanagon::Platform::DSL.new('el-10-x86_64')
plat.instance_eval("platform 'el-10-x86_64' do |plat| end")
@platform = plat._platform

comp = Vanagon::Component::DSL.new('build-dir-test', {}, @platform)
comp.add_source @fake_file,
# Checksum of spec/fixtures/files/fake_file.txt
sum: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
sum_type: 'sha256'
subject = comp._component

# Not the best test as local files don't execute verification logic.
# However, properly mocking the download logic of a HTTP source would
# require a re-write of the class.
expect(Vanagon::Component::Source).to receive(:source)
.with(anything, hash_including(sum_type: 'sha256'))
.and_call_original

subject.get_sources(@workdir)
end
end

describe "#get_patches" do
Expand Down