Skip to content

Commit

Permalink
Added tests, DRY the code
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Mar 24, 2017
1 parent ec9837a commit aa3cffd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/modules/AddOnProduct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -595,24 +595,19 @@ def DoInstall_NoControlFile
end

def IntegrateY2Update(src_id)
# this works only with the SUSE tags repositories
binaries = GetCachedFileFromSource(
src_id, # optional
1,
"/y2update.tgz",
"digested",
true
)
# try skelcd package containing installer update
if binaries.nil?
# fetch the package, includes installation.xml as well
WorkflowManager.GetCachedWorkflowFilename(:addon, src_id, nil) #to cache the whole package
alt_file = Directory.tmpdir + "/workflow-updates/" + src_id.to_s + "/y2update.tgz"
Builtins.y2milestone("Alternative file name: %1", alt_file)
if File.exists? alt_file
Builtins.y2milestone("Alternative file exists")
binaries = alt_file
end
end

# try the package containing the installer update, works with all repositories,
# including RPM-MD
binaries ||= addon_y2update_path(src_id)

# File /y2update.tgz exists
if binaries != nil
# Try to extract files from the archive
Expand Down Expand Up @@ -1181,7 +1176,7 @@ def IntegrateReleaseNotes(repo_id)
def Integrate(srcid)
Builtins.y2milestone("Integrating repository %1", srcid)

# Updating inst-sys
# Updating inst-sys, this works only with the SUSE tags repositories
y2update = GetCachedFileFromSource(
srcid, # optional
1,
Expand All @@ -1190,17 +1185,9 @@ def Integrate(srcid)
true
)

# try skelcd package containing installer update
if y2update.nil?
# fetch the package, includes installation.xml as well
WorkflowManager.GetCachedWorkflowFilename(:addon, src_id, nil) #to cache the whole package
alt_file = Directory.tmpdir + "/workflow-updates/" + src_id.to_s + "/y2update.tgz"
Builtins.y2milestone("Alternative file name: %1", alt_file)
if File.exists? alt_file
Builtins.y2milestone("Alternative file exists")
y2update = alt_file
end
end
# try the package containing the installer update, works with all repositories,
# including RPM-MD
y2update ||= addon_y2update_path(srcid)

if y2update == nil
Builtins.y2milestone("No YaST update found on the media")
Expand Down Expand Up @@ -2427,6 +2414,21 @@ def parse_add_on_products_file(filename, type, base_url)
false
end
end

private

# Download the y2update from the addon package.
# @param src_id [Fixnum] repository ID
# @return [String,nil] full path to the `y2update.tgz` file or nil if not found
def addon_y2update_path(src_id)
# fetch and extract the "installerextension" package
WorkflowManager.GetCachedWorkflowFilename(:addon, src_id, nil)
alt_file = File.join(WorkflowManager.addon_control_dir(src_id), "y2update.tgz")
return nil unless File.exist?(alt_file)

log.info("Found y2update.tgz file from the installer extension package: #{alt_file}")
alt_file
end
end

AddOnProduct = AddOnProductClass.new
Expand Down
24 changes: 24 additions & 0 deletions test/addon_product_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,28 @@
end
end
end

describe "#Integrate" do
let(:src_id) { 3 }

before do
allow(subject).to receive(:GetCachedFileFromSource)
allow(subject).to receive(:HandleProductPATTERNS)
allow(subject).to receive(:IntegrateReleaseNotes)
allow(Yast::WorkflowManager).to receive(:GetCachedWorkflowFilename)
allow(Yast::WorkflowManager).to receive(:AddWorkflow)
end

it "updates the inst-sys with the y2update.tgz file from the installer extension package" do
expect(File).to receive(:exist?).with(/\/y2update\.tgz\z/).and_return(true)
expect(subject).to receive(:UpdateInstSys).with(/\/y2update\.tgz\z/)
subject.Integrate(src_id)
end

it "does not update inst-sys when y2update.tgz was not found in the installer extension package" do
expect(File).to receive(:exist?).with(/\/y2update\.tgz\z/).and_return(false)
expect(subject).to_not receive(:UpdateInstSys)
subject.Integrate(src_id)
end
end
end

0 comments on commit aa3cffd

Please sign in to comment.