omnibus 3.1.1 → 3.2.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +71 -0
  3. data/Gemfile +0 -7
  4. data/README.md +108 -36
  5. data/Rakefile +1 -5
  6. data/docs/omnibus-build-cache.md +5 -5
  7. data/features/commands/_deprecated.feature +21 -3
  8. data/features/step_definitions/generator_steps.rb +7 -7
  9. data/lib/omnibus.rb +232 -171
  10. data/lib/omnibus/build_version.rb +2 -2
  11. data/lib/omnibus/builder.rb +38 -19
  12. data/lib/omnibus/cleaner.rb +5 -5
  13. data/lib/omnibus/cleanroom.rb +141 -0
  14. data/lib/omnibus/cli.rb +6 -9
  15. data/lib/omnibus/cli/base.rb +2 -1
  16. data/lib/omnibus/cli/cache.rb +15 -21
  17. data/lib/omnibus/cli/deprecated.rb +40 -4
  18. data/lib/omnibus/cli/publish.rb +61 -0
  19. data/lib/omnibus/config.rb +350 -189
  20. data/lib/omnibus/digestable.rb +131 -0
  21. data/lib/omnibus/exceptions.rb +163 -83
  22. data/lib/omnibus/fetcher.rb +1 -1
  23. data/lib/omnibus/fetchers/net_fetcher.rb +19 -13
  24. data/lib/omnibus/fetchers/path_fetcher.rb +8 -1
  25. data/lib/omnibus/fetchers/s3_cache_fetcher.rb +16 -7
  26. data/lib/omnibus/generator.rb +2 -2
  27. data/lib/omnibus/generator_files/Gemfile.erb +4 -1
  28. data/lib/omnibus/generator_files/README.md.erb +10 -0
  29. data/lib/omnibus/generator_files/{omnibus.rb.example.erb → omnibus.rb.erb} +20 -11
  30. data/lib/omnibus/generator_files/package_scripts/makeselfinst.erb +1 -1
  31. data/lib/omnibus/generator_files/project.rb.erb +2 -2
  32. data/lib/omnibus/generator_files/windows_msi/localization-en-us.wxl.erb +3 -3
  33. data/lib/omnibus/git_cache.rb +192 -0
  34. data/lib/omnibus/health_check.rb +171 -116
  35. data/lib/omnibus/library.rb +4 -2
  36. data/lib/omnibus/logger.rb +60 -1
  37. data/lib/omnibus/null_argumentable.rb +51 -0
  38. data/lib/omnibus/ohai.rb +29 -8
  39. data/lib/omnibus/package.rb +240 -0
  40. data/lib/omnibus/packagers/base.rb +21 -42
  41. data/lib/omnibus/packagers/mac_dmg.rb +5 -5
  42. data/lib/omnibus/packagers/mac_pkg.rb +20 -19
  43. data/lib/omnibus/packagers/windows_msi.rb +7 -7
  44. data/lib/omnibus/project.rb +969 -486
  45. data/lib/omnibus/publisher.rb +76 -0
  46. data/lib/omnibus/publishers/artifactory_publisher.rb +168 -0
  47. data/lib/omnibus/publishers/null_publisher.rb +23 -0
  48. data/lib/omnibus/publishers/s3_publisher.rb +99 -0
  49. data/lib/omnibus/s3_cache.rb +150 -63
  50. data/lib/omnibus/software.rb +749 -321
  51. data/lib/omnibus/{sugar.rb → sugarable.rb} +11 -6
  52. data/lib/omnibus/version.rb +1 -1
  53. data/omnibus.gemspec +8 -8
  54. data/spec/data/complicated/config/projects/angrychef.rb +1 -1
  55. data/spec/data/complicated/config/projects/chef-windows.rb +1 -1
  56. data/spec/data/complicated/config/projects/chef.rb +1 -1
  57. data/spec/data/complicated/config/projects/chefdk-windows.rb +1 -1
  58. data/spec/data/complicated/config/projects/chefdk.rb +1 -1
  59. data/spec/data/complicated/config/software/cacerts.rb +1 -1
  60. data/spec/data/complicated/config/software/chef-client-msi.rb +1 -1
  61. data/spec/data/complicated/config/software/libgcc.rb +1 -1
  62. data/spec/data/complicated/config/software/libiconv.rb +0 -11
  63. data/spec/data/complicated/config/software/libpng.rb +2 -2
  64. data/spec/data/complicated/config/software/openssl.rb +1 -1
  65. data/spec/data/complicated/config/software/ruby.rb +1 -1
  66. data/spec/data/complicated/config/software/runit.rb +4 -4
  67. data/spec/data/projects/chefdk.rb +1 -1
  68. data/spec/data/projects/sample.rb +1 -1
  69. data/spec/data/software/erchef.rb +3 -1
  70. data/spec/functional/packagers/mac_spec.rb +25 -24
  71. data/spec/functional/packagers/windows_spec.rb +21 -20
  72. data/spec/spec_helper.rb +43 -4
  73. data/spec/unit/build_version_spec.rb +14 -16
  74. data/spec/unit/cleanroom_spec.rb +63 -0
  75. data/spec/unit/config_spec.rb +36 -30
  76. data/spec/unit/digestable_spec.rb +38 -0
  77. data/spec/unit/fetchers/net_fetcher_spec.rb +98 -87
  78. data/spec/unit/{install_path_cache_spec.rb → git_cache_spec.rb} +67 -56
  79. data/spec/unit/health_check_spec.rb +73 -0
  80. data/spec/unit/library_spec.rb +166 -159
  81. data/spec/unit/ohai_spec.rb +19 -0
  82. data/spec/unit/omnibus_spec.rb +43 -41
  83. data/spec/unit/package_spec.rb +178 -0
  84. data/spec/unit/packagers/base_spec.rb +17 -47
  85. data/spec/unit/packagers/mac_pkg_spec.rb +104 -126
  86. data/spec/unit/project_spec.rb +176 -25
  87. data/spec/unit/publisher_spec.rb +49 -0
  88. data/spec/unit/publishers/artifactory_publisher_spec.rb +80 -0
  89. data/spec/unit/publishers/s3_publisher_spec.rb +120 -0
  90. data/spec/unit/s3_cacher_spec.rb +84 -19
  91. data/spec/unit/software_spec.rb +397 -170
  92. data/spec/unit/sugarable_spec.rb +43 -0
  93. metadata +62 -50
  94. data/Guardfile +0 -10
  95. data/lib/omnibus/artifact.rb +0 -165
  96. data/lib/omnibus/cli/release.rb +0 -40
  97. data/lib/omnibus/generator_files/Vagrantfile.erb +0 -75
  98. data/lib/omnibus/install_path_cache.rb +0 -105
  99. data/lib/omnibus/overrides.rb +0 -88
  100. data/lib/omnibus/package_release.rb +0 -154
  101. data/lib/omnibus/software_s3_urls.rb +0 -50
  102. data/spec/unit/artifact_spec.rb +0 -91
  103. data/spec/unit/overrides_spec.rb +0 -102
  104. data/spec/unit/package_release_spec.rb +0 -180
  105. data/spec/unit/sugar_spec.rb +0 -17
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module Omnibus
4
+ describe Ohai do
5
+ context 'using dot notation' do
6
+ it 'does not raise an exception' do
7
+ expect { Ohai.kernel }.to_not raise_error
8
+ expect { Ohai.kernel.machine }.to_not raise_error
9
+ end
10
+ end
11
+
12
+ context 'using hash notation' do
13
+ it 'allows fetching values by hash notation' do
14
+ expect { Ohai['kernel'] }.to_not raise_error
15
+ expect { Ohai['kernel']['machine'] }.to_not raise_error
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,62 +2,64 @@ require 'omnibus'
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Omnibus do
5
- # evil class variables
6
- before { Omnibus.reset! }
7
- after { Omnibus.reset! }
8
-
9
- describe '::omnibus_software_root' do
10
- it 'reads the software_gem out of Omnibus::Config.software_gem' do
11
- spec_array = [double(Gem::Specification, gem_dir: '/data')]
12
- expect(Omnibus::Config).to receive(:software_gem)
13
- .and_return('my-omnibus-software-gem')
14
- expect(Gem::Specification).to receive(:find_all_by_name)
15
- .with('my-omnibus-software-gem')
16
- .and_return(spec_array)
17
-
18
- Omnibus.omnibus_software_root
19
- end
5
+ before do
6
+ allow(File).to receive(:directory?).and_return(true)
20
7
 
