Skip to content

Commit

Permalink
Updated testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Feb 27, 2014
1 parent 8f17e00 commit 617e934
Showing 1 changed file with 77 additions and 8 deletions.
85 changes: 77 additions & 8 deletions test/install_inf_convertor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,33 @@

context "linuxrc provides dhcp configuration" do

DEVICE = "enp0s3"
NETCONFIG = "dhcp"

before(:each) do
@device = "enp0s3"
@netconfig = "dhcp"

@install_inf_convertor = Yast::InstallInfConvertor.instance

Yast::InstallInfConvertor::InstallInf
.stub(:[]) { "" }
Yast::InstallInfConvertor::InstallInf
.stub(:[])
.with("Netdevice") { DEVICE }
.with("Netdevice") { @device }
Yast::InstallInfConvertor::InstallInf
.stub(:[])
.with("NetConfig") { NETCONFIG }
.with("NetConfig") { @netconfig }
end

describe "#dev_name" do
it "returns expected device name" do
expect(@install_inf_convertor.send(:dev_name)).to eql DEVICE
expect(@install_inf_convertor.send(:dev_name)).to eql @device
end
end

describe "#write_ifcfg" do
it "creates ifcfg file for #{DEVICE}" do
it "creates ifcfg file for #{@device}" do
expect(SCR)
.to receive(:Write)
.with(path(".target.string"), /.*-#{DEVICE}/, "") { true }
.with(path(".target.string"), /.*-#{@device}/, "") { true }
expect(@install_inf_convertor.send(:write_ifcfg, "")).to eql true
end
end
Expand All @@ -126,4 +126,73 @@
end
end

context "linuxrc provides static configuration" do

before(:each) do
Yast.import "Netmask"

@device = "enp0s3"
@ip = "10.121.157.133"
@netmask = "255.255.240.0"
@netconfig = "static"
@nameserver = "10.120.0.1"

@install_inf_convertor = Yast::InstallInfConvertor.instance

Yast::InstallInfConvertor::InstallInf
.stub(:[]) { "" }
Yast::InstallInfConvertor::InstallInf
.stub(:[])
.with("Netdevice") { @device }
Yast::InstallInfConvertor::InstallInf
.stub(:[])
.with("NetConfig") { @netconfig }
Yast::InstallInfConvertor::InstallInf
.stub(:[])
.with("IP") { @ip }
Yast::InstallInfConvertor::InstallInf
.stub(:[])
.with("Netmask") { @netmask }
Yast::InstallInfConvertor::InstallInf
.stub(:[])
.with("Nameserver") { @nameserver }
end

describe "#create_ifcfg" do
it "creates a valid ifcfg for netconfig" do
expect(ifcfg = @install_inf_convertor.send(:create_ifcfg)).not_to be_empty
expect(ifcfg).to match /BOOTPROTO='static'/
expect(ifcfg).to match /IPADDR='#{@ip}\/#{Netmask.ToBits(@netmask)}'/
end
end

describe "#write_global_netconfig" do
it "writes all expected configuration" do
expect(@install_inf_convertor)
.to receive(:write_dns)
expect(@install_inf_convertor.send(:write_global_netconfig))
.to eql nil
end
end

describe "#write_dns" do
it "updates global netconfig file" do
expect(Yast::SCR)
.to receive(:Write)
.with(
path(".sysconfig.network.config"),
nil
) { true }
expect(Yast::SCR)
.to receive(:Write)
.with(
path(".sysconfig.network.config.NETCONFIG_DNS_STATIC_SERVERS"),
@nameserver
).once { true }
expect(@install_inf_convertor.send(:write_dns)).to eql true
end
end

end

end

0 comments on commit 617e934

Please sign in to comment.