packaging 0.88.77

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +17 -0
  3. data/README-Solaris.md +117 -0
  4. data/README.md +977 -0
  5. data/lib/packaging.rb +32 -0
  6. data/lib/packaging/archive.rb +126 -0
  7. data/lib/packaging/artifactory.rb +651 -0
  8. data/lib/packaging/artifactory/extensions.rb +94 -0
  9. data/lib/packaging/config.rb +492 -0
  10. data/lib/packaging/config/params.rb +387 -0
  11. data/lib/packaging/config/validations.rb +13 -0
  12. data/lib/packaging/deb.rb +28 -0
  13. data/lib/packaging/deb/repo.rb +264 -0
  14. data/lib/packaging/gem.rb +70 -0
  15. data/lib/packaging/metrics.rb +15 -0
  16. data/lib/packaging/nuget.rb +39 -0
  17. data/lib/packaging/paths.rb +376 -0
  18. data/lib/packaging/platforms.rb +507 -0
  19. data/lib/packaging/repo.rb +155 -0
  20. data/lib/packaging/retrieve.rb +75 -0
  21. data/lib/packaging/rpm.rb +5 -0
  22. data/lib/packaging/rpm/repo.rb +254 -0
  23. data/lib/packaging/sign.rb +8 -0
  24. data/lib/packaging/sign/deb.rb +9 -0
  25. data/lib/packaging/sign/dmg.rb +41 -0
  26. data/lib/packaging/sign/ips.rb +57 -0
  27. data/lib/packaging/sign/msi.rb +124 -0
  28. data/lib/packaging/sign/rpm.rb +115 -0
  29. data/lib/packaging/tar.rb +163 -0
  30. data/lib/packaging/util.rb +146 -0
  31. data/lib/packaging/util/date.rb +20 -0
  32. data/lib/packaging/util/execution.rb +85 -0
  33. data/lib/packaging/util/file.rb +125 -0
  34. data/lib/packaging/util/git.rb +174 -0
  35. data/lib/packaging/util/git_tags.rb +73 -0
  36. data/lib/packaging/util/gpg.rb +66 -0
  37. data/lib/packaging/util/jenkins.rb +95 -0
  38. data/lib/packaging/util/misc.rb +69 -0
  39. data/lib/packaging/util/net.rb +410 -0
  40. data/lib/packaging/util/os.rb +17 -0
  41. data/lib/packaging/util/platform.rb +40 -0
  42. data/lib/packaging/util/rake_utils.rb +112 -0
  43. data/lib/packaging/util/serialization.rb +19 -0
  44. data/lib/packaging/util/ship.rb +300 -0
  45. data/lib/packaging/util/tool.rb +41 -0
  46. data/lib/packaging/util/version.rb +334 -0
  47. data/spec/fixtures/config/ext/build_defaults.yaml +2 -0
  48. data/spec/fixtures/config/ext/project_data.yaml +2 -0
  49. data/spec/fixtures/configs/components/test_file.json +1 -0
  50. data/spec/fixtures/configs/components/test_file_2.json +0 -0
  51. data/spec/fixtures/configs/components/test_file_not_tagged.json +1 -0
  52. data/spec/fixtures/configs/components/test_file_wrong_ext.txt +0 -0
  53. data/spec/fixtures/configs/components/test_file_wrong_ext.wrong +0 -0
  54. data/spec/fixtures/util/pre_tasks.yaml +4 -0
  55. data/spec/lib/packaging/artifactory_spec.rb +221 -0
  56. data/spec/lib/packaging/config_spec.rb +576 -0
  57. data/spec/lib/packaging/deb/repo_spec.rb +157 -0
  58. data/spec/lib/packaging/deb_spec.rb +52 -0
  59. data/spec/lib/packaging/gem_spec.rb +86 -0
  60. data/spec/lib/packaging/paths_spec.rb +418 -0
  61. data/spec/lib/packaging/platforms_spec.rb +178 -0
  62. data/spec/lib/packaging/repo_spec.rb +135 -0
  63. data/spec/lib/packaging/retrieve_spec.rb +100 -0
  64. data/spec/lib/packaging/rpm/repo_spec.rb +133 -0
  65. data/spec/lib/packaging/sign_spec.rb +133 -0
  66. data/spec/lib/packaging/tar_spec.rb +116 -0
  67. data/spec/lib/packaging/util/execution_spec.rb +56 -0
  68. data/spec/lib/packaging/util/file_spec.rb +139 -0
  69. data/spec/lib/packaging/util/git_spec.rb +160 -0
  70. data/spec/lib/packaging/util/git_tag_spec.rb +36 -0
  71. data/spec/lib/packaging/util/gpg_spec.rb +64 -0
  72. data/spec/lib/packaging/util/jenkins_spec.rb +112 -0
  73. data/spec/lib/packaging/util/misc_spec.rb +31 -0
  74. data/spec/lib/packaging/util/net_spec.rb +259 -0
  75. data/spec/lib/packaging/util/os_spec.rb +31 -0
  76. data/spec/lib/packaging/util/rake_utils_spec.rb +70 -0
  77. data/spec/lib/packaging/util/ship_spec.rb +199 -0
  78. data/spec/lib/packaging/util/version_spec.rb +123 -0
  79. data/spec/lib/packaging_spec.rb +19 -0
  80. data/spec/spec_helper.rb +22 -0
  81. data/static_artifacts/PackageInfo.plist +3 -0
  82. data/tasks/00_utils.rake +214 -0
  83. data/tasks/30_metrics.rake +33 -0
  84. data/tasks/apple.rake +268 -0
  85. data/tasks/archive.rake +69 -0
  86. data/tasks/build.rake +12 -0
  87. data/tasks/clean.rake +5 -0
  88. data/tasks/config.rake +35 -0
  89. data/tasks/deb.rake +129 -0
  90. data/tasks/deb_repos.rake +28 -0
  91. data/tasks/deprecated.rake +130 -0
  92. data/tasks/doc.rake +20 -0
  93. data/tasks/education.rake +57 -0
  94. data/tasks/fetch.rake +60 -0
  95. data/tasks/gem.rake +159 -0
  96. data/tasks/jenkins.rake +538 -0
  97. data/tasks/jenkins_dynamic.rake +202 -0
  98. data/tasks/load_extras.rake +21 -0
  99. data/tasks/mock.rake +348 -0
  100. data/tasks/nightly_repos.rake +286 -0
  101. data/tasks/pe_deb.rake +12 -0
  102. data/tasks/pe_rpm.rake +13 -0
  103. data/tasks/pe_ship.rake +226 -0
  104. data/tasks/pe_sign.rake +13 -0
  105. data/tasks/pe_tar.rake +5 -0
  106. data/tasks/retrieve.rake +52 -0
  107. data/tasks/rpm.rake +66 -0
  108. data/tasks/rpm_repos.rake +29 -0
  109. data/tasks/ship.rake +692 -0
  110. data/tasks/sign.rake +154 -0
  111. data/tasks/tag.rake +8 -0
  112. data/tasks/tar.rake +28 -0
  113. data/tasks/update.rake +16 -0
  114. data/tasks/vanagon.rake +35 -0
  115. data/tasks/vendor_gems.rake +117 -0
  116. data/tasks/version.rake +33 -0
  117. data/tasks/z_data_dump.rake +65 -0
  118. data/templates/README +1 -0
  119. data/templates/downstream.xml.erb +47 -0
  120. data/templates/msi.xml.erb +197 -0
  121. data/templates/packaging.xml.erb +346 -0
  122. data/templates/repo.xml.erb +117 -0
  123. metadata +287 -0