21
- it 'uses the omnibus-software gem as the default' do
22
- spec_array = [double(Gem::Specification, gem_dir: '/data')]
23
- expect(Gem::Specification).to receive(:find_all_by_name)
24
- .with('omnibus-software')
25
- .and_return(spec_array)
8
+ allow(Gem::Specification).to receive(:find_all_by_name)
9
+ .with('omnibus-software')
10
+ .and_return([double(gem_dir: '/gem/omnibus-software')])
26
11
 
27
- Omnibus.omnibus_software_root
28
- end
12
+ allow(Gem::Specification).to receive(:find_all_by_name)
13
+ .with('custom-omnibus-software')
14
+ .and_return([double(gem_dir: '/gem/custom-omnibus-software')])
15
+
16
+ Omnibus::Config.project_root('/foo/bar')
17
+ Omnibus::Config.local_software_dirs(['/local', '/other'])
18
+ Omnibus::Config.software_gems(['omnibus-software', 'custom-omnibus-software'])
29
19
  end
30
20
 
31
21
  describe '#software_dirs' do
32
- context 'omnibus_software_root not nil' do
33
- before do
34
- Omnibus.stub(:omnibus_software_root) { './data' }
35
- end
36
-
37
- it 'will include list of software from omnibus-software gem' do
38
- expect(Omnibus.software_dirs.length).to eq(2)
39
- end
22
+ let(:software_dirs) { Omnibus.software_dirs }
23
+
24
+ it 'includes project_root' do
25
+ expect(software_dirs).to include('/foo/bar/config/software')
26
+ end
27
+
28
+ it 'includes local_software_dirs dirs' do
29
+ expect(software_dirs).to include('/local/config/software')
30
+ expect(software_dirs).to include('/other/config/software')
40
31
  end
