Skip to content

Commit

Permalink
returning conflicting files instead of boolean only
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Feb 3, 2020
1 parent e7e7f3c commit 7741047
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion library/general/src/lib/cfa/sysctl.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) [2019] SUSE LLC
# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
Expand Down
16 changes: 10 additions & 6 deletions library/general/src/lib/cfa/sysctl_config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) [2019] SUSE LLC
# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -100,9 +100,9 @@ def save
# Whether there is a conflict with given attributes
#
# @param only [Array<String,Symbol>] attributes to check
# @return [Boolean] true if any conflict is found; false otherwise
def conflict?(only: [])
return false if yast_config_file.empty?
# @return [Array<String>] list of conflicting files
def conflict_files(only: [])
return [] if yast_config_file.empty?

conflicting_attrs = yast_config_file.present_attributes
if !only.empty?
Expand All @@ -111,12 +111,16 @@ def conflict?(only: [])
conflicting_attrs.delete(key) unless only.include?(key)
end
end
higher_precedence_files.any? do |file|
file_list = []
higher_precedence_files.each do |file|
# Checking all "higher" files if their values overrule the current
# YAST settings.
higher_attr = file.present_attributes
conflicting_attrs.any? { |k, v| !higher_attr[k].nil? && v != higher_attr[k] }
if conflicting_attrs.any? { |k, v| !higher_attr[k].nil? && v != higher_attr[k] }
file_list << file.file_path
end
end
file_list
end

def files
Expand Down
16 changes: 8 additions & 8 deletions library/general/test/cfa/sysctl_config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@
end
end

describe "#conflict?" do
describe "#conflict_files" do
context "when YaST configuration file is empty" do
it "returns false" do
expect(config.conflict?).to eq(false)
it "returns empty list" do
expect(config.conflict_files).to be_empty
end
end

Expand All @@ -165,23 +165,23 @@
context "and no specific attributes are given" do
it "checks all known attributes" do
expect(file).to receive(:attr_value).exactly(CFA::Sysctl.known_attributes.count).times
config.conflict?
config.conflict_files
end
end

context "when some main file value is overriden" do
let(:tcp_syncookies) { false }

it "returns true" do
expect(config.conflict?).to eq(true)
it "returns file array" do
expect(config.conflict_files).to eq(["/etc/sysctl.conf"])
end
end

context "when no value is overriden" do
let(:tcp_syncookies) { true }

it "returns false" do
expect(config.conflict?).to eq(false)
it "returns empty list" do
expect(config.conflict_files).to be_empty
end
end
end
Expand Down

0 comments on commit 7741047

Please sign in to comment.