/
package_spec.rb
219 lines (184 loc) · 6.77 KB
/
package_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
require "spec_setup"
require "fpm" # local
describe FPM::Package do
after do
subject.cleanup
end # after
shared_examples_for :Default do |item, default|
context "default value" do
it "should be #{default}" do
if default.nil?
expect(subject.send(item)).to(be_nil)
else
expect(subject.send(item)).to(be == default)
end
end
end
end
shared_examples_for :Mutator do |item|
context "when set" do
let(:value) { "whatever" }
it "should return the set value" do
expect(subject.send("#{item}=", value)).to(be == value)
end
context "the getter" do
before do
subject.send("#{item}=", value)
end
it "returns the value set previously" do
expect(subject.send(item)).to(be == value)
end
end
end
end
describe "#name" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, nil
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#version" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, nil
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#architecture" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, "native"
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#attributes" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, { :workdir => ::Dir.tmpdir }
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#category" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, "default"
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#config_files" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, []
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#conflicts" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, []
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#dependencies" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, []
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#description" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, "no description given"
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#epoch" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, nil
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#iteration" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, nil
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#license" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, "unknown"
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#maintainer" do
require "socket"
default_maintainer = "<#{ENV["USER"]}@#{Socket.gethostname}>"
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, default_maintainer
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#provides" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, []
end
describe "#replaces" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, []
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#scripts" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, {}
end
describe "#url" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, nil
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#vendor" do
it_behaves_like :Default, description.gsub(/^#/, "").to_sym, "none"
it_behaves_like :Mutator, description.gsub(/^#/, "").to_sym
end
describe "#exclude (internal method)" do
it "should obey attributes[:excludes]" do
File.write(subject.staging_path("hello"), "hello")
File.write(subject.staging_path("world"), "world")
subject.attributes[:excludes] = ["*world*"]
subject.instance_eval { exclude }
insist { subject.files } == ["hello"]
end
it "should obey attributes[:excludes] for directories" do
Dir.mkdir(subject.staging_path("example"))
Dir.mkdir(subject.staging_path("example/foo"))
File.write(subject.staging_path("example/foo/delete_me"), "Hello!")
File.write(subject.staging_path("keeper"), "Hello!")
subject.attributes[:excludes] = ["example"]
subject.instance_eval { exclude }
insist { subject.files } == ["keeper"]
end
it "should obey attributes[:excludes] for child directories" do
Dir.mkdir(subject.staging_path("example"))
Dir.mkdir(subject.staging_path("example/foo"))
File.write(subject.staging_path("example/foo/delete_me"), "Hello!")
File.write(subject.staging_path("keeper"), "Hello!")
subject.attributes[:excludes] = ["example/foo"]
subject.instance_eval { exclude }
insist { subject.files.sort } == ["example", "keeper"]
end
end
describe "#script (internal method)" do
scripts = [:after_install, :before_install, :after_remove, :before_remove]
before do
scripts.each do |script|
subject.scripts[script] = "<%= name %>"
end
subject.name = "Example"
end
context "when :template_scripts? is true" do
before do
subject.attributes[:template_scripts?] = true
end
scripts.each do |script|
it "should evaluate #{script} as a template" do
expect(subject.script(script)).to(be == subject.name)
end
end
end
context "when :template_scripts? is false" do
before do
subject.attributes[:template_scripts?] = false
end
scripts.each do |script|
it "should not process #{script} as a template" do
expect(subject.script(script)).to(be == subject.scripts[script])
end
end
end
it "should not template by default" do
expect(subject.attributes[:template_scripts?]).to(be_falsey)
end
end
describe "#staging_path and #staging_path" do
before() do
@oldtmp = ENV["TMP"]
ENV["TMP"] = '/var/tmp'
end
after() do
ENV["TMP"] = @oldtmp
end
it "should be a subdirectory of workdir (#1124)" do
expect(subject.build_path("hello1")).to(start_with("/var/tmp"))
expect(subject.build_path("hello1")).to(end_with("hello1"))
expect(subject.build_path("hello1")).to(include("build"))
end
it "should be a subdirectory of workdir (#1124)" do
expect(subject.staging_path("hello2")).to(start_with("/var/tmp"))
expect(subject.staging_path("hello2")).to(end_with("hello2"))
expect(subject.staging_path("hello2")).to(include("staging"))
end
end
end # describe FPM::Package