41
32
 
42
- context 'omnibus_software_root nil' do
43
- before do
44
- Omnibus.stub(:omnibus_software_root) { nil }
45
- end
33
+ it 'includes software_gems dirs' do
34
+ expect(software_dirs).to include('/gem/omnibus-software/config/software')
35
+ expect(software_dirs).to include('/gem/custom-omnibus-software/config/software')
36
+ end
37
+
38
+ it 'has the correct precedence order' do
39
+ expect(software_dirs).to eq([
40
+ '/foo/bar/config/software',
41
+ '/local/config/software',
42
+ '/other/config/software',
43
+ '/gem/omnibus-software/config/software',
44
+ '/gem/custom-omnibus-software/config/software',
45
+ ])
46
+ end
47
+ end
48
+
49
+ describe '#software_map' do
50
+ let(:software_map) { Omnibus.send(:software_map) }
46
51
 
47
- it 'will not include list of software from omnibus-software gem' do
48
- expect(Omnibus.software_dirs.length).to eq(1)
49
- end
52
+ it 'returns a hash' do
53
+ expect(software_map).to be_a(Hash)
50
54
  end
51
55
  end
52
56
 
53
57
  describe '#process_dsl_files' do
54
58
  before do
55
- Omnibus.stub(:project_root).and_return(complicated_path)
56
- stub_ohai(platform: 'linux')
59
+ Omnibus::Config.project_root(complicated_path)
60
+ stub_ohai(platform: 'ubuntu', version: '12.04')
57
61
  end
58
62
 
59
- after { Omnibus.reset! }
60
-
61
63
  it 'populates the 5 projects' do
62
64
  Omnibus.process_dsl_files
63
65
 
