Skip to content

Commit

Permalink
Merge 1670b67 into 1b9392b
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Feb 8, 2019
2 parents 1b9392b + 1670b67 commit f7a379e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
10 changes: 9 additions & 1 deletion src/modules/services_manager_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module Yast
import 'Stage'
import "Report"

class ServicesManagerTargetClass < Module
include Yast::Logger
Expand Down Expand Up @@ -139,8 +140,15 @@ def inspect

def save
return true unless modified?

log.info('Saving default target...')
Yast2::Systemd::Target.set_default(default_target)
unless Yast2::Systemd::Target.find(self.default_target)
# TRANSLATORS: error popup, %s is the default target e.g. graphical
Report.Warning(_("Cannot find default target '%s' which is not available," \
"using the text mode fallback.") % self.default_target)
self.default_target = BaseTargets::MULTIUSER
end
Yast2::Systemd::Target.set_default(self.default_target)
end

def reset
Expand Down
60 changes: 39 additions & 21 deletions test/services_manager_target_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ class Template < Struct.new(
MULTI_USER = Template.new("multi-user", true)
POWEROFF = Template.new("poweroff", true)
SLEEP = Template.new("sleep", false)
MDMONITOR = Template.new("mdmonitor", true)

ALL = [ GRAPHICAL, MULTI_USER, POWEROFF, SLEEP ]
ALL = [ GRAPHICAL, MULTI_USER, POWEROFF, SLEEP, MDMONITOR ]
end

extend Yast::I18n
Expand All @@ -50,13 +51,13 @@ class Template < Struct.new(
allow(Yast::Mode).to receive(:mode).and_return("normal")

allow(Yast2::Systemd::Target).to receive(:all).and_return(TestTarget::ALL)
allow(Yast2::Systemd::Target).to receive(:get_default).and_return(TestTarget::GRAPHICAL)
allow(Yast2::Systemd::Target).to receive(:get_default).and_return(TestTarget::MULTI_USER)
end

describe "#default_target" do
context "when the default target has not been set yet" do
it "returns the default target in the system" do
expect(subject.default_target).to eq("graphical")
expect(subject.default_target).to eq("multi-user")
end
end

Expand All @@ -73,7 +74,7 @@ class Template < Struct.new(

describe "#targets" do
it "returns the list of all possible targets" do
expect(subject.targets.keys).to contain_exactly("multi-user", "graphical")
expect(subject.targets.keys).to contain_exactly("multi-user", "graphical", "mdmonitor")
end

it "does not include targets that does not allow isolate" do
Expand All @@ -100,34 +101,51 @@ class Template < Struct.new(
subject.default_target = target
end

context "when the default target has not been changed" do
let(:target) { "graphical" }
context "default target is available" do
before do
allow(Yast2::Systemd::Target).to receive(:find).and_return(TestTarget::GRAPHICAL)
end

it "does not perform changes in the underlying system" do
expect(Yast2::Systemd::Target).to_not receive(:set_default)
context "when the default target has not been changed" do
let(:target) { "multi-user" }

subject.save
it "does not perform changes in the underlying system" do
expect(Yast2::Systemd::Target).to_not receive(:set_default)

subject.save
end
end

context "when the default target has been changed" do
let(:target) { "graphical" }

it "saves the changes in the underlying system" do
expect(Yast2::Systemd::Target).to receive(:set_default).with("graphical")

subject.save
end
end
end

context "when the default target has been changed" do
let(:target) { "multi-user" }
context "when default target is not available" do
let(:target) { "graphical" }

it "saves the changes in the underlying system" do
it "reports an error and set to multi-user" do
expect(Yast2::Systemd::Target).to receive(:find).and_return(nil)
expect(Yast::Report).to receive(:Warning)
expect(Yast2::Systemd::Target).to receive(:set_default).with("multi-user")

subject.save
end
end
end

describe "#reset" do
it "sets the default target according to value in the system" do
subject.default_target = "multi-user"
subject.default_target = "mdmonitor"

subject.reset

expect(subject.default_target).to eq("graphical")
expect(subject.default_target).to eq("multi-user")
end
end

Expand All @@ -136,19 +154,19 @@ class Template < Struct.new(
subject.default_target = target
end

context "when the default target has not been changed" do
context "when the default target has been changed" do
let(:target) { "graphical" }

it "returns false" do
expect(subject.modified?).to eq(false)
expect(subject.modified?).to eq(true)
end
end

context "when the default target has been changed" do
context "when the default target has not been changed" do
let(:target) { "multi-user" }

it "returns true" do
expect(subject.modified?).to eq(true)
expect(subject.modified?).to eq(false)
end
end
end
Expand All @@ -171,7 +189,7 @@ class Template < Struct.new(
let(:target) { "multi-user" }

before do
subject.default_target = "multi-user"
subject.default_target = "graphical"
end

it "does not set the module as 'not modified'" do
Expand All @@ -191,7 +209,7 @@ class Template < Struct.new(

context "when the default target has been changed" do
before do
subject.default_target = "multi-user"
subject.default_target = "graphical"
end

it "returns a summary describing the change" do
Expand Down

0 comments on commit f7a379e

Please sign in to comment.