Skip to content

Commit

Permalink
feat(ruby): implement the SourceProbeError callback
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jan 22, 2025
1 parent 486829f commit d4e66d3
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 4 deletions.
44 changes: 44 additions & 0 deletions service/lib/agama/software/callbacks/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def setup
Pkg.CallbackSourceCreateError(
fun_ref(method(:source_create_error), "symbol (string, symbol, string)")
)
Pkg.CallbackSourceProbeError(
fun_ref(method(:source_probe_error), "symbol (string, symbol, string)")
)
end

# Create source error callback
Expand Down Expand Up @@ -90,6 +93,47 @@ def source_create_error(url, error, description)
end
end

# Probe source error callback
#
# @param url [String] Source URL
# @param error [Symbol] Error (:NOT_FOUND, :IO, :INVALID, :NO_ERROR, :REJECTED)
# @param description [String] Problem description.
# @return [Symbol] :RETRY or :ABORT (not implemented)
def source_probe_error(url, error, description)
logger.debug(
format(
"Source probe: error: url: %s, error: %s, description: %s",
Yast::URL.HidePassword(url),
error,
description
)
)
message =
case error
when :NOT_FOUND
_("Unable to retrieve the remote repository description.")
when :IO
_("An error occurred while retrieving the new metadata.")
when :INVALID
_("The repository is not valid.")
when :NO_ERROR
_("Repository probing details.")
when :REJECTED
_("Repository metadata is invalid.")
end

question = Agama::Question.new(
qclass: "software.source_probe_error",
text: message,
options: [:Retry],
default_option: :Retry,
data: { "url" => url, "description" => description }
)
questions_client.ask(question) do |_question_client|
:RETRY
end
end

private

# @return [Agama::DBus::Clients::Questions]
Expand Down
44 changes: 40 additions & 4 deletions service/test/agama/software/callbacks/source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

let(:answer) { :Retry }

let(:url) { "https://example.net/repo" }

let(:description) { "Some description" }

describe "#source_create_error" do
before do
allow(questions_client).to receive(:ask).and_yield(question_client)
Expand All @@ -42,16 +46,48 @@
let(:question_client) { instance_double(Agama::DBus::Clients::Question) }

it "registers a question with the details" do
expect(questions_client).to_not receive(:ask)
subject.source_create_error("https://example.net/repo", :NOT_FOUND, "Some description")
expect(questions_client).to receive(:ask) do |q|
expect(q.text).to include("Unable to retrieve")
expect(q.data).to include(
"url" => url, "description" => description
)
end
subject.source_create_error(url, :NOT_FOUND, description)
end

context "when the user answers :Retry" do
let(:answer) { :Retry }

it "returns 'R'" do
ret = subject.source_create_error(url, :NOT_FOUND, description)
expect(ret).to eq(:RETRY)
end
end
end

describe "#source_probe_error" do
before do
allow(questions_client).to receive(:ask).and_yield(question_client)
allow(question_client).to receive(:answer).and_return(answer)
end

let(:question_client) { instance_double(Agama::DBus::Clients::Question) }

it "registers a question with the details" do
expect(questions_client).to receive(:ask) do |q|
expect(q.text).to include("metadata is invalid")
expect(q.data).to include(
"url" => url, "description" => description
)
end
subject.source_probe_error(url, :REJECTED, description)
end

context "when the user answers :Retry" do
let(:answer) { :Retry }

it "returns 'R'" do
ret = subject.source_create_error("https://example.net/repo", :NOT_FOUND,
"Some description")
ret = subject.source_probe_error(url, :NOT_FOUND, description)
expect(ret).to eq(:RETRY)
end
end
Expand Down

0 comments on commit d4e66d3

Please sign in to comment.