@@ -0,0 +1,178 @@
1
+ require 'spec_helper'
2
+
3
+ module Omnibus
4
+ describe Package::Metadata do
5
+ let(:instance) do
6
+ double(Package::Metadata,
7
+ path: '/path/to/package.deb.metadata.json',
8
+ )
9
+ end
10
+
11
+ let(:package) do
12
+ double(Package,
13
+ name: 'package',
14
+ path: '/path/to/package.deb',
15
+ md5: 'abc123',
16
+ sha1: 'abc123',
17
+ sha256: 'abcd1234',
18
+ sha512: 'abcdef123456',
19
+ )
20
+ end
21
+
22
+ let(:data) { { foo: 'bar' } }
23
+
24
+ subject { described_class.new(package, data) }
25
+
26
+ describe '.generate' do
27
+ it 'writes out the file' do
28
+ described_class.stub(:new).and_return(instance)
29
+ expect(instance).to receive(:save).once
30
+
31
+ described_class.generate(package, data)
32
+ end
33
+ end
34
+
35
+ describe '.for_package' do
36
+ it 'raises an exception when the file does not exist' do
37
+ File.stub(:read).and_raise(Errno::ENOENT)
38
+ expect { described_class.for_package(package) }
39
+ .to raise_error(NoPackageMetadataFile)
40
+ end
41
+
42
+ it 'returns a metadata object' do
43
+ File.stub(:read).and_return('{ "platform": "ubuntu" }')
44
+ expect(described_class.for_package(package)).to be_a(described_class)
45
+ end
46
+
47
+ it 'loads the metadata from disk' do
48
+ File.stub(:read).and_return('{ "platform": "ubuntu" }')
49
+ instance = described_class.for_package(package)
50
+
51
+ expect(instance[:platform]).to eq('ubuntu')
52
+ end
53
+ end
54
+
55
+ describe '.path_for' do
56
+ it 'returns the postfixed .metadata.json' do
57
+ expect(described_class.path_for(package))
58
+ .to eq('/path/to/package.deb.metadata.json')
59
+ end
60
+ end
61
+
62
+ describe '#name' do
63
+ it 'returns the basename of the package' do
64
+ expect(subject.name).to eq('package.deb.metadata.json')
65
+ end
66
+ end
67
+
68
+ describe '#path' do
69
+ it 'delegates to .path_for' do
70
+ expect(described_class).to receive(:path_for).once
71
+ subject.path
72
+ end
73
+ end
74
+
75
+ describe '#save' do
76
+ let(:file) { double(File) }
77
+
78
+ before { File.stub(:open).and_yield(file) }
79
+
80
+ it 'saves the file to disk' do
81
+ expect(file).to receive(:write).once
82
+ subject.save
83
+ end
84
+ end
85
+
86
+ describe '#to_json' do
87
+ it 'generates pretty JSON' do
88
+ expect(subject.to_json).to eq <<-EOH.gsub(/^ {10}/, '').strip
89
+ {
90
+ "foo": "bar"
91
+ }
92
+ EOH
93
+ end
94
+ end
95
+ end
96
+
97
+ describe Package do
98
+ let(:path) { '/path/to/files/thing.deb' }
99
+
100
+ subject { described_class.new(path) }
101
+
102
+ describe '.initialize' do
103
+ it 'sets the path' do
104
+ expect(subject.instance_variables).to include(:@path)
105
+ end
106
+ end
107
+
108
+ describe '#name' do
109
+ it 'returns the basename of the file' do
110
+ expect(subject.name).to eq('thing.deb')
111
+ end
112
+ end
113
+
114
+ describe '#md5' do
115
+ let(:md5) { 'abcdef123456' }
116
+
117
+ before { subject.stub(:digest).with(path, :md5).and_return(md5) }
118
+
119
+ it 'returns the md5 of the package at the path' do
120
+ expect(subject.md5).to eq(md5)
121
+ end
122
+ end
123
+
124
+ describe '#sha256' do
125
+ let(:sha256) { 'abcdef123456' }
126
+
127
+ before { subject.stub(:digest).with(path, :sha256).and_return(sha256) }
128
+
129
+ it 'returns the sha256 of the package at the path' do
130
+ expect(subject.sha256).to eq(sha256)
131
+ end
132
+ end
133
+
134
+ describe '#sha512' do
135
+ let(:sha512) { 'abcdef123456' }
136
+
137
+ before { subject.stub(:digest).with(path, :sha512).and_return(sha512) }
138
+
139
+ it 'returns the sha512 of the package at the path' do
140
+ expect(subject.sha512).to eq(sha512)
141
+ end
142
+ end
143
+
144
+ describe '#content' do
145
+ context 'when the file exists' do
146
+ let(:content) { 'BINARY' }
147
+
148
+ before { IO.stub(:read).with(path).and_return(content) }
149
+
150
+ it 'reads the file' do
151
+ expect(subject.content).to eq(content)
152
+ end
153
+ end
154
+
155
+ context 'when the file does not exist' do
156
+ before { IO.stub(:read).and_raise(Errno::ENOENT) }
157
+
158
+ it 'raises an exception' do
159
+ expect { subject.content }.to raise_error(NoPackageFile)
160
+ end
161
+ end
162
+ end
163
+
164
+ describe '#metadata' do
165
+ let(:content) { '{ "platform": "ubuntu" }' }
166
+
167
+ before { IO.stub(:read).and_return(content) }
168
+
169
+ it 'returns a Metadata object' do
170
+ expect(subject.metadata).to be_a(Package::Metadata)
171
+ end
172
+
173
+ it 'reads the information in the file' do
174
+ expect(subject.metadata[:platform]).to eq('ubuntu')
175
+ end
176
+ end
177
+ end
178
+ end
@@ -2,19 +2,21 @@ require 'stringio'
2
2
 
