Skip to content

Commit

Permalink
Testsuite update - mock Pkg calls
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Jun 2, 2017
1 parent d826ffb commit 7b20f08
Showing 1 changed file with 105 additions and 4 deletions.
109 changes: 105 additions & 4 deletions library/packages/test/file_conflict_callbacks_test.rb
Expand Up @@ -24,6 +24,94 @@ def CallbackFileConflictReport(func)
def CallbackFileConflictFinish(func)
@fc_finish = func
end

# run this command in "irb -ryast" to obtain the method names:
# Yast.import "Pkg"; Yast::Pkg.methods.select {|m| m.to_s.start_with?("Callback")}
# (Remove the methods which are defined above.)
MOCK_METHODS = [
:CallbackAcceptFileWithoutChecksum,
:CallbackAcceptUnknownDigest,
:CallbackAcceptUnknownGpgKey,
:CallbackAcceptUnsignedFile,
:CallbackAcceptVerificationFailed,
:CallbackAcceptWrongDigest,
:CallbackAuthentication,
:CallbackDestDownload,
:CallbackDoneDownload,
:CallbackDonePackage,
:CallbackDoneProvide,
:CallbackDoneRefresh,
:CallbackDoneScanDb,
:CallbackErrorScanDb,
:CallbackFinishDeltaApply,
:CallbackFinishDeltaDownload,
:CallbackImportGpgKey,
:CallbackInitDownload,
:CallbackMediaChange,
:CallbackMessage,
:CallbackNotifyConvertDb,
:CallbackNotifyRebuildDb,
:CallbackPkgGpgCheck,
:CallbackProblemDeltaApply,
:CallbackProblemDeltaDownload,
:CallbackProcessDone,
:CallbackProcessNextStage,
:CallbackProcessProgress,
:CallbackProcessStart,
:CallbackProgressConvertDb,
:CallbackProgressDeltaApply,
:CallbackProgressDeltaDownload,
:CallbackProgressDownload,
:CallbackProgressPackage,
:CallbackProgressProvide,
:CallbackProgressRebuildDb,
:CallbackProgressReportEnd,
:CallbackProgressReportProgress,
:CallbackProgressReportStart,
:CallbackProgressScanDb,
:CallbackResolvableReport,
:CallbackScriptFinish,
:CallbackScriptProblem,
:CallbackScriptProgress,
:CallbackScriptStart,
:CallbackSourceChange,
:CallbackSourceCreateDestroy,
:CallbackSourceCreateEnd,
:CallbackSourceCreateError,
:CallbackSourceCreateInit,
:CallbackSourceCreateProgress,
:CallbackSourceCreateStart,
:CallbackSourceProbeEnd,
:CallbackSourceProbeError,
:CallbackSourceProbeFailed,
:CallbackSourceProbeProgress,
:CallbackSourceProbeStart,
:CallbackSourceProbeSucceeded,
:CallbackSourceReportDestroy,
:CallbackSourceReportEnd,
:CallbackSourceReportError,
:CallbackSourceReportInit,
:CallbackSourceReportProgress,
:CallbackSourceReportStart,
:CallbackStartConvertDb,
:CallbackStartDeltaApply,
:CallbackStartDeltaDownload,
:CallbackStartDownload,
:CallbackStartPackage,
:CallbackStartProvide,
:CallbackStartRebuildDb,
:CallbackStartRefresh,
:CallbackStartScanDb,
:CallbackStopConvertDb,
:CallbackStopRebuildDb,
:CallbackTrustedKeyAdded,
:CallbackTrustedKeyRemoved
].freeze

MOCK_METHODS.each do |method|
# mock empty methods with a single argument
define_method(method) { |arg| }
end
end

describe Packages::FileConflictCallbacks do
Expand All @@ -42,10 +130,10 @@ def CallbackFileConflictFinish(func)

describe ".register" do
it "calls the Pkg methods for registering the file conflicts handlers" do
expect(dummy_pkg).to receive(:CallbackFileConflictStart)
expect(dummy_pkg).to receive(:CallbackFileConflictProgress)
expect(dummy_pkg).to receive(:CallbackFileConflictReport)
expect(dummy_pkg).to receive(:CallbackFileConflictFinish)
expect(dummy_pkg).to receive(:CallbackFileConflictStart).at_least(:once)
expect(dummy_pkg).to receive(:CallbackFileConflictProgress).at_least(:once)
expect(dummy_pkg).to receive(:CallbackFileConflictReport).at_least(:once)
expect(dummy_pkg).to receive(:CallbackFileConflictFinish).at_least(:once)

Packages::FileConflictCallbacks.register
end
Expand All @@ -71,6 +159,10 @@ def CallbackFileConflictFinish(func)
end

context "in UI mode" do
before do
allow(Yast::Mode).to receive(:commandline).and_return(false)
end

it "reuses the package installation progress" do
expect(Yast::UI).to receive(:WidgetExists).and_return(true)
expect(Yast::UI).to receive(:ChangeWidget).twice
Expand Down Expand Up @@ -121,6 +213,10 @@ def CallbackFileConflictFinish(func)
end

context "in UI mode" do
before do
allow(Yast::Mode).to receive(:commandline).and_return(false)
end

it "returns false to abort if user clicks Abort" do
expect(Yast::UI).to receive(:PollInput).and_return(:abort)

Expand Down Expand Up @@ -232,6 +328,7 @@ def CallbackFileConflictFinish(func)

context "in UI mode" do
before do
allow(Yast::Mode).to receive(:commandline).and_return(false)
allow(Yast::UI).to receive(:OpenDialog)
allow(Yast::UI).to receive(:CloseDialog)
allow(Yast::UI).to receive(:SetFocus)
Expand Down Expand Up @@ -280,6 +377,10 @@ def CallbackFileConflictFinish(func)
end

context "in UI mode" do
before do
allow(Yast::Mode).to receive(:commandline).and_return(false)
end

it "no change if installation progress was already displayed" do
ui = double("no method call expected", WidgetExists: true)
stub_const("Yast::UI", ui)
Expand Down

0 comments on commit 7b20f08

Please sign in to comment.