-
Notifications
You must be signed in to change notification settings - Fork 20
/
script_runner_test.rb
124 lines (104 loc) · 3.49 KB
/
script_runner_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Copyright (c) [2021] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
require_relative "../../test_helper"
require "autoinstall/script"
require "autoinstall/script_runner"
describe Y2Autoinstall::ScriptRunner do
subject(:runner) { described_class.new }
let(:script) { Y2Autoinstallation::PreScript.new(spec) }
let(:spec) { { "filename" => "test.sh" } }
describe "#run" do
before do
allow(Yast::SCR).to receive(:Read)
.with(Yast::Path.new(".target.string"), script.log_path)
.and_return("logs content")
allow(script).to receive(:execute).and_return(true)
end
it "executes the script" do
expect(script).to receive(:execute).and_return(true)
runner.run(script)
end
it "returns true" do
expect(runner.run(script)).to eq(true)
end
context "when a notification is defined" do
let(:spec) do
{ "notification" => "A script is running..." }
end
it "displays the notification" do
expect(Yast::Popup).to receive(:ShowFeedback)
.with("", "A script is running...")
runner.run(script)
end
end
context "when a notification is not defined" do
it "does not display the notification" do
expect(Yast::Popup).to_not receive(:ShowFeedback)
runner.run(script)
end
end
context "when feedback is enabled but the type is not set" do
let(:spec) { { "feedback" => true } }
it "displays the logs in a pop-up" do
expect(Yast::Popup).to receive(:LongText)
runner.run(script)
end
end
context "when feedback is set to 'message'" do
let(:spec) do
{ "feedback" => true, "feedback_type" => "message" }
end
it "displays the logs as a regular message" do
expect(Yast::Report).to receive(:Message).with("logs content")
runner.run(script)
end
end
context "when feedback is set to 'warning'" do
let(:spec) do
{ "feedback" => true, "feedback_type" => "warning" }
end
it "displays the logs as a warning" do
expect(Yast::Report).to receive(:Warning).with("logs content")
runner.run(script)
end
end
context "when feedback is set to 'error'" do
let(:spec) do
{ "feedback" => true, "feedback_type" => "error" }
end
it "displays the logs as a error" do
expect(Yast::Report).to receive(:Error).with("logs content")
runner.run(script)
end
end
context "when the script failed" do
before do
allow(script).to receive(:execute).and_return(false)
end
it "reports the error" do
expect(Yast::Report).to receive(:Warning)
.with(/User script/, any_args)
runner.run(script)
end
it "returns false" do
expect(runner.run(script)).to eq(false)
end
end
end
end