/
ayast_setup_test.rb
executable file
·134 lines (110 loc) · 4.06 KB
/
ayast_setup_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
#!/usr/bin/env rspec
# Copyright (c) [2017] 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/clients/ayast_setup"
require "yast"
module Yast
class DummyClient < Module
include Y2Autoinstall::Clients::AyastSetup
attr_accessor :dopackages
end
end
Yast.import "Profile"
describe "Y2Autoinstall::Clients::AyastSetup" do
let(:subject) { Yast::DummyClient.new }
let(:profile) do
{
"general" => { "mode" => { "confirm" => true } },
"software" => { "post-packages" => packages }
}
end
let(:packages) { ["vim"] }
let(:dopackages) { false }
let(:client) do
instance_double(Y2Autoinstall::Clients::AyastSetup, Setup: true)
end
describe "#main" do
it "Start the ayast_setup client" do
expect(client.Setup).to eq true
end
end
describe "#Setup" do
before do
Yast::Profile.current = profile
allow(Yast::AutoInstall).to receive(:Save)
allow(Yast::AutoinstGeneral).to receive(:Import)
allow(Yast::WFM).to receive(:CallFunction)
allow(Yast::Mode).to receive(:SetMode)
allow(Yast::Stage).to receive(:Set)
allow(Yast::Package).to receive(:Installed).and_return(true)
allow(Yast::Pkg).to receive(:TargetInit)
allow(subject).to receive(:restart_initscripts)
end
it "saves the current profile if modified" do
expect(Yast::AutoInstall).to receive(:Save)
subject.Setup
end
it "calls the inst_autopost client" do
expect(Yast::WFM).to receive(:CallFunction).with("inst_autopost", [])
subject.Setup
end
context "when install_packages is set to true" do
it "installs given post installation packages / patterns when not installed yet" do
expect(Yast::Package).to receive(:Installed).and_return(false)
expect(Yast::AutoinstSoftware).to receive(:addPostPackages).with(["vim"])
expect(Yast::WFM).to receive(:CallFunction).with("inst_rpmcopy", [])
subject.Setup(install_packages: true)
end
end
context "when install_packages is set to specified" do
it "installs given post installation packages / patterns when not installed yet" do
expect(Yast::Package).to receive(:Installed).and_return(false)
expect(Yast::AutoinstSoftware).to receive(:addPostPackages).with(["vim"])
expect(Yast::WFM).to receive(:CallFunction).with("inst_rpmcopy", [])
subject.Setup
end
end
context "when install_packages is set to false" do
it "does not try to install given post installation packages / patterns" do
expect(Yast::WFM).to_not receive(:CallFunction).with("inst_rpmcopy", [])
subject.Setup(install_packages: false)
end
end
it "runs inst_autoconfigure client" do
expect(Yast::WFM).to receive(:CallFunction).with("inst_autoconfigure", [])
subject.Setup
end
it "restarts AutoYaST initscripts" do
expect(subject).to receive(:restart_initscripts)
subject.Setup
end
it "does not add a networking section when it is not defined in the profile" do
expect(Yast::Profile.current.keys).to_not include("networking")
subject.Setup
expect(Yast::Profile.current.keys).to_not include("networking")
end
it "imports general settings" do
expect(Yast::AutoinstGeneral).to receive(:Import).with(
"mode" => { "confirm" => true }
)
subject.Setup
end
end
end