Skip to content

Commit

Permalink
add test for copy logs client
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 7, 2015
1 parent 78588b7 commit 522e70c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib/installation/copy_logs_finish.rb
Expand Up @@ -31,6 +31,7 @@ def initialize
textdomain "installation"

Yast.import "Directory"
Yast.import "Installation"
end

def steps
Expand Down Expand Up @@ -74,12 +75,12 @@ def write
Yast::WFM.Execute(LOCAL_BASH, compress_cmd)
when /\Ay2log-\d+\.gz\z/
target_no = file[/y2log-(\d+)/, 1].to_i + 1
copy_log_to_target(file, "y2log-#{target_no}")
copy_log_to_target(file, "y2log-#{target_no}.gz")
when "zypp.log"
# Save zypp.log from the inst-sys
copy_log_to_target(file, "zypp.log-1") # not y2log, y2log-*
else
copy_log_to_target(file))
copy_log_to_target(file)
end
end

Expand Down
1 change: 1 addition & 0 deletions test/Makefile.am
@@ -1,6 +1,7 @@
TESTS = \
inst_functions_test.rb \
cio_ignore_test.rb \
copy_logs_finish_test.rb \
prep_shrink_test.rb \
remote_finish_test.rb

Expand Down
45 changes: 45 additions & 0 deletions test/copy_logs_finish_test.rb
@@ -0,0 +1,45 @@
#! /usr/bin/env rspec

require_relative "./test_helper"

require "installation/copy_logs_finish"

describe ::Installation::CopyLogsFinish do
describe "#write" do
before do
allow(Yast::WFM).to receive(:Execute)
end

it "copies logs from instalation to target system" do
allow(Yast::WFM).to receive(:Read).and_return(["y2start.log"])

expect(Yast::WFM).to receive(:Execute).with(anything(), /cp/).at_least(:once)

subject.write
end

it "rotate y2log" do
allow(Yast::WFM).to receive(:Read).and_return(["y2log-1.gz"])

expect(Yast::WFM).to receive(:Execute).with(anything(), /cp .*y2log-1.gz .*y2log-2.gz/)

subject.write
end

it "compress y2log if not already done" do
allow(Yast::WFM).to receive(:Read).and_return(["y2log-1"])

expect(Yast::WFM).to receive(:Execute).with(anything(), /gzip .*y2log-2/) #-2 due to rotation

subject.write
end

it "rotate zypp.log" do
allow(Yast::WFM).to receive(:Read).and_return(["zypp.log"])

expect(Yast::WFM).to receive(:Execute).with(anything(), /cp .*zypp.log .*zypp.log-1/)

subject.write
end
end
end

0 comments on commit 522e70c

Please sign in to comment.