3
3
  module Omnibus
4
4
  describe Packager::Base do
5
+ before do
6
+ Config.package_tmp('pkg-tmp')
7
+ end
8
+
5
9
  let(:project) do
6
- double('project',
7
- name: 'hamlet',
8
- build_version: '1.0.0',
9
- iteration: '12902349',
10
- mac_pkg_identifier: 'com.chef.hamlet',
11
- install_path: '/opt/hamlet',
12
- package_scripts_path: 'package-scripts',
13
- files_path: 'files',
14
- package_dir: 'pkg',
15
- package_tmp: 'pkg-tmp',
16
- resources_path: nil,
17
- friendly_name: 'HAMLET',
10
+ double(Project,
11
+ name: 'hamlet',
12
+ build_version: '1.0.0',
13
+ iteration: '12902349',
14
+ mac_pkg_identifier: 'com.chef.hamlet',
15
+ install_dir: '/opt/hamlet',
16
+ package_scripts_path: 'package-scripts',
17
+ files_path: 'files',
18
+ resources_path: nil,
19
+ friendly_name: 'HAMLET',
18
20
  )
19
21
  end
20
22
 
@@ -24,38 +26,6 @@ module Omnibus
24
26
  expect(subject).to be_a(Util)
25
27
  end
26
28
 
27
- it 'delegates #name to @project' do
28
- expect(subject.name).to eq(project.name)
29
- end
30
-
31
- it 'delegates #friendly_name to @project' do
32
- expect(subject.friendly_name).to eq(project.friendly_name)
33
- end
34
-
35
- it 'delegates #version to @project' do
36
- expect(subject.version).to eq(project.build_version)
37
- end
38
-
39
- it 'delegates #iteration to @project' do
40
- expect(subject.iteration).to eq(project.iteration)
41
- end
42
-
43
- it 'delegates #identifer to @project' do
44
- expect(subject.identifier).to eq(project.mac_pkg_identifier)
45
- end
46
-
47
- it 'delegates #scripts to @project' do
48
- expect(subject.scripts).to eq(project.package_scripts_path)
49
- end
50
-
51
- it 'delegates #files_path to @project' do
52
- expect(subject.files_path).to eq(project.files_path)
53
- end
54
-
55
- it 'delegates #package_dir to @project' do
56
- expect(subject.package_dir).to eq(project.package_dir)
57
- end
58
-
59
29
  describe '.setup' do
60
30
  it 'sets the value of the block' do
61
31
  block = proc {}
@@ -168,7 +138,7 @@ module Omnibus
168
138
 
169
139
  before do
170
140
  input = StringIO.new
171
- input.write('<%= friendly_name %>')
141
+ input.write('<%= project.friendly_name %>')
172
142
  input.rewind
173
143
 
174
144
  File.stub(:open).with(source_path).and_yield(input)
@@ -245,14 +215,14 @@ module Omnibus
245
215
 
246
216
  describe '#staging_dir' do
247
217
  it 'is the project package tmp and underscored named' do
248
- name = "#{project.package_tmp}/base"
218
+ name = "#{Config.package_tmp}/base"
249
219
  expect(subject.send(:staging_dir)).to eq(File.expand_path(name))
250
220
  end
251
221
  end
252
222
 
253
223
  describe '#staging_resources_path' do
254
224
  it 'is base/Resources under package temp' do
255
- name = "#{project.package_tmp}/base/Resources"
225
+ name = "#{Config.package_tmp}/base/Resources"
256
226
  expect(subject.send(:staging_resources_path)).to eq(File.expand_path(name))
257
227
  end
258
228
  end
@@ -1,24 +1,25 @@
1
1
  require 'stringio'
2
2
  require 'spec_helper'
3
3
 
4
- describe Omnibus::Packager::MacPkg do
5
-
6
- let(:project_name) { 'myproject' }
7
-
8
- let(:mac_pkg_identifier) { 'com.mycorp.myproject' }
4
+ module Omnibus
5
+ describe Packager::MacPkg do
6
+ before do
7
+ Config.package_dir('/home/someuser/omnibus-myproject/pkg')
8
+ Config.package_tmp('/var/cache/omnibus/pkg-tmp')
9
+ end
9
10
 
10
- let(:omnibus_root) { '/omnibus/project/root' }
11
+ let(:project_name) { 'myproject' }
11
12
 
12
- let(:scripts_path) { "#{omnibus_root}/scripts" }
13
+ let(:mac_pkg_identifier) { 'com.mycorp.myproject' }
13
14
 
14
- let(:package_dir) { '/home/someuser/omnibus-myproject/pkg' }
15
+ let(:omnibus_root) { '/omnibus/project/root' }
15
16
 
16
- let(:package_tmp) { '/var/cache/omnibus/pkg-tmp' }
17
+ let(:scripts_path) { "#{omnibus_root}/scripts" }
17
18
 
18
- let(:files_path) { "#{omnibus_root}/files" }
19
+ let(:files_path) { "#{omnibus_root}/files" }
19
20
 
20
- let(:expected_distribution_content) do
21
- <<-EOH
21
+ let(:expected_distribution_content) do
22
+ <<-EOH
22
23
  <?xml version="1.0" standalone="no"?>
23
24
  <installer-gui-script minSpecVersion="1">
24
25
  <title>Myproject</title>
@@ -40,134 +41,111 @@ describe Omnibus::Packager::MacPkg do
40
41
  </choice>
41
42
  <pkg-ref id="com.mycorp.myproject" version="23.4.2" onConclusion="none">myproject-core.pkg</pkg-ref>
42
43
  </installer-gui-script>
43
- EOH
44
- end
45
-
46
- let(:expected_distribution_path) { '/var/cache/omnibus/pkg-tmp/mac_pkg/Distribution' }
47
-
48
- let(:pkg_signing_config) do
49
- {
50
- sign_pkg: false,
51
- signing_identity: nil,
52
- }
53
- end
54
-
55
- let(:project) do
56
- double Omnibus::Project,
57
- name: project_name,
58
- build_version: '23.4.2',
59
- iteration: 4,
60
- maintainer: "Joe's Software",
61
- install_path: '/opt/myproject',
62
- package_scripts_path: scripts_path,
63
- files_path: files_path,
64
- package_dir: package_dir,
65
- package_tmp: package_tmp,
66
- mac_pkg_identifier: mac_pkg_identifier,
67
- config: pkg_signing_config,
68
- friendly_name: 'Myproject'
69
- end
70
-
71
- let(:packager) do
72
- Omnibus::Packager::MacPkg.new(project)
73
- end
74
-
75
- it "uses the project's version" do
76
- expect(packager.version).to eq(project.build_version)
77
- end
78
-
79
- it "uses the project's name" do
80
- expect(packager.name).to eq(project.name)
81
- end
82
-
83
- it "uses the project's mac_pkg_identifier" do
84
- expect(packager.identifier).to eq(mac_pkg_identifier)
85
- end
86
-
87
- it 'names the component package PROJECT_NAME-core.pkg' do
88
- expect(packager.component_pkg).to eq('myproject-core.pkg')
89
- end
90
-
91
- it 'names the product package PROJECT_NAME.pkg' do
92
- expect(packager.package_name).to eq('myproject-23.4.2-4.pkg')
93
- end
94
-
95
- it "use's the project's package_scripts_path" do
96
- expect(packager.scripts).to eq(project.package_scripts_path)
97
- end
44
+ EOH
45
+ end
98
46
 
99
- it 'runs pkgbuild' do
100
- expect(packager).to receive(:execute).with <<-EOH.gsub(/^ {6}/, '')
101
- pkgbuild \\
102
- --identifier "com.mycorp.myproject" \\
103
- --version "23.4.2" \\
104
- --scripts "/omnibus/project/root/scripts" \\
105
- --root "/opt/myproject" \\
106
- --install-location "/opt/myproject" \\
107
- "myproject-core.pkg"
108
- EOH
109
- packager.build_component_pkg
110
- end
47
+ let(:expected_distribution_path) { '/var/cache/omnibus/pkg-tmp/mac_pkg/Distribution' }
48
+
49
+ let(:project) do
50
+ double(Project,
51
+ name: project_name,
52
+ build_version: '23.4.2',
53
+ iteration: 4,
54
+ maintainer: "Joe's Software",
55
+ install_dir: '/opt/myproject',
56
+ files_path: files_path,
57
+ package_scripts_path: scripts_path,
58
+ mac_pkg_identifier: mac_pkg_identifier,
59
+ friendly_name: 'Myproject'
60
+ )
61
+ end
111
62
 
112
- it 'generates a Distribution file describing the product package content' do
113
- file = StringIO.new
114
- File.stub(:open).with(any_args).and_yield(file)
63
+ let(:packager) { Packager::MacPkg.new(project) }
115
64
 
116
- expect(file).to receive(:puts).with(expected_distribution_content)
117
- packager.generate_distribution
118
- end
65
+ it 'names the component package PROJECT_NAME-core.pkg' do
66
+ expect(packager.component_pkg).to eq('myproject-core.pkg')
67
+ end
119
68
 
120
- describe 'generating the distribution file' do
121
- let(:distribution_file) { StringIO.new }
69
+ it 'names the product package PROJECT_NAME.pkg' do
70
+ expect(packager.package_name).to eq('myproject-23.4.2-4.pkg')
71
+ end
122
72
 
123
- before do
124
- expect(File).to receive(:open)
125
- .with(expected_distribution_path, 'w', 0600)
126
- .and_yield(distribution_file)
73
+ it 'runs pkgbuild' do
74
+ expect(packager).to receive(:execute).with <<-EOH.gsub(/^ {8}/, '')
75
+ pkgbuild \\
76
+ --identifier "com.mycorp.myproject" \\
77
+ --version "23.4.2" \\
78
+ --scripts "/omnibus/project/root/scripts" \\
79
+ --root "/opt/myproject" \\
80
+ --install-location "/opt/myproject" \\
81
+ "myproject-core.pkg"
82
+ EOH
83
+ packager.build_component_pkg
127
84
  end
128
85
 
129
- it 'writes the distribution file to the staging directory' do
86
+ it 'generates a Distribution file describing the product package content' do
87
+ file = StringIO.new
88
+ File.stub(:open).with(any_args).and_yield(file)
89
+
90
+ expect(file).to receive(:puts).with(expected_distribution_content)
130
91
  packager.generate_distribution
131
- expect(distribution_file.string).to eq(expected_distribution_content)
132
92
  end
133
- end
134
93
 
135
- describe 'building the product package' do
136
- it 'generates the distribution and runs productbuild' do
137
- expect(packager).to receive(:execute).with ['productbuild',
138
- %Q(--distribution "/var/cache/omnibus/pkg-tmp/mac_pkg/Distribution"),
139
- %Q(--resources "/var/cache/omnibus/pkg-tmp/mac_pkg/Resources"),
140
- '/home/someuser/omnibus-myproject/pkg/myproject-23.4.2-4.pkg',
141
- ].join(' ')
142
- packager.build_product_pkg
143
- end
144
- end
94
+ describe 'generating the distribution file' do
95
+ let(:distribution_file) { StringIO.new }
145
96
 
146
- context 'when pkg signing is enabled' do
147
- let(:pkg_signing_config) do
148
- {
149
- sign_pkg: true,
150
- signing_identity: 'My Special Identity',
151
- }
152
- end
97
+ before do
98
+ expect(File).to receive(:open)
99
+ .with(expected_distribution_path, 'w', 0600)
100
+ .and_yield(distribution_file)
101
+ end
153
102
 
154
- it 'includes the signing parameters in the product build command' do
155
- expect(packager).to receive(:execute).with ['productbuild',
156
- %Q(--distribution "/var/cache/omnibus/pkg-tmp/mac_pkg/Distribution"),
157
- %Q(--resources "/var/cache/omnibus/pkg-tmp/mac_pkg/Resources"),
158
- %Q(--sign "My Special Identity"),
159
- '/home/someuser/omnibus-myproject/pkg/myproject-23.4.2-4.pkg',
160
- ].join(' ')
161
- packager.build_product_pkg
103
+ it 'writes the distribution file to the staging directory' do
104
+ packager.generate_distribution
105
+ expect(distribution_file.string).to eq(expected_distribution_content)
106
+ end
162
107
  end
163
- end
164
-
165
- context "when the mac_pkg_identifier isn't specified by the project" do
166
- let(:mac_pkg_identifier) { nil }
167
- let(:project_name) { 'My $Project' }
168
108
 
169
- it 'uses com.example.PROJECT_NAME as the identifier' do
170
- expect(packager.identifier).to eq('test.joessoftware.pkg.myproject')
109
+ describe '#build_product_pkg' do
110
+ context 'when pkg signing is disabled' do
111
+ it 'generates the distribution and runs productbuild' do
112
+ expect(packager).to receive(:execute).with <<-EOH.gsub(/^ {12}/, '')
113
+ productbuild \\
114
+ --distribution "/var/cache/omnibus/pkg-tmp/mac_pkg/Distribution" \\
115
+ --resources "/var/cache/omnibus/pkg-tmp/mac_pkg/Resources" \\
116
+ "/home/someuser/omnibus-myproject/pkg/myproject-23.4.2-4.pkg"
117
+ EOH
118
+
119
+ packager.build_product_pkg
120
+ end
121
+ end
122
+
123
+ context 'when pkg signing is enabled' do
124
+ before do
125
+ Config.sign_pkg(true)
126
+ Config.signing_identity('My Special Identity')
127
+ end
128
+
129
+ it 'includes the signing parameters in the product build command' do
130
+ expect(packager).to receive(:execute).with <<-EOH.gsub(/^ {12}/, '')
131
+ productbuild \\
132
+ --distribution "/var/cache/omnibus/pkg-tmp/mac_pkg/Distribution" \\
133
+ --resources "/var/cache/omnibus/pkg-tmp/mac_pkg/Resources" \\
134
+ --sign "My Special Identity" \\
135
+ "/home/someuser/omnibus-myproject/pkg/myproject-23.4.2-4.pkg"
136
+ EOH
137
+ packager.build_product_pkg
138
+ end
139
+ end
140
+
141
+ context "when the mac_pkg_identifier isn't specified by the project" do
142
+ let(:mac_pkg_identifier) { nil }
143
+ let(:project_name) { 'My $Project' }
144
+
145
+ it 'uses com.example.PROJECT_NAME as the identifier' do
146
+ expect(packager.identifier).to eq('test.joessoftware.pkg.myproject')
147
+ end
148
+ end
171
149
  end
172
150
  end
173
151
  end