@@ -0,0 +1,576 @@
1
+ # -*- ruby -*-
2
+ require 'spec_helper'
3
+ require 'yaml'
4
+
5
+ describe "Pkg::Config" do
6
+
7
+ Build_Params = [:apt_archive_path,
8
+ :apt_archive_repo_command,
9
+ :apt_host,
10
+ :apt_releases,
11
+ :apt_repo_path,
12
+ :apt_repo_url,
13
+ :apt_repo_name,
14
+ :apt_repo_command,
15
+ :author,
16
+ :benchmark,
17
+ :build_date,
18
+ :build_defaults,
19
+ :build_dmg,
20
+ :build_doc,
21
+ :build_gem,
22
+ :build_ips,
23
+ :build_msi,
24
+ :build_pe,
25
+ :build_tar,
26
+ :builder_data_file,
27
+ :bundle_platforms,
28
+ :certificate_pem,
29
+ :cows,
30
+ :db_table,
31
+ :deb_build_host,
32
+ :deb_build_mirrors,
33
+ :debversion,
34
+ :debug,
35
+ :default_cow,
36
+ :default_mock,
37
+ :description,
38
+ :dmg_path,
39
+ :downloads_archive_path,
40
+ :email,
41
+ :files,
42
+ :final_mocks,
43
+ :freight_archive_path,
44
+ :freight_conf,
45
+ :gem_default_executables,
46
+ :gem_dependencies,
47
+ :gem_description,
48
+ :gem_devel_dependencies,
49
+ :gem_development_dependencies,
50
+ :gem_excludes,
51
+ :gem_executables,
52
+ :gem_files,
53
+ :gem_forge_project,
54
+ :gem_host,
55
+ :gem_name,
56
+ :gem_path,
57
+ :gem_platform_dependencies,
58
+ :gem_rdoc_options,
59
+ :gem_require_path,
60
+ :gem_required_ruby_version,
61
+ :gem_required_rubygems_version,
62
+ :gem_runtime_dependencies,
63
+ :gem_summary,
64
+ :gem_test_files,
65
+ :gemversion,
66
+ :gpg_key,
67
+ :gpg_name,
68
+ :homepage,
69
+ :ips_build_host,
70
+ :ips_host,
71
+ :ips_inter_cert,
72
+ :ips_package_host,
73
+ :ips_path,
74
+ :ips_repo,
75
+ :ips_store,
76
+ :jenkins_build_host,
77
+ :jenkins_packaging_job,
78
+ :jenkins_repo_path,
79
+ :metrics,
80
+ :metrics_url,
81
+ :msi_name,
82
+ :name,
83
+ :nonfinal_apt_repo_command,
84
+ :nonfinal_apt_repo_path,
85
+ :nonfinal_apt_repo_staging_path,
86
+ :nonfinal_dmg_path,
87
+ :nonfinal_gem_path,
88
+ :nonfinal_ips_path,
89
+ :nonfinal_msi_path,
90
+ :nonfinal_p5p_path,
91
+ :nonfinal_repo_name,
92
+ :nonfinal_repo_link_target,
93
+ :nonfinal_svr4_path,
94
+ :nonfinal_swix_path,
95
+ :nonfinal_yum_repo_path,
96
+ :notify,
97
+ :project,
98
+ :origversion,
99
+ :osx_build_host,
100
+ :packager,
101
+ :packaging_repo,
102
+ :packaging_root,
103
+ :packaging_url,
104
+ :pbuild_conf,
105
+ :pe_name,
106
+ :pe_version,
107
+ :pg_major_version,
108
+ :pre_tar_task,
109
+ :pre_tasks,
110
+ :privatekey_pem,
111
+ :random_mockroot,
112
+ :rc_mocks,
113
+ :release,
114
+ :rpm_build_host,
115
+ :rpmrelease,
116
+ :rpmversion,
117
+ :ref,
118
+ :repo_name,
119
+ :short_ref,
120
+ :sign_tar,
121
+ :signing_server,
122
+ :summary,
123
+ :svr4_host,
124
+ :svr4_path,
125
+ :swix_path,
126
+ :tar_excludes,
127
+ :tar_host,
128
+ :tarball_path,
129
+ :team,
130
+ :templates,
131
+ :update_version_file,
132
+ :version,
133
+ :version_file,
134
+ :version_strategy,
135
+ :yum_archive_path,
136
+ :yum_host,
137
+ :yum_repo_path,
138
+ :yum_repo_name,
139
+ :yum_repo_command,
140
+ ]
141
+
142
+ describe "#new" do
143
+ Build_Params.each do |param|
144
+ it "should have r/w accessors for #{param}" do
145
+ Pkg::Config.should respond_to(param)
146
+ Pkg::Config.should respond_to("#{param.to_s}=")
147
+ end
148
+ end
149
+ end
150
+
151
+ describe "#config_from_hash" do
152
+ good_params = { :yum_host => 'foo', :pe_name => 'bar' }
153
+ context "given a valid params hash #{good_params}" do
154
+ it "should set instance variable values for each param" do
155
+ good_params.each do |param, value|
156
+ Pkg::Config.should_receive(:instance_variable_set).with("@#{param}", value)
157
+ end
158
+ Pkg::Config.config_from_hash(good_params)
159
+ end
160
+ end
161
+
162
+ bad_params = { :foo => 'bar' }
163
+ context "given an invalid params hash #{bad_params}" do
164
+ bad_params.each do |param, value|
165
+ it "should print a warning that param '#{param}' is not valid" do
166
+ Pkg::Config.should_receive(:warn).with(/No build data parameter found for '#{param}'/)
167
+ Pkg::Config.config_from_hash(bad_params)
168
+ end
169
+
170
+ it "should not try to set instance variable @:#{param}" do
171
+ Pkg::Config.should_not_receive(:instance_variable_set).with("@#{param}", value)
172
+ Pkg::Config.config_from_hash(bad_params)
173
+ end
174
+ end
175
+ end
176
+
177
+ mixed_params = { :sign_tar => true, :baz => 'qux' }
178
+ context "given a hash with both valid and invalid params" do
179
+ it "should set the valid param" do
180
+ Pkg::Config.should_receive(:instance_variable_set).with("@sign_tar", true)
181
+ Pkg::Config.config_from_hash(mixed_params)
182
+ end
183
+
184
+ it "should issue a warning that the invalid param is not valid" do
185
+ Pkg::Config.should_receive(:warn).with(/No build data parameter found for 'baz'/)
186
+ Pkg::Config.config_from_hash(mixed_params)
187
+ end
188
+
189
+ it "should not try to set instance variable @:baz" do
190
+ Pkg::Config.should_not_receive(:instance_variable_set).with("@baz", "qux")
191
+ Pkg::Config.config_from_hash(mixed_params)
192
+ end
193
+ end
194
+ end
195
+
196
+ describe "#params" do
197
+ it "should return a hash containing keys for all build parameters" do
198
+ params = Pkg::Config.config
199
+ Build_Params.each { |param| params.has_key?(param).should == true }
200
+ end
201
+ end
202
+
203
+ describe "#platform_data" do
204
+ platform_tags = [
205
+ 'osx-10.15-x86_64',
206
+ 'osx-11-x86_64',
207
+ 'ubuntu-16.04-i386',
208
+ 'el-6-x86_64',
209
+ 'el-7-ppc64le',
210
+ 'sles-12-x86_64',
211
+ ]
212
+
213
+ artifacts = \
214
+ "./artifacts/apple/10.15/PC1/x86_64/puppet-agent-5.3.2.658.gc79ef9a-1.osx10.15.dmg\n" \
215
+ "./artifacts/apple/11/PC1/x86_64/puppet-agent-5.3.2.658.gc79ef9a-1.osx11.dmg\n" \
216
+ "./artifacts/deb/xenial/PC1/puppet-agent_5.3.2-1xenial_i386.deb\n" \
217
+ "./artifacts/el/6/PC1/x86_64/puppet-agent-5.3.2.658.gc79ef9a-1.el6.x86_64.rpm\n" \
218
+ "./artifacts/el/7/PC1/ppc64le/puppet-agent-5.3.2-1.el7.ppc64le.rpm\n" \
219
+ "./artifacts/sles/12/PC1/x86_64/puppet-agent-5.3.2-1.sles12.x86_64.rpm"
220
+
221
+ aix_artifacts = \
222
+ "./artifacts/aix/7.1/PC1/ppc/puppet-agent-5.3.2-1.aix7.1.ppc.rpm"
223
+
224
+ fedora_artifacts = \
225
+ "./artifacts/fedora/31/PC1/x86_64/puppet-agent-5.3.2-1.fc31.x86_64.rpm"
226
+
227
+ windows_artifacts = \
228
+ "./artifacts/windows/puppet-agent-x64.msi\n" \
229
+ "./artifacts/windows/puppet-agent-5.3.2-x86.wixpdb\n" \
230
+ "./artifacts/windows/puppet-agent-5.3.2-x86.msi\n" \
231
+ "./artifacts/windows/puppet-agent-5.3.2-x64.msi\n"\
232
+ "./artifacts/windowsfips/puppet-agent-x64.msi\n" \
233
+ "./artifacts/windowsfips/puppet-agent-5.3.2-x64.msi"
234
+
235
+ solaris_artifacts = \
236
+ "./artifacts/solaris/11/PC1/puppet-agent@5.3.2,5.11-1.sparc.p5p\n" \
237
+ "./artifacts/solaris/10/PC1/puppet-agent-5.3.2-1.i386.pkg.gz"
238
+
239
+ stretch_artifacts = \
240
+ "./artifacts/deb/stretch/PC1/puppet-agent-dbgsym_5.3.2-1stretch_i386.deb\n" \
241
+ "./artifacts/deb/stretch/PC1/puppet-agent_5.3.2-1stretch_i386.deb\n" \
242
+ "./artifacts/deb/stretch/PC1/puppet-agent_5.3.2.658.gc79ef9a-1stretch_amd64.deb\n" \
243
+ "./artifacts/deb/stretch/PC1/puppet-agent-dbgsym_5.3.2.658.gc79ef9a-1stretch_amd64.deb"
244
+
245
+ artifacts_not_matching_project = \
246
+ "./artifacts/deb/xenial/pe-postgresql-contrib_2019.1.9.6.12-1xenial_amd64.deb\n" \
247
+ "./artifacts/deb/xenial/pe-postgresql-devel_2019.1.9.6.12-1xenial_amd64.deb\n" \
248
+ "./artifacts/deb/xenial/pe-postgresql-server_2019.1.9.6.12-1xenial_amd64.deb\n" \
249
+ "./artifacts/deb/xenial/pe-postgresql_2019.1.9.6.12-1xenial_amd64.deb"
250
+ project = 'puppet-agent'
251
+ ref = '5.3.2'
252
+
253
+ before :each do
254
+ allow(Pkg::Config).to receive(:project).and_return(project)
255
+ allow(Pkg::Config).to receive(:ref).and_return(ref)
256
+ allow(Pkg::Util::Net).to receive(:check_host_ssh).and_return([])
257
+ end
258
+
259
+ it "should return a hash mapping platform tags to paths" do
260
+ allow(Pkg::Util::Net).to receive(:remote_execute).and_return(artifacts, nil)
261
+ expect(Pkg::Config.platform_data.keys).to eql(platform_tags)
262
+ end
263
+
264
+ it "should return nil if project isn't set" do
265
+ allow(Pkg::Config).to receive(:project).and_return(nil)
266
+ expect(Pkg::Config.platform_data).to be_nil
267
+ end
268
+
269
+ it "should return nil if ref isn't set" do
270
+ allow(Pkg::Config).to receive(:ref).and_return(nil)
271
+ expect(Pkg::Config.platform_data).to be_nil
272
+ end
273
+
274
+ it "should return nil if can't connect to build server" do
275
+ allow(Pkg::Util::Net).to receive(:check_host_ssh).and_return(['something'])
276
+ expect(Pkg::Config.platform_data).to be_nil
277
+ end
278
+
279
+ it "should not use 'f' in fedora platform tags" do
280
+ allow(Pkg::Util::Net).to receive(:remote_execute).and_return(fedora_artifacts, nil)
281
+ data = Pkg::Config.platform_data
282
+ expect(data).to include('fedora-31-x86_64')
283
+ expect(data).not_to include('fedora-f31-x86_64')
284
+ end
285
+
286
+ it "should collect packages whose extname differ from package_format" do
287
+ allow(Pkg::Util::Net).to receive(:remote_execute).and_return(solaris_artifacts, nil)
288
+ data = Pkg::Config.platform_data
289
+ expect(data).to include('solaris-10-i386' => {:artifact => './solaris/10/PC1/puppet-agent-5.3.2-1.i386.pkg.gz', :repo_config => nil})
290
+ expect(data).to include('solaris-11-sparc' => {:artifact => './solaris/11/PC1/puppet-agent@5.3.2,5.11-1.sparc.p5p', :repo_config => nil})
291
+ end
292
+
293
+ it "should collect versioned msis" do
294
+ allow(Pkg::Util::Net).to receive(:remote_execute).and_return(windows_artifacts, nil)
295
+ data = Pkg::Config.platform_data
296
+ expect(data['windows-2012-x86']).to include(:artifact => './windows/puppet-agent-5.3.2-x86.msi')
297
+ expect(data['windows-2012-x64']).to include(:artifact => './windows/puppet-agent-5.3.2-x64.msi')
298
+ expect(data['windowsfips-2012-x64']).to include(:artifact => './windowsfips/puppet-agent-5.3.2-x64.msi')
299
+ end
300
+
301
+ it "should not collect debug packages" do
302
+ allow(Pkg::Util::Net).to receive(:remote_execute).and_return(stretch_artifacts, nil)
303
+ data = Pkg::Config.platform_data
304
+ expect(data['debian-9-amd64']).to include(:artifact => './deb/stretch/PC1/puppet-agent_5.3.2.658.gc79ef9a-1stretch_amd64.deb')
305
+ end
306
+
307
+ it "should collect packages that don't match the project name" do
308
+ allow(Pkg::Util::Net).to receive(:remote_execute).and_return(artifacts_not_matching_project, nil)
309
+ data = Pkg::Config.platform_data
310
+ expect(data['ubuntu-16.04-amd64']).to include(:artifact => './deb/xenial/pe-postgresql-contrib_2019.1.9.6.12-1xenial_amd64.deb')
311
+ expect(data['ubuntu-16.04-amd64'][:additional_artifacts].size).to eq(3)
312
+ expect(data['ubuntu-16.04-amd64'][:additional_artifacts]).to include('./deb/xenial/pe-postgresql-devel_2019.1.9.6.12-1xenial_amd64.deb')
313
+ expect(data['ubuntu-16.04-amd64'][:additional_artifacts]).to include('./deb/xenial/pe-postgresql-server_2019.1.9.6.12-1xenial_amd64.deb')
314
+ expect(data['ubuntu-16.04-amd64'][:additional_artifacts]).to include('./deb/xenial/pe-postgresql_2019.1.9.6.12-1xenial_amd64.deb')
315
+ end
316
+
317
+ it "should use 'ppc' instead of 'power' in aix paths" do
318
+ allow(Pkg::Util::Net).to receive(:remote_execute).and_return(aix_artifacts, nil)
319
+ data = Pkg::Config.platform_data
320
+ expect(data['aix-7.1-power']).to include(:artifact => './aix/7.1/PC1/ppc/puppet-agent-5.3.2-1.aix7.1.ppc.rpm')
321
+ end
322
+
323
+ it "should not record an aix repo config" do
324
+ allow(Pkg::Util::Net).to receive(:remote_execute).and_return(aix_artifacts, nil)
325
+ data = Pkg::Config.platform_data
326
+ expect(data['aix-7.1-power'][:repo_config]).to be_nil
327
+ end
328
+ end
329
+
330
+ describe "#config_to_yaml" do
331
+ it "should write a valid yaml file" do
332
+ file = double('file')
333
+ File.should_receive(:open).with(anything(), 'w').and_yield(file)
334
+ file.should_receive(:puts).with(instance_of(String))
335
+ YAML.should_receive(:load_file).with(file)
336
+ expect { YAML.load_file(file) }.to_not raise_error
337
+ Pkg::Config.config_to_yaml
338
+ end
339
+ end
340
+
341
+ describe "#get_binding" do
342
+ it "should return the binding of the Pkg::Config object" do
343
+ # test by eval'ing using the binding before and after setting a param
344
+ orig = Pkg::Config.apt_host
345
+ Pkg::Config.apt_host = "foo"
346
+ expect(eval("@apt_host", Pkg::Config.get_binding)).to eq("foo")
347
+ Pkg::Config.apt_host = "bar"
348
+ expect(eval("@apt_host", Pkg::Config.get_binding)).to eq("bar")
349
+ Pkg::Config.apt_host = orig
350
+ end
351
+ end
352
+
353
+ describe "#config_from_yaml" do
354
+ context "given a yaml file" do
355
+ it "should, use it to set params" do
356
+ # apt_host: is set to "foo" in the fixture
357
+ orig = Pkg::Config.apt_host
358
+ Pkg::Config.apt_host = "bar"
359
+ Pkg::Config.config_from_yaml(File.join(FIXTURES, 'config', 'ext', 'build_defaults.yaml'))
360
+ expect(Pkg::Config.apt_host).to eq("foo")
361
+ Pkg::Config.apt_host = orig
362
+ end
363
+ end
364
+ end
365
+
366
+ describe "#string_to_array" do
367
+ ary = %W(FOO BAR ARR RAY)
368
+ context "given a string with spaces in it" do
369
+ it "should return an array containing the contents of that string" do
370
+ space_str = "FOO BAR ARR RAY"
371
+ expect(Pkg::Config.string_to_array(space_str)).to eq(ary)
372
+ end
373
+ end
374
+
375
+ context "given a string with commas in it" do
376
+ it "should return an array containing the contents of that string" do
377
+ comma_str = "FOO,BAR,ARR,RAY"
378
+ expect(Pkg::Config.string_to_array(comma_str)).to eq(ary)
379
+ end
380
+ end
381
+
382
+ context "given a string with semicolons in it" do
383
+ it "should return an array containing the contents of that string" do
384
+ semi_str = "FOO;BAR;ARR;RAY"
385
+ expect(Pkg::Config.string_to_array(semi_str)).to eq(ary)
386
+ end
387
+ end
388
+
389
+ context "given a string with multiple delimiters in it" do
390
+ delimiters = [',', ' ', ';']
391
+ mixed_str = "FOO, BAR, ARR, ; RAY"
392
+ mixed_arr = Pkg::Config.string_to_array(mixed_str)
393
+
394
+ it "should not return the delimiters as array items" do
395
+ expect(mixed_arr).to_not include(*delimiters)
396
+ end
397
+
398
+ it "should not contain empty strings" do
399
+ expect(mixed_arr).to_not include("\s")
400
+ end
401
+
402
+ it "should still return the expected array" do
403
+ expect(mixed_arr).to eq(ary)
404
+ end
405
+ end
406
+ end
407
+
408
+ describe "#cow_list" do
409
+ it "should return a list of the cows for a project" do
410
+ Pkg::Config.cows = "base-lucid-i386.cow base-lucid-amd64.cow base-precise-i386.cow base-precise-amd64.cow base-quantal-i386.cow base-quantal-amd64.cow base-saucy-i386.cow base-saucy-amd64.cow base-sid-i386.cow base-sid-amd64.cow base-squeeze-i386.cow base-squeeze-amd64.cow base-stable-i386.cow base-stable-amd64.cow base-testing-i386.cow base-testing-amd64.cow base-trusty-i386.cow base-trusty-amd64.cow base-unstable-i386.cow base-unstable-amd64.cow base-wheezy-i386.cow base-wheezy-amd64.cow"
411
+ Pkg::Config.cow_list.should eq "lucid precise quantal saucy sid squeeze stable testing trusty unstable wheezy"
412
+ end
413
+ end
414
+
415
+ describe "#config" do
416
+ context "given :format => :hash" do
417
+ it "should call Pkg::Config.config_to_hash" do
418
+ expect(Pkg::Config).to receive(:config_to_hash)
419
+ Pkg::Config.config(:target => nil, :format => :hash)
420
+ end
421
+ end
422
+
423
+ context "given :format => :yaml" do
424
+ it "should call Pkg::Config.config_to_yaml if given :format => :yaml" do
425
+ expect(Pkg::Config).to receive(:config_to_yaml)
426
+ Pkg::Config.config(:target => nil, :format => :yaml)
427
+ end
428
+ end
429
+ end
430
+
431
+ describe "#issue_reassignments" do
432
+ around do |example|
433
+ prev_tar_host = Pkg::Config.tar_host
434
+ Pkg::Config.tar_host = nil
435
+ example.run
436
+ Pkg::Config.tar_host = prev_tar_host
437
+ end
438
+
439
+ it "should set tar_host to staging_server" do
440
+ Pkg::Config.config_from_hash({ :staging_server => 'foo' })
441
+ Pkg::Config.issue_reassignments
442
+ Pkg::Config.tar_host.should eq("foo")
443
+ end
444
+ end
445
+
446
+ describe "#config_to_hash" do
447
+ it "should return a hash object" do
448
+ hash = Pkg::Config.config_to_hash
449
+ hash.should be_a(Hash)
450
+ end
451
+
452
+ it "should return a hash with the current parameters" do
453
+ Pkg::Config.apt_host = "foo"
454
+ Pkg::Config.config_to_hash[:apt_host].should eq("foo")
455
+ Pkg::Config.apt_host = "bar"
456
+ Pkg::Config.config_to_hash[:apt_host].should eq("bar")
457
+ end
458
+ end
459
+
460
+ describe "#load_default_configs" do
461
+ before(:each) do
462
+ @project_root = double('project_root')
463
+ Pkg::Config.project_root = @project_root
464
+ @test_project_data = File.join(Pkg::Config.project_root, 'ext', 'project_data.yaml')
465
+ @test_build_defaults = File.join(Pkg::Config.project_root, 'ext', 'build_defaults.yaml')
466
+ end
467
+
468
+ around do |example|
469
+ orig = Pkg::Config.project_root
470
+ example.run
471
+ Pkg::Config.project_root = orig
472
+ end
473
+
474
+ context "given ext/build_defaults.yaml and ext/project_data.yaml are readable" do
475
+ it "should try to load build_defaults.yaml and project_data.yaml" do
476
+ allow(File).to receive(:readable?).with(@test_project_data).and_return(true)
477
+ allow(File).to receive(:readable?).with(@test_build_defaults).and_return(true)
478
+ expect(Pkg::Config).to receive(:config_from_yaml).with(@test_project_data)
479
+ expect(Pkg::Config).to receive(:config_from_yaml).with(@test_build_defaults)
480
+ Pkg::Config.load_default_configs
481
+ end
482
+ end
483
+
484
+ context "given ext/build_defaults.yaml is readable but ext/project_data.yaml is not" do
485
+ it "should try to load build_defaults.yaml but not project_data.yaml" do
486
+ allow(File).to receive(:readable?).with(@test_project_data).and_return(false)
487
+ allow(File).to receive(:readable?).with(@test_build_defaults).and_return(true)
488
+ expect(Pkg::Config).to_not receive(:config_from_yaml).with(@test_project_data)
489
+ expect(Pkg::Config).to receive(:config_from_yaml).with(@test_build_defaults)
490
+ Pkg::Config.load_default_configs
491
+ end
492
+ end
493
+
494
+ context "given ext/build_defaults.yaml is not readable but ext/project_data.yaml is" do
495
+ it "should try to load build_defaults.yaml then unset project_root" do
496
+ allow(File).to receive(:readable?).with(@test_project_data).and_return(true)
497
+ allow(File).to receive(:readable?).with(@test_build_defaults).and_return(false)
498
+ expect(Pkg::Config).to_not receive(:config_from_yaml).with(@test_build_defaults)
499
+ Pkg::Config.load_default_configs
500
+ expect(Pkg::Config.project_root).to be_nil
501
+ end
502
+ end
503
+
504
+ context "given ext/build_defaults.yaml and ext/project_data.yaml are not readable" do
505
+ it "should not try to load build_defaults.yaml and project_data.yaml" do
506
+ Pkg::Config.project_root = 'foo'
507
+ expect(Pkg::Config).to_not receive(:config_from_yaml)
508
+ Pkg::Config.load_default_configs
509
+ end
510
+
511
+ it "should set the project root to nil" do
512
+ Pkg::Config.project_root = 'foo'
513
+ Pkg::Config.load_default_configs
514
+ expect(Pkg::Config.project_root).to be_nil
515
+ end
516
+ end
517
+ end
518
+
519
+ describe "#load_versioning" do
520
+ around do |example|
521
+ orig = Pkg::Config.project_root
522
+ example.run
523
+ Pkg::Config.project_root = orig
524
+ end
525
+
526
+ # We let the actual version determination testing happen in the version
527
+ # tests. Here we just test that we try when we should.
528
+ context "When project root is nil" do
529
+ it "should not try to load versioning" do
530
+ Pkg::Config.project_root = nil
531
+ expect(Pkg::Util::Version).to_not receive(:git_sha_or_tag)
532
+ Pkg::Config.load_versioning
533
+ end
534
+ end
535
+ end
536
+
537
+ describe "#load_envvars" do
538
+ # We're going to pollute the environment with this test, so afterwards we
539
+ # explicitly set everything to nil to prevent any hazardous effects on
540
+ # the rest of the tests.
541
+ after(:all) do
542
+ reset_env(Pkg::Params::ENV_VARS.map {|hash| hash[:envvar].to_s})
543
+ end
544
+
545
+ Pkg::Params::ENV_VARS.each do |v|
546
+ case v[:type]
547
+ when :bool
548
+ it "should set boolean value on #{v[:var]} for :type == :bool" do
549
+ ENV[v[:envvar].to_s] = "FOO"
550
+ Pkg::Util.stub(:boolean_value) {"FOO"}
551
+ allow(Pkg::Config).to receive(:instance_variable_set)
552
+ expect(Pkg::Util).to receive(:boolean_value).with("FOO")
553
+ expect(Pkg::Config).to receive(:instance_variable_set).with("@#{v[:var]}", "FOO")
554
+ Pkg::Config.load_envvars
555
+ end
556
+ when :array
557
+ it "should set Pkg::Config##{v[:var]} to an Array for :type == :array" do
558
+ ENV[v[:envvar].to_s] = "FOO BAR ARR RAY"
559
+ Pkg::Config.stub(:string_to_array) {%w(FOO BAR ARR RAY)}
560
+ allow(Pkg::Config).to receive(:instance_variable_set)
561
+ expect(Pkg::Config).to receive(:string_to_array).with("FOO BAR ARR RAY")
562
+ expect(Pkg::Config).to receive(:instance_variable_set).with("@#{v[:var]}", %w(FOO BAR ARR RAY))
563
+ Pkg::Config.load_envvars
564
+ end
565
+ else
566
+ it "should set Pkg::Config##{v[:var]} to ENV[#{v[:envvar].to_s}]" do
567
+ ENV[v[:envvar].to_s] = "FOO"
568
+ Pkg::Util.stub(:boolean_value) {"FOO"}
569
+ allow(Pkg::Config).to receive(:instance_variable_set)
570
+ expect(Pkg::Config).to receive(:instance_variable_set).with("@#{v[:var]}", "FOO")
571
+ Pkg::Config.load_envvars
572
+ end
573
+ end
574
+ end
575
+ end
576
+ end