Skip to content

Commit

Permalink
Add unit test covering network defaults methods
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed May 28, 2021
1 parent fb0b980 commit bfc0eed
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/lib/y2network/proposal_settings.rb
Expand Up @@ -55,9 +55,8 @@ def initialize

# Modifies the proposal according to the given settings
#
# @param settings [Hash] networking default settings to be loaded
def modify_defaults(settings)
load_features # Networking section first
# @param settings [Hash] network default settings to be loaded
def modify_defaults(settings = network_section)
load_features(settings)
@defaults_applied = false
end
Expand Down
12 changes: 11 additions & 1 deletion test/save_network_test.rb
Expand Up @@ -60,6 +60,7 @@
.and_return(propose_bridge)
allow(Yast::NetworkAutoconfiguration.instance).to receive(:configure_dns)
allow(Yast::NetworkAutoconfiguration.instance).to receive(:configure_hosts)
allow(Yast::NetworkAutoconfiguration.instance).to receive(:configure_routing)
allow(Yast::Lan).to receive(:yast_config).and_return(yast_config)
allow(Yast::Lan).to receive(:system_config).and_return(system_config)
allow(Yast::Lan).to receive(:write_config)
Expand Down Expand Up @@ -170,12 +171,21 @@
context "if the hosts are not configured by AutoYaST" do
it "configures the /etc/hosts automatically" do
allow(Yast::NetworkAutoYast.instance).to receive(:configure_hosts).and_return(false)
expect(Yast::NetworkAutoconfiguration.instance).to_not receive(:configure_dns)
expect(Yast::NetworkAutoconfiguration.instance).to receive(:configure_hosts)
subject.main
end
end
end

context "in case of not written previously" do
it "configures dns, hosts and routing according to the proposal" do
expect(Yast::NetworkAutoconfiguration.instance).to receive(:configure_dns)
expect(Yast::NetworkAutoconfiguration.instance).to receive(:configure_routing)
expect(Yast::NetworkAutoconfiguration.instance).to receive(:configure_hosts)
subject.main
end
end

context "when the backend is network manager" do
let(:selected_backend) { :network_manager }

Expand Down
66 changes: 66 additions & 0 deletions test/y2network/proposal_settings_test.rb
Expand Up @@ -425,4 +425,70 @@ def stub_features(features)
end
end
end

describe "#modify_defaults" do
let(:settings) { described_class.create_instance }
let(:feature) { { "network" => { "ipv4_forwarding" => true } } }

context "in case of defined IP forwarding features in the control file" do
context "and no specific section is given" do
it "uses the profile network section" do
expect(settings).to receive(:load_features).with(feature["network"])
settings.modify_defaults
end
end

it "sets the IPv4 forwarding settings according to the feature value" do
settings.modify_defaults
expect(settings.ipv4_forwarding).to eql(true)
expect(settings.ipv6_forwarding).to eql(nil)
end

it "sets the IPv6 forwarding settings according to the feature value" do
role_feature = { "network" => { "ipv6_forwarding" => true } }
settings.modify_defaults(role_feature["network"])
expect(settings.ipv6_forwarding).to eql(true)
end

it "sets the modified defaults as not applied" do
settings.defaults_applied = true
settings.modify_defaults
expect(settings.defaults_applied).to eql(false)
end
end
end

describe "#apply_defaults" do
let(:settings) { described_class.create_instance }
let(:config) { Y2Network::Config.new(source: "test", routing: routing) }
let(:routing) { Y2Network::Routing.new(forward_ipv4: false, forward_ipv6: false, tables: []) }
let(:feature) { { "network" => { "ipv4_forwarding" => true } } }

before do
allow(Yast::Lan).to receive(:yast_config).and_return(config)
settings.modify_defaults
end

context "when the network defaults were already applied" do
it "does not touch any network configuration" do
settings.defaults_applied = true
expect(Yast::Lan).to_not receive(:yast_config)
settings.apply_defaults
end
end

context "when the network defaults has not been applied yet" do
it "modifies the current network config with the modified defaults" do
expect(routing.forward_ipv4).to eql(false)
settings.apply_defaults
expect(routing.forward_ipv4).to eql(true)
end

it "sets the modified defaults as already applied" do
expect(settings.defaults_applied).to eql(false)
settings.apply_defaults
expect(settings.defaults_applied).to eql(true)
end
end
end
end

0 comments on commit bfc0eed

Please sign in to comment.