-
Notifications
You must be signed in to change notification settings - Fork 44
/
updates_manager_test.rb
executable file
·170 lines (141 loc) · 4.76 KB
/
updates_manager_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
#!/usr/bin/env rspec
require_relative "./test_helper"
require "installation/updates_manager"
require "installation/driver_update"
require "pathname"
require "uri"
describe Installation::UpdatesManager do
subject(:manager) { Installation::UpdatesManager.new }
let(:uri) { URI("http://updates.opensuse.org/sles12") }
let(:repo0) { double("repo0", apply: true, cleanup: true, empty?: false) }
let(:repo1) { double("repo1", apply: true, cleanup: true, empty?: false) }
let(:dud0) { double("dud0", apply: true) }
describe "#add_repository" do
before do
allow(Installation::UpdateRepository).to receive(:new).with(uri)
.and_return(repo0)
end
context "when repository is added successfully" do
it "returns true and add the repository" do
allow(repo0).to receive(:fetch)
expect(manager.add_repository(uri)).to eq(true)
expect(manager.repositories).to eq([repo0])
end
end
context "when repository is empty" do
it "returns false" do
allow(repo0).to receive(:fetch)
allow(repo0).to receive(:empty?).and_return(true)
expect(manager.add_repository(uri)).to eq(false)
expect(manager.repositories).to be_empty
end
end
context "when a valid repository is not found" do
it "raises a NotValidRepo error" do
allow(repo0).to receive(:fetch)
.and_raise(Installation::UpdateRepository::NotValidRepo)
expect { manager.add_repository(uri) }
.to raise_error(Installation::UpdatesManager::NotValidRepo)
end
end
context "when update could not be fetched" do
it "raises a CouldNotFetchUpdateFromRepo error" do
allow(repo0).to receive(:fetch)
.and_raise(Installation::UpdateRepository::FetchError)
expect { manager.add_repository(uri) }
.to raise_error(Installation::UpdatesManager::CouldNotFetchUpdateFromRepo)
end
end
end
describe "#repositories" do
context "when no update was added" do
it "returns an empty array" do
expect(manager.repositories).to be_empty
end
end
context "when some update was added" do
before do
allow(Installation::UpdateRepository).to receive(:new).with(uri)
.and_return(repo0)
expect(repo0).to receive(:fetch).and_return(true)
manager.add_repository(uri)
end
it "returns an array containing the updates" do
expect(manager.repositories).to eq([repo0])
end
end
end
describe "#driver_updates" do
context "when no driver updates exist" do
before do
allow(Installation::DriverUpdate).to receive(:find).and_return([])
end
it "returns an empty array" do
expect(subject.driver_updates).to eq([])
end
end
context "when some driver update exist" do
before do
allow(Installation::DriverUpdate).to receive(:find).and_return([dud0])
end
it "returns an array containing existing updates" do
expect(subject.driver_updates).to eq([dud0])
end
end
end
describe "#apply_all" do
let(:new_control_file?) { false }
before do
allow(manager).to receive(:repositories).and_return([repo0, repo1])
allow(File).to receive(:exist?).with("/usr/lib/skelcd/CD1/control.xml")
.and_return(new_control_file?)
end
it "applies all the updates" do
expect(repo0).to receive(:apply)
expect(repo1).to receive(:apply)
expect(repo0).to receive(:cleanup)
expect(repo1).to receive(:cleanup)
manager.apply_all
end
context "when some driver update exists" do
before do
allow(manager).to receive(:driver_updates).and_return([dud0])
end
it "also re-applies the driver updates" do
expect(dud0).to receive(:apply)
manager.apply_all
end
end
context "when a new control file is available" do
let(:new_control_file?) { true }
it "updates the control file" do
expect(Yast::Execute).to receive(:locally!)
.with("/sbin/adddir", "/usr/lib/skelcd/CD1", "/")
manager.apply_all
end
end
it "does not replace the control file" do
expect(Yast::Execute).to_not receive(:locally!)
.with("/sbin/adddir", /skelcd/, "/")
manager.apply_all
end
end
describe "#repositories?" do
context "when some repository was added" do
before do
allow(manager).to receive(:repositories).and_return([repo0])
end
it "returns true" do
expect(manager.repositories?).to eq(true)
end
end
context "when no repository was added" do
before do
allow(manager).to receive(:repositories).and_return([])
end
it "returns false" do
expect(manager.repositories?).to eq(false)
end
end
end
end