Skip to content

Commit

Permalink
fix product registration finish
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 8, 2025
1 parent 3850472 commit 0cedb6a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion service/lib/agama/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def deregister
def finish
return unless reg_code

files = [credentials_path(@credentials_file), SUSE::Connect::YaST::GLOBAL_CREDENTIALS_PATH]
files = [GLOBAL_CREDENTIALS_PATH]
files << credentials_path(@credentials_file) if @credentials_file

files.each do |file|
dest = File.join(Yast::Installation.destdir, file)
FileUtils.cp(file, dest)
Expand Down
36 changes: 36 additions & 0 deletions service/test/agama/registration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
subject { described_class.new(manager, logger) }

let(:manager) { instance_double(Agama::Software::Manager) }
let(:product) { Agama::Software::Product.new("test").tap { |p| p.version = "5.0" } }

let(:logger) { Logger.new($stdout, level: :warn) }

Expand Down Expand Up @@ -375,4 +376,39 @@
end
end
end

describe "#finish" do
context "system is not registered" do
before do
subject.instance_variable_set(:@reg_code, nil)
end

it "do nothing" do
expect(::FileUtils).to_not receive(:cp)

subject.finish
end
end

context "system is registered" do
before do
subject.instance_variable_set(:@reg_code, "test")
subject.instance_variable_set(:@credentials_file, "test")
Yast::Installation.destdir = "/mnt"
allow(::FileUtils).to receive(:cp)
end

it "copies global credentials file" do
expect(::FileUtils).to receive(:cp).with("/etc/zypp/credentials.d/SCCcredentials", "/mnt/etc/zypp/credentials.d/SCCcredentials")

subject.finish
end

it "copies product credentials file" do
expect(::FileUtils).to receive(:cp).with("/etc/zypp/credentials.d/test", "/mnt/etc/zypp/credentials.d/test")

subject.finish
end
end
end
end

0 comments on commit 0cedb6a

Please sign in to comment.