Skip to content

Commit

Permalink
Merge pull request #575 from teclator/save_network_test
Browse files Browse the repository at this point in the history
Added mocks to avoid call save_network
  • Loading branch information
teclator committed Oct 4, 2017
2 parents a0afe71 + 40200d4 commit b083079
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions test/data/ifcfg-eth0.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BOOTPROTO='dhcp'
STARTMODE='auto'
21 changes: 18 additions & 3 deletions test/save_network_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,36 @@

require "yast"
require "network/clients/save_network"

describe Yast::SaveNetworkClient do

describe "#adjust_for_network_disks" do
let(:template_file) { File.join(SCRStub::DATA_PATH, "ifcfg-eth0.template") }
let(:file) { File.join(SCRStub::DATA_PATH, "ifcfg-eth0") }

around do |example|
::FileUtils.cp(template_file, file)
example.run
::FileUtils.rm(file)
end

before do
Y2Storage::StorageManager.create_test_instance

staging = Y2Storage::StorageManager.instance.staging
allow(staging).to receive(:filesystem_in_network?).and_return(in_network)
allow(Yast::SCR).to receive(:Execute).and_return("exit" => 0, "stdout" => "", "stderr" => "")
allow(subject).to receive(:save_network)
# Mainly for import
subject.main
end

context "when installation directory is in a network device" do
let(:in_network) { true }

it "tunes ifcfg file for remote filesystem" do
expect(Yast::SCR).to receive(:Execute).with(anything, /nfsroot/).once
subject.main
subject.adjust_for_network_disks(file)
expect(::File.read(file)).to include("STARTMODE=nfsroot")
end
end

Expand All @@ -29,7 +43,8 @@

it "does not touch any configuration file" do
expect(Yast::SCR).to_not receive(:Execute).with(anything, /nfsroot/)
subject.main
subject.adjust_for_network_disks(file)
expect(::File.read(file)).to eq(::File.read(template_file))
end
end
end
Expand Down

0 comments on commit b083079

Please sign in to comment.