Skip to content

Commit

Permalink
feat: configure SUMA product tree base URL
Browse files Browse the repository at this point in the history
Allow user to configure the SUMA product tree base URL in RMT's config
file `mirroring.suma_product_tree_base_url` attribute. The configured
value takes precedence over the default (https://scc.suse.com/suma/).
  • Loading branch information
lcaparroz committed Dec 23, 2024
1 parent b0db3be commit 05122c4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/rmt/mirror/suma_product_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ class RMT::Mirror::SumaProductTree

attr_reader :mirroring_base_dir, :url, :logger

def initialize(logger:, mirroring_base_dir:, url: FILE_URL)
def initialize(logger:, mirroring_base_dir:, url: nil)
@mirroring_base_dir = mirroring_base_dir
@url = url
@url = url || Settings.try(:mirroring).try(:suma_product_tree_base_url) || FILE_URL
@logger = logger
end

Expand Down
38 changes: 32 additions & 6 deletions spec/lib/rmt/mirror/suma_product_tree_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let(:ref_configuration) do
{
relative_path: 'product_tree.json',
base_url: described_class::FILE_URL,
base_url: base_url,
cache_dir: nil,
base_dir: File.join(base_dir, '/suma/')
}
Expand All @@ -21,11 +21,7 @@
let(:base_dir) { '/tmp' }
let(:downloader) { instance_double RMT::Downloader }

describe '#mirror' do
before do
allow(RMT::Downloader).to receive(:new).and_return downloader
end

shared_examples 'mirror SUMA product tree' do
it 'mirrors the product_tree file' do
expect(RMT::Mirror::FileReference).to receive(:new).with(**ref_configuration)
expect(downloader).to receive(:download_multi)
Expand All @@ -48,4 +44,34 @@
end
end
end

describe '#mirror' do
before do
allow(RMT::Downloader).to receive(:new).and_return downloader
end

context 'with default SUMA product tree URL' do
before do
allow(Settings).to receive(:try).with(:mirroring).and_return(nil)
end

it_behaves_like 'mirror SUMA product tree' do
let(:base_url) { 'https://scc.suse.com/suma/' }
end
end

context 'with custom SUMA product tree URL' do
before do
allow(Settings).to receive(:try).with(:mirroring).and_return(mirroring_configuration)
allow(mirroring_configuration).to receive(:try)
.with(:suma_product_tree_base_url).and_return(base_url)
end

let(:mirroring_configuration) { instance_double(Config::Options) }

it_behaves_like 'mirror SUMA product tree' do
let(:base_url) { 'http://localhost:3000/suma/' }
end
end
end
end

0 comments on commit 05122c4

Please sign in to comment.