Skip to content

Commit

Permalink
Fix broken specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ngetahun committed Jan 3, 2024
1 parent 2ecb518 commit 30afcb3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/rmt/cli/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def repos(path)
path = needs_path(path, writable: true)

mirror = RMT::Mirror::Repomd.new(mirroring_base_dir: path, logger: logger, airgap_mode: true)

suma_product_tree = RMT::Mirror::SumaProductTree.new(mirroring_base_dir: path, logger: logger)
begin
mirror.mirror_suma_product_tree(repository_url: 'https://scc.suse.com/suma/')
suma_product_tree.mirror
rescue RMT::Mirror::Exception => e
logger.warn(e.message)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/rmt/cli/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def repos(path)
begin
exported_suma_path = File.join(path, '/suma/')
suma_repo_url = URI.join('file://', exported_suma_path).to_s
mirror.mirror_suma_product_tree(repository_url: suma_repo_url)
suma_product_tree = RMT::Mirror::SumaProductTree.new(mirroring_base_dir: exported_suma_path, logger: logger, url: suma_repo_url)
suma_product_tree.mirror
rescue RMT::Mirror::Exception => e
logger.warn(e.message)
end
Expand Down
12 changes: 7 additions & 5 deletions spec/lib/rmt/cli/export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

let(:command) { described_class.start(['repos', path]) }
let(:mirror_double) { instance_double('RMT::Mirror::Repomd') }
let(:suma_product_tree_double) { instance_double('RMT::Mirror::SumaProductTree') }
let(:repo_settings) do
[
{ url: 'http://foo.bar/repo1', auth_token: 'foobar' },
Expand All @@ -77,7 +78,7 @@

context 'suma product tree mirror with exception' do
it 'outputs exception message' do
expect_any_instance_of(RMT::Mirror::Repomd).to receive(:mirror_suma_product_tree).and_raise(RMT::Mirror::Exception, 'black mirror')
expect_any_instance_of(RMT::Mirror::SumaProductTree).to receive(:mirror).and_raise(RMT::Mirror::Exception, 'black mirror')
expect_any_instance_of(RMT::Mirror::Repomd).to receive(:mirror).twice

FileUtils.mkdir_p path
Expand All @@ -92,7 +93,7 @@
it 'outputs a warning' do
FileUtils.mkdir_p path

expect_any_instance_of(RMT::Mirror::Repomd).to receive(:mirror_suma_product_tree)
expect_any_instance_of(RMT::Mirror::SumaProductTree).to receive(:mirror)
expect { command }.to raise_error(SystemExit).and(output("#{File.join(path, 'repos.json')} does not exist.\n").to_stderr)
end
end
Expand All @@ -112,7 +113,7 @@
FileUtils.mkdir_p path
File.write('/mnt/usb/repos.json', repo_settings.to_json)

expect(mirror_double).to receive(:mirror_suma_product_tree)
expect_any_instance_of(RMT::Mirror::SumaProductTree).to receive(:mirror)
expect(mirror_double).to receive(:mirror).with(
repository_url: 'http://foo.bar/repo1',
auth_token: 'foobar',
Expand Down Expand Up @@ -142,7 +143,7 @@
FileUtils.mkdir_p path
File.write("#{path}/repos.json", repo_settings.to_json)

expect(mirror_double).to receive(:mirror_suma_product_tree)
expect_any_instance_of(RMT::Mirror::SumaProductTree).to receive(:mirror)
expect(mirror_double).to receive(:mirror).with(
repository_url: 'http://foo.bar/repo1',
auth_token: 'foobar',
Expand All @@ -163,7 +164,8 @@
FileUtils.mkdir_p path
File.write("#{path}/repos.json", repo_settings.to_json)

expect(mirror_double).to receive(:mirror_suma_product_tree).with({ repository_url: 'https://scc.suse.com/suma/' })

expect_any_instance_of(RMT::Mirror::SumaProductTree).to receive(:mirror)
expect(mirror_double).to receive(:mirror).with(
repository_url: 'http://foo.bar/repo1',
auth_token: 'foobar',
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/rmt/cli/import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
airgap_mode: true
).and_return(mirror_double)

expect(mirror_double).to receive(:mirror_suma_product_tree)
expect_any_instance_of(RMT::Mirror::SumaProductTree).to receive(:mirror)
expect(mirror_double).to receive(:mirror).with(
repository_url: repo1_local_path,
local_path: Repository.make_local_path(repo1.external_url),
Expand Down Expand Up @@ -96,7 +96,7 @@
airgap_mode: true
).and_return(mirror_double)

expect(mirror_double).to receive(:mirror_suma_product_tree)
expect_any_instance_of(RMT::Mirror::SumaProductTree).to receive(:mirror)
expect(mirror_double).to receive(:mirror).with(
repository_url: repo1_local_path,
local_path: Repository.make_local_path(repo1.external_url),
Expand Down Expand Up @@ -124,7 +124,7 @@

context 'suma product tree mirror with exception' do
it 'outputs exception message' do
expect_any_instance_of(RMT::Mirror::Repomd).to receive(:mirror_suma_product_tree).and_raise(RMT::Mirror::Exception, 'black mirror')
expect_any_instance_of(RMT::Mirror::SumaProductTree).to receive(:mirror).and_raise(RMT::Mirror::Exception, 'black mirror')
expect_any_instance_of(RMT::Mirror::Repomd).to receive(:mirror).twice

FileUtils.mkdir_p path
Expand All @@ -148,7 +148,7 @@
FileUtils.mkdir_p path
File.write("#{path}/repos.json", repo_settings.to_json)

expect_any_instance_of(RMT::Mirror::Repomd).to receive(:mirror_suma_product_tree)
expect_any_instance_of(RMT::Mirror::SumaProductTree).to receive(:mirror)
expect { command }.to output(/repository by URL #{missing_repo_url} does not exist in database/).to_stderr.and output('').to_stdout
end
end
Expand All @@ -170,7 +170,7 @@
airgap_mode: true
).and_return(mirror_double)

expect(mirror_double).to receive(:mirror_suma_product_tree)
expect_any_instance_of(RMT::Mirror::SumaProductTree).to receive(:mirror)
expect(mirror_double).to receive(:mirror).with(
repository_url: repo1_local_path,
local_path: Repository.make_local_path(repo1.external_url),
Expand Down

0 comments on commit 30afcb3

Please sign in to comment.