/
rpm_spec.rb
327 lines (266 loc) · 10.1 KB
/
rpm_spec.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
require "spec_setup"
require "fpm" # local
require "fpm/package/rpm" # local
require "fpm/package/dir" # local
require "arr-pm/file" # gem 'arr-pm'
if !program_in_path?("rpmbuild")
Cabin::Channel.get("rspec") \
.warn("Skipping RPM#output tests because 'rpmbuild' isn't in your PATH")
end
describe FPM::Package::RPM do
after :each do
subject.cleanup
end
describe "#architecture" do
it "should convert amd64 to x86_64" do
subject.architecture = "amd64"
insist { subject.architecture } == "x86_64"
end
it "should convert 'all' to 'noarch'" do
subject.architecture = "all"
insist { subject.architecture } == "noarch"
end
it "should default to native" do
expected = %x{uname -m}.chomp
insist { subject.instance_eval { @architecture } } == "native"
insist { subject.architecture } == expected
end
end
describe "#iteration" do
it "should default to 1" do
insist { subject.iteration } == 1
end
end
describe "#epoch" do
it "should default to 1" do
insist { subject.epoch } == "1"
end
end
describe "#to_s" do
it "should have a default output usable as a filename" do
subject.name = "name"
subject.version = "123"
subject.architecture = "all"
subject.iteration = "100"
subject.epoch = "5"
# This is the default filename I see commonly output by rpmbuild
insist { subject.to_s } == "name-123-100.noarch.rpm"
end
end
describe "#templating" do
context "default user and group" do
before :all do
FileUtils.mkdir_p(subject.staging_path(File.dirname(__FILE__)))
FileUtils.cp(__FILE__, subject.staging_path(__FILE__))
# set the list of files for this RPM
def subject.files; [__FILE__]; end
def subject.rpmspec; @rpmspec; end
def subject.render_template; @rpmspec = template("rpm.erb").result(binding); end
subject.render_template
end
after :all do
subject.cleanup
end
it "should set the user and group of each file in the RPM" do
subject.rpmspec.should include('%defattr(-,root,root,-')
end
end # context
context "non-default user and group" do
before :all do
subject.attributes[:rpm_user] = "some_user"
subject.attributes[:rpm_group] = "some_group"
FileUtils.mkdir_p(subject.staging_path(File.dirname(__FILE__)))
FileUtils.cp(__FILE__, subject.staging_path(__FILE__))
# set the list of files for this RPM
def subject.files; [__FILE__]; end
def subject.rpmspec; @rpmspec; end
def subject.render_template; @rpmspec = template("rpm.erb").result(binding); end
subject.render_template
end
after :all do
subject.cleanup
end
it "should set the user and group of each file in the RPM" do
subject.rpmspec.should include('%defattr(-,some_user,some_group,-')
end
end # context
end
describe "#output", :if => program_in_path?("rpmbuild") do
context "package attributes" do
before :all do
@target = Tempfile.new("fpm-test-rpm").path
File.delete(@target)
subject.name = "name"
subject.version = "123"
subject.architecture = "all"
subject.iteration = "100"
subject.epoch = "5"
subject.dependencies << "something > 10"
subject.dependencies << "hello >= 20"
subject.conflicts << "bad < 2"
# Make sure multi-line licenses are hacked to work in rpm (#252)
subject.license = "this\nis\nan\example"
subject.provides << "bacon = 1.0"
# TODO(sissel): This api sucks, yo.
subject.scripts[:before_install] = "example before_install"
subject.scripts[:after_install] = "example after_install"
subject.scripts[:before_remove] = "example before_remove"
subject.scripts[:after_remove] = "example after_remove"
# Write the rpm out
subject.output(@target)
# Read the rpm
@rpm = ::RPM::File.new(@target)
@rpmtags = {}
@rpm.header.tags.each do |tag|
@rpmtags[tag.tag] = tag.value
end
end # before :all
after :all do
subject.cleanup
File.delete(@target)
end # after :all
it "should have the correct name" do
insist { @rpmtags[:name] } == subject.name
end
it "should have the correct version" do
insist { @rpmtags[:version] } == subject.version
end
it "should have the correct iteration" do
insist { @rpmtags[:release] } == subject.iteration
end
it "should have the correct epoch" do
insist { @rpmtags[:epoch].first.to_s } == subject.epoch
end
it "should output a package with the correct dependencies" do
# @rpm.requires is an array of [name, op, requires] elements
# fpm uses strings here, so convert.
requires = @rpm.requires.collect { |a| a.join(" ") }
subject.dependencies.each do |dep|
insist { requires }.include?(dep)
end
end
it "should output a package with the correct conflicts" do
# @rpm.requires is an array of [name, op, requires] elements
# fpm uses strings here, so convert.
conflicts = @rpm.conflicts.collect { |a| a.join(" ") }
subject.conflicts.each do |dep|
insist { conflicts }.include?(dep)
end
end
it "should output a package with the correct provides" do
# @rpm.requires is an array of [name, op, requires] elements
# fpm uses strings here, so convert.
provides = @rpm.provides.collect { |a| a.join(" ") }
subject.provides.each do |dep|
insist { provides }.include?(dep)
end
end
it "should replace newlines with spaces in the license field (issue#252)" do
insist { @rpm.tags[:license] } == subject.license.split("\n").join(" ")
end
it "should have the correct 'preun' script" do
insist { @rpm.tags[:preun] } == "example before_remove"
insist { @rpm.tags[:preunprog] } == "/bin/sh"
end
it "should have the correct 'postun' script" do
insist { @rpm.tags[:postun] } == "example after_remove"
insist { @rpm.tags[:postunprog] } == "/bin/sh"
end
it "should have the correct 'prein' script" do
insist { @rpm.tags[:prein] } == "example before_install"
insist { @rpm.tags[:preinprog] } == "/bin/sh"
end
it "should have the correct 'postin' script" do
insist { @rpm.tags[:postin] } == "example after_install"
insist { @rpm.tags[:postinprog] } == "/bin/sh"
end
it "should use md5/gzip by default" do
insist { @rpmtags[:payloadcompressor] } == "gzip"
# For whatever reason, the 'filedigestalgo' tag is an array of numbers.
# I only ever see one element in this array, so just do value.first
#
# Even though you can specify a file digest algorithm of md5, not
# specifying one at all is also valid in the RPM file itself,
# and not having one at all means md5. So accept 'nil' or the digest
# identifier for md5 (1).
insist { [nil, FPM::Package::RPM::DIGEST_ALGORITHM_MAP["md5"]] } \
.include?((@rpmtags[:filedigestalgo].first rescue nil))
end
end # package attributes
end # #output
describe "regressions should not occur", :if => program_in_path?("rpmbuild") do
before :each do
@target = Tempfile.new("fpm-test-rpm").path
File.delete(@target)
subject.name = "name"
subject.version = "1.23"
end
after :each do
subject.cleanup
File.delete(@target)
end # after
it "should permit spaces in filenames (issue #164)" do
File.write(subject.staging_path("file with space"), "Hello")
# This will raise an exception if rpmbuild fails.
subject.output(@target)
end
it "should permit brackets in filenames (issue #202)" do
File.write(subject.staging_path("file[with]bracket"), "Hello")
# This will raise an exception if rpmbuild fails.
subject.output(@target)
end
it "should permit asterisks in filenames (issue #202)" do
File.write(subject.staging_path("file*asterisk"), "Hello")
# This will raise an exception if rpmbuild fails.
subject.output(@target)
end
it "should have some reasonable defaults that never change" do
subject.output(@target)
# Read the rpm
rpm = ::RPM::File.new(@target)
rpmtags = {}
rpm.header.tags.each do |tag|
rpmtags[tag.tag] = tag.value
end
# Default epoch must be '1'
# For some reason, epoch is an array of numbers in rpm?
insist { rpmtags[:epoch] } == [1]
# Default release must be '1'
insist { rpmtags[:release] } == "1"
end
end # regression stuff
describe "#output with digest and compression settings", :if => program_in_path?("rpmbuild") do
context "bzip2/sha1" do
before :all do
@target = Tempfile.new("fpm-test-rpm").path
File.delete(@target)
subject.name = "name"
subject.version = "123"
subject.architecture = "all"
subject.iteration = "100"
subject.epoch = "5"
subject.attributes[:rpm_compression] = "bzip2"
subject.attributes[:rpm_digest] = "sha1"
# Write the rpm out
subject.output(@target)
# Read the rpm
@rpm = ::RPM::File.new(@target)
@rpmtags = {}
@rpm.header.tags.each do |tag|
@rpmtags[tag.tag] = tag.value
end
end
after :all do
subject.cleanup
File.delete(@target)
end # after
it "should have the compressor and digest algorithm listed" do
insist { @rpmtags[:payloadcompressor] } == "bzip2"
# For whatever reason, the 'filedigestalgo' tag is an array of numbers.
# I only ever see one element in this array, so just do value.first
insist { @rpmtags[:filedigestalgo].first } \
== FPM::Package::RPM::DIGEST_ALGORITHM_MAP["sha1"]
end
end # bzip2/sha1
end # #output with digest/compression settings
end # describe FPM::Package::RPM