-
Notifications
You must be signed in to change notification settings - Fork 20
/
autoinst_storage_test.rb
executable file
·234 lines (188 loc) · 6.94 KB
/
autoinst_storage_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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/env rspec
require_relative "test_helper"
require "y2storage"
Yast.import "AutoinstStorage"
describe Yast::AutoinstStorage do
subject { Yast::AutoinstStorage }
describe "#Import" do
let(:storage_proposal) do
instance_double(
Y2Autoinstallation::StorageProposal, valid?: valid?, issues_list: issues_list
)
end
let(:issues_dialog) { instance_double(Y2Autoinstallation::Dialogs::Question, run: :abort) }
let(:issues_list) { Y2Storage::AutoinstIssues::List.new }
let(:profile_section) { Y2Storage::AutoinstProfile::PartitionSection.new_from_hashes({}) }
let(:valid?) { true }
let(:errors_settings) { { "show" => false, "timeout" => 10 } }
let(:warnings_settings) { { "show" => true, "timeout" => 5 } }
let(:settings) { [{ "device" => "/dev/sda" }] }
let(:ask_settings) { [{ "device" => "ask" }] }
let(:preprocessor) { instance_double(Y2Autoinstallation::PartitioningPreprocessor, run: settings) }
before do
allow(Y2Autoinstallation::StorageProposal).to receive(:new)
.and_return(storage_proposal)
allow(Y2Autoinstallation::Dialogs::Question).to receive(:new)
.and_return(issues_dialog)
allow(storage_proposal).to receive(:save)
allow(Y2Autoinstallation::PartitioningPreprocessor).to receive(:new)
.and_return(preprocessor)
end
around do |example|
old_settings = Yast::Report.Export
Yast::Report.Import({"warnings" => warnings_settings, "errors" => errors_settings})
example.run
Yast::Report.Import(old_settings)
end
it "creates a proposal" do
expect(Y2Autoinstallation::StorageProposal).to receive(:new)
subject.Import({})
end
it "preprocess given settings" do
expect(preprocessor).to receive(:run).with(ask_settings)
expect(Y2Autoinstallation::StorageProposal).to receive(:new)
.with(settings)
.and_return(storage_proposal)
subject.Import([{ "device" => "ask" }])
end
context "when settings are not preprocessed successfully" do
let(:settings) { nil }
it "returns false" do
expect(subject.Import({})).to eq(false)
end
end
context "when the proposal is valid" do
let(:valid?) { true }
it "returns true" do
expect(subject.Import({})).to eq(true)
end
it "saves the proposal" do
expect(storage_proposal).to receive(:save)
subject.Import({})
end
end
context "when the proposal contains fatal issues" do
let(:valid?) { false }
before do
issues_list.add(:missing_root)
end
it "shows errors to the user without timeout" do
expect(Y2Autoinstallation::Dialogs::Question).to receive(:new)
.with(/Important issues/, timeout: 0, buttons_set: :abort)
.and_return(issues_dialog)
expect(issues_dialog).to receive(:run)
subject.Import({})
end
it "returns false" do
allow(issues_dialog).to receive(:run).and_return(:abort)
expect(subject.Import({})).to eq(false)
end
context "and errors logging is enabled" do
let(:errors_settings) { { "log" => true } }
it "logs the error" do
expect(subject.log).to receive(:error)
.with(/Important issues/)
subject.Import({})
end
end
context "and errors logging is disabled" do
let(:errors_settings) { { "log" => false } }
it "does not log the error" do
expect(subject.log).to_not receive(:error)
.with(/Important issues/)
subject.Import({})
end
end
end
context "when the proposal contains non fatal issues" do
let(:valid?) { false }
let(:continue) { true }
before do
issues_list.add(:invalid_value, profile_section, :size, "auto")
allow(subject.log).to receive(:warn).and_call_original
end
context "and warnings reporting is enabled" do
it "asks the user for confirmation" do
expect(Y2Autoinstallation::Dialogs::Question).to receive(:new)
.with(/Minor issues/, timeout: 5, buttons_set: :question)
.and_return(issues_dialog)
expect(issues_dialog).to receive(:run)
subject.Import({})
end
context "and the user confirms the proposal" do
before do
allow(issues_dialog).to receive(:run).and_return(:ok)
end
it "returns true" do
expect(subject.Import({})).to eq(true)
end
end
context "and the user dismisses the proposal" do
before do
allow(issues_dialog).to receive(:run).and_return(:abort)
end
it "returns false" do
expect(subject.Import({})).to eq(false)
end
end
end
context "and warnings reporting is disabled" do
let(:warnings_settings) { { "show" => false } }
it "returns true" do
expect(subject.Import({})).to eq(true)
end
end
context "and warnings logging is enabled" do
let(:warnings_settings) { { "log" => true } }
it "logs the warning" do
expect(subject.log).to receive(:warn)
.with(/Minor issues/)
subject.Import({})
end
end
context "and warnings logging is disabled" do
let(:warnings_settings) { { "log" => false } }
it "does not log the warning" do
expect(subject.log).to_not receive(:warn)
.with(/Some minor problems/)
subject.Import({})
end
end
end
end
describe "#import_general_settings" do
let(:profile) { { "proposal_lvm" => true } }
it "overrides control file values" do
subject.import_general_settings(profile)
end
context "when multipath is enabled" do
let(:profile) { { "start_multipath" => true } }
it "sets multipath"
end
context "when multipath is not enabled" do
it "does not set multipath"
end
context "when btrfs default subvolume name is set to false" do
let(:profile) { { "btrfs_set_default_subvolume_name" => false } }
it "disables the btrfs default subvolume" do
expect(Yast::ProductFeatures).to receive(:SetSection)
.with("partitioning", { "btrfs_default_subvolume" => "" })
subject.import_general_settings(profile)
end
end
context "when btrfs default subvolume name is not set" do
let(:profile) { {} }
it "uses the default for the product" do
expect(Yast::ProductFeatures).to receive(:SetSection).with("partitioning", {})
subject.import_general_settings(profile)
end
end
context "when btrfs default subvolume name is set to true" do
let(:profile) { { "btrfs_set_default_subvolume_name" => true } }
it "uses the default for the product" do
expect(Yast::ProductFeatures).to receive(:SetSection).with("partitioning", {})
subject.import_general_settings(profile)
end
end
end
end