Skip to content

Commit

Permalink
Adapted tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Oct 6, 2017
1 parent ab3d74c commit 759b844
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
28 changes: 3 additions & 25 deletions library/network/test/susefirewall_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,59 +24,37 @@ def reset_SuSEFirewallIsInstalled_cache
end

context "while in inst-sys" do
it "returns whether SuSEfirewall2 is selected for installation or already installed" do
expect(Yast::Stage).to receive(:stage).and_return("initial").at_least(:once)
it "returns whether SuSEfirewall2 is installed or not" do
expect(Yast::Mode).to receive(:mode).and_return("installation").twice

# Value is not cached
expect(Yast::Pkg).to receive(:IsSelected).and_return(true, false, false).exactly(3).times
# Fallback: if not selected, checks whether the package is installed
# Checks whether the package is installed
expect(Yast::PackageSystem).to receive(:Installed).and_return(false, true).twice

# Selected
expect(subject.SuSEFirewallIsInstalled).to eq(true)
# Not selected and not installed
expect(subject.SuSEFirewallIsInstalled).to eq(false)
# Not selected, but installed
expect(subject.SuSEFirewallIsInstalled).to eq(true)
end
end

context "while on a running system (normal configuration)" do
it "returns whether SuSEfirewall2 was or could have been installed" do
expect(Yast::Stage).to receive(:stage).and_return("normal").at_least(:once)
expect(Yast::Mode).to receive(:mode).and_return("normal").at_least(:once)

# Value is cached
expect(Yast::PackageSystem).to receive(:CheckAndInstallPackages).and_return(true, false).twice

expect(subject.SuSEFirewallIsInstalled).to eq(true)
expect(subject.SuSEFirewallIsInstalled).to eq(true)
expect(subject.SuSEFirewallIsInstalled).to eq(true)

reset_SuSEFirewallIsInstalled_cache

expect(subject.SuSEFirewallIsInstalled).to eq(false)
expect(subject.SuSEFirewallIsInstalled).to eq(false)
expect(subject.SuSEFirewallIsInstalled).to eq(false)
end
end

context "while in AutoYast config" do
it "returns whether SuSEfirewall2 is installed" do
expect(Yast::Stage).to receive(:stage).and_return("normal").at_least(:once)
expect(Yast::Mode).to receive(:mode).and_return("autoinst_config").at_least(:once)

# Value is cached
expect(Yast::PackageSystem).to receive(:Installed).and_return(false, true).twice

expect(subject.SuSEFirewallIsInstalled).to eq(false)
expect(subject.SuSEFirewallIsInstalled).to eq(false)
expect(subject.SuSEFirewallIsInstalled).to eq(false)

reset_SuSEFirewallIsInstalled_cache

expect(subject.SuSEFirewallIsInstalled).to eq(true)
expect(subject.SuSEFirewallIsInstalled).to eq(true)
expect(subject.SuSEFirewallIsInstalled).to eq(true)
end
end
Expand Down
14 changes: 3 additions & 11 deletions library/network/test/susefirewalld_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,19 @@ def reset_FirewallDIsInstalled_cache
end

context "while in inst-sys" do
it "returns whether FirewallD is selected for installation or already installed" do
expect(Yast::Stage).to receive(:stage).and_return("initial").at_least(:once)
it "returns whether FirewallD is installed or not" do
expect(Yast::Mode).to receive(:mode).and_return("installation").at_least(:twice)

# Value is not cached
expect(Yast::Pkg).to receive(:IsSelected).and_return(true, false, false).exactly(3).times
# Fallback: if not selected, checks whether the package is installed
# Checks whether the package is installed
expect(Yast::PackageSystem).to receive(:Installed).and_return(false, true).twice

# Selected
expect(subject.SuSEFirewallIsInstalled).to eq(true)
# Not selected and not installed
expect(subject.SuSEFirewallIsInstalled).to eq(false)
# Not selected, but installed
expect(subject.SuSEFirewallIsInstalled).to eq(true)
end
end

context "while on a running system (normal configuration)" do
it "returns whether FirewallD was or could have been installed" do
expect(Yast::Stage).to receive(:stage).and_return("normal").at_least(:once)
expect(Yast::Mode).to receive(:mode).and_return("normal").at_least(:once)

expect(Yast::PackageSystem).to receive(:CheckAndInstallPackages).and_return(true, false)
Expand All @@ -70,7 +63,6 @@ def reset_FirewallDIsInstalled_cache

context "while in AutoYast config" do
it "returns whether FirewallD is installed" do
expect(Yast::Stage).to receive(:stage).and_return("normal").at_least(:once)
expect(Yast::Mode).to receive(:mode).and_return("autoinst_config").at_least(:once)

expect(Yast::PackageSystem).to receive(:Installed).and_return(false, true)
Expand Down

0 comments on commit 759b844

Please sign in to comment.