omnibus 1.3.0 → 2.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -1
  3. data/.rubocop.yml +30 -0
  4. data/.travis.yml +14 -3
  5. data/CHANGELOG.md +72 -49
  6. data/Gemfile +8 -5
  7. data/NOTICE +2 -2
  8. data/README.md +65 -7
  9. data/Rakefile +12 -3
  10. data/bin/makeself-header.sh +1 -1
  11. data/bin/makeself.sh +2 -2
  12. data/bin/omnibus +2 -2
  13. data/functional/fixtures/mac_pkg/files/mac_pkg/Resources/background.png +0 -0
  14. data/functional/fixtures/mac_pkg/files/mac_pkg/Resources/license.html +1 -0
  15. data/functional/fixtures/mac_pkg/files/mac_pkg/Resources/welcome.html +1 -0
  16. data/functional/fixtures/mac_pkg/package-scripts/functional-test-project/postinstall +4 -0
  17. data/functional/packagers/mac_pkg_spec.rb +72 -0
  18. data/lib/omnibus/artifact.rb +11 -13
  19. data/lib/omnibus/build_version.rb +18 -21
  20. data/lib/omnibus/builder.rb +37 -48
  21. data/lib/omnibus/clean_tasks.rb +3 -5
  22. data/lib/omnibus/cli/application.rb +46 -53
  23. data/lib/omnibus/cli/base.rb +16 -19
  24. data/lib/omnibus/cli/build.rb +13 -13
  25. data/lib/omnibus/cli/cache.rb +13 -15
  26. data/lib/omnibus/cli/release.rb +4 -9
  27. data/lib/omnibus/cli.rb +2 -4
  28. data/lib/omnibus/config.rb +43 -23
  29. data/lib/omnibus/exceptions.rb +35 -1
  30. data/lib/omnibus/fetcher.rb +9 -13
  31. data/lib/omnibus/fetchers/git_fetcher.rb +15 -19
  32. data/lib/omnibus/fetchers/net_fetcher.rb +34 -38
  33. data/lib/omnibus/fetchers/path_fetcher.rb +7 -9
  34. data/lib/omnibus/fetchers/s3_cache_fetcher.rb +3 -4
  35. data/lib/omnibus/fetchers.rb +3 -3
  36. data/lib/omnibus/health_check.rb +126 -127
  37. data/lib/omnibus/library.rb +11 -12
  38. data/lib/omnibus/overrides.rb +6 -8
  39. data/lib/omnibus/package_release.rb +20 -22
  40. data/lib/omnibus/packagers/mac_pkg.rb +285 -0
  41. data/lib/omnibus/project.rb +215 -110
  42. data/lib/omnibus/reports.rb +16 -24
  43. data/lib/omnibus/s3_cacher.rb +15 -21
  44. data/lib/omnibus/software.rb +178 -88
  45. data/lib/omnibus/util.rb +25 -13
  46. data/lib/omnibus/version.rb +2 -2
  47. data/lib/omnibus.rb +11 -13
  48. data/omnibus.gemspec +20 -18
  49. data/spec/artifact_spec.rb +55 -52
  50. data/spec/build_version_spec.rb +121 -129
  51. data/spec/config_spec.rb +40 -0
  52. data/spec/data/projects/chefdk.rb +41 -0
  53. data/spec/data/projects/sample.rb +10 -0
  54. data/spec/data/software/erchef.rb +12 -12
  55. data/spec/data/software/zlib.rb +67 -0
  56. data/spec/fetchers/git_fetcher_spec.rb +55 -48
  57. data/spec/fetchers/net_fetcher_spec.rb +72 -78
  58. data/spec/omnibus_spec.rb +59 -0
  59. data/spec/overrides_spec.rb +64 -64
  60. data/spec/package_release_spec.rb +65 -64
  61. data/spec/packagers/mac_pkg_spec.rb +261 -0
  62. data/spec/project_spec.rb +138 -0
  63. data/spec/s3_cacher_spec.rb +9 -10
  64. data/spec/software_spec.rb +71 -50
  65. data/spec/spec_helper.rb +14 -7
  66. metadata +68 -60
  67. data/.rspec +0 -1
  68. data/.yardopts +0 -6
  69. data/spec/software_dirs_spec.rb +0 -34
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2012 Opscode, Inc.
2
+ # Copyright:: Copyright (c) 2012-2014 Chef Software, Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,75 +19,75 @@ require 'omnibus/package_release'
19
19
  require 'spec_helper'
20
20
 
21
21
  describe Omnibus::PackageRelease do
22
- let(:s3_key) { "s3key" }
23
- let(:s3_secret) { "hey-bezos-store-my-stuff" }
24
- let(:s3_bucket) { "myorg-omnibus-packages" }
25
- let(:pkg_path) { "pkg/chef_11.4.0-183-g2c0040c-0.el6.x86_64.rpm" }
22
+ let(:s3_key) { 's3key' }
23
+ let(:s3_secret) { 'hey-bezos-store-my-stuff' }
24
+ let(:s3_bucket) { 'myorg-omnibus-packages' }
25
+ let(:pkg_path) { 'pkg/chef_11.4.0-183-g2c0040c-0.el6.x86_64.rpm' }
26
26
  let(:pkg_metadata_path) { "#{pkg_path}.metadata.json" }
27
27
 
28
28
  let(:config) do
29
29
  {
30
- :release_s3_access_key => s3_key,
31
- :release_s3_secret_key => s3_secret,
32
- :release_s3_bucket => s3_bucket
30
+ release_s3_access_key: s3_key,
31
+ release_s3_secret_key: s3_secret,
32
+ release_s3_bucket: s3_bucket,
33
33
  }
34
34
  end
35
35
  subject(:package_release) do
36
36
  Omnibus::PackageRelease.new(pkg_path)
37
37
  end
38
38
 
39
- it "has a package path" do
40
- package_release.package_path.should == pkg_path
39
+ it 'has a package path' do
40
+ expect(package_release.package_path).to eq(pkg_path)
41
41
  end
42
42
 
43
43
  it "defaults to `:private' access policy" do
44
- package_release.access_policy.should == :private
44
+ expect(package_release.access_policy).to eq(:private)
45
45
  end
46
46
 
47
- describe "validating configuration" do
47
+ describe 'validating configuration' do
48
48
 
49
49
  before do
50
50
  Omnibus.stub(:config).and_return(config)
51
51
  end
52
52
 
53
- it "validates that the s3 key is set" do
53
+ it 'validates that the s3 key is set' do
54
54
  config.delete(:release_s3_access_key)
55
- lambda { package_release.validate_config! }.should raise_error(Omnibus::InvalidS3ReleaseConfiguration)
55
+ expect { package_release.validate_config! }.to raise_error(Omnibus::InvalidS3ReleaseConfiguration)
56
56
  end
57
57
 
58
- it "validates that the s3 secret key is set" do
58
+ it 'validates that the s3 secret key is set' do
59
59
  config.delete(:release_s3_secret_key)
60
- lambda { package_release.validate_config! }.should raise_error(Omnibus::InvalidS3ReleaseConfiguration)
60
+ expect { package_release.validate_config! }.to raise_error(Omnibus::InvalidS3ReleaseConfiguration)
61
61
  end
62
62
 
63
- it "validates that the s3 bucket is set" do
63
+ it 'validates that the s3 bucket is set' do
64
64
  config.delete(:release_s3_bucket)
65
- lambda { package_release.validate_config! }.should raise_error(Omnibus::InvalidS3ReleaseConfiguration)
65
+ expect { package_release.validate_config! }.to raise_error(Omnibus::InvalidS3ReleaseConfiguration)
66
66
  end
67
67
 
68
- it "does not error on a valid configuration" do
69
- lambda { package_release.validate_config! }.should_not raise_error
68
+ it 'does not error on a valid configuration' do
69
+ expect { package_release.validate_config! }.to_not raise_error
70
70
  end
71
71
  end
72
72
 
73
- describe "validating package for upload" do
74
- it "ensures that the package file exists" do
75
- lambda { package_release.validate_package! }.should raise_error(Omnibus::NoPackageFile)
73
+ describe 'validating package for upload' do
74
+ it 'ensures that the package file exists' do
75
+ expect { package_release.validate_package! }.to raise_error(Omnibus::NoPackageFile)
76
76
  end
77
77
 
78
- it "ensures that there is a metadata file for the package" do
79
- File.should_receive(:exist?).with(pkg_path).and_return(true)
80
- File.should_receive(:exist?).with(pkg_metadata_path).and_return(false)
81
- lambda { package_release.validate_package! }.should raise_error(Omnibus::NoPackageMetadataFile)
78
+ it 'ensures that there is a metadata file for the package' do
79
+ expect(File).to receive(:exist?).with(pkg_path).and_return(true)
80
+ expect(File).to receive(:exist?).with(pkg_metadata_path).and_return(false)
81
+ expect { package_release.validate_package! }.to raise_error(Omnibus::NoPackageMetadataFile)
82
82
  end
83
83
  end
84
84
 
85
- context "with a valid config and package" do
85
+ context 'with a valid config and package' do
86
86
 
87
- let(:basename) { "chef_11.4.0-183-g2c0040c-0.el6.x86_64.rpm" }
88
- let(:md5) { "016f2e0854c69901b3f0ad8f99ffdb75" }
89
- let(:platform_path) { "el/6/x86_64" }
90
- let(:pkg_content) { "expected package content" }
87
+ let(:basename) { 'chef_11.4.0-183-g2c0040c-0.el6.x86_64.rpm' }
88
+ let(:md5) { '016f2e0854c69901b3f0ad8f99ffdb75' }
89
+ let(:platform_path) { 'el/6/x86_64' }
90
+ let(:pkg_content) { 'expected package content' }
91
91
 
92
92
  let(:metadata_json) do
93
93
  <<-E
@@ -111,38 +111,37 @@ describe Omnibus::PackageRelease do
111
111
  IO.stub(:read).with(pkg_path).and_return(pkg_content)
112
112
  end
113
113
 
114
- it "configures s3 with the given credentials" do
114
+ it 'configures s3 with the given credentials' do
115
115
  expected_s3_config = {
116
- :access_key => s3_key,
117
- :secret_access_key => s3_secret,
118
- :bucket => s3_bucket,
119
- :adaper => :net_http
116
+ access_key: s3_key,
117
+ secret_access_key: s3_secret,
118
+ bucket: s3_bucket,
119
+ adaper: :net_http,
120
120
  }
121
- UberS3.should_receive(:new).with(expected_s3_config)
121
+ expect(UberS3).to receive(:new).with(expected_s3_config)
122
122
  package_release.s3_client
123
123
  end
124
124
 
125
- it "generates the relative path for the package s3 key" do
126
- package_release.platform_path.should == platform_path
125
+ it 'generates the relative path for the package s3 key' do
126
+ expect(package_release.platform_path).to eq(platform_path)
127
127
  end
128
128
 
129
-
130
- it "uploads the package and metadata" do
131
- package_release.s3_client.should_receive(:store).with(
129
+ it 'uploads the package and metadata' do
130
+ expect(package_release.s3_client).to receive(:store).with(
132
131
  "#{platform_path}/#{basename}.metadata.json",
133
132
  metadata_json,
134
- :access => :private
133
+ access: :private,
135
134
  )
136
- package_release.s3_client.should_receive(:store).with(
135
+ expect(package_release.s3_client).to receive(:store).with(
137
136
  "#{platform_path}/#{basename}",
138
137
  pkg_content,
139
- :access => :private,
140
- :content_md5 => md5
138
+ access: :private,
139
+ content_md5: md5,
141
140
  )
142
141
  package_release.release
143
142
  end
144
143
 
145
- context "and a callback is given for after upload" do
144
+ context 'and a callback is given for after upload' do
146
145
  let(:upload_records) { [] }
147
146
 
148
147
  subject(:package_release) do
@@ -151,42 +150,44 @@ describe Omnibus::PackageRelease do
151
150
  end
152
151
  end
153
152
 
154
- it "fires the after_upload callback for each item uploaded" do
155
- package_release.s3_client.should_receive(:store).with(
153
+ it 'fires the after_upload callback for each item uploaded' do
154
+ expect(package_release.s3_client).to receive(:store).with(
156
155
  "#{platform_path}/#{basename}.metadata.json",
157
156
  metadata_json,
158
- :access => :private
157
+ access: :private,
159
158
  )
160
- package_release.s3_client.should_receive(:store).with(
159
+ expect(package_release.s3_client).to receive(:store).with(
161
160
  "#{platform_path}/#{basename}",
162
161
  pkg_content,
163
- :access => :private,
164
- :content_md5 => md5
162
+ access: :private,
163
+ content_md5: md5,
165
164
  )
166
165
  package_release.release
167
166
 
168
- upload_records.should == [ "#{platform_path}/#{basename}.metadata.json",
169
- "#{platform_path}/#{basename}" ]
167
+ expect(upload_records).to eq [
168
+ "#{platform_path}/#{basename}.metadata.json",
169
+ "#{platform_path}/#{basename}",
170
+ ]
170
171
  end
171
172
  end
172
173
 
173
- context "and the package is public" do
174
+ context 'and the package is public' do
174
175
 
175
176
  subject(:package_release) do
176
- Omnibus::PackageRelease.new(pkg_path, :access => :public_read)
177
+ Omnibus::PackageRelease.new(pkg_path, access: :public_read)
177
178
  end
178
179
 
179
- it "uploads the package and metadata" do
180
- package_release.s3_client.should_receive(:store).with(
180
+ it 'uploads the package and metadata' do
181
+ expect(package_release.s3_client).to receive(:store).with(
181
182
  "#{platform_path}/#{basename}.metadata.json",
182
183
  metadata_json,
183
- :access => :public_read
184
+ access: :public_read,
184
185
  )
185
- package_release.s3_client.should_receive(:store).with(
186
+ expect(package_release.s3_client).to receive(:store).with(
186
187
  "#{platform_path}/#{basename}",
187
188
  pkg_content,
188
- :access => :public_read,
189
- :content_md5 => md5
189
+ access: :public_read,
190
+ content_md5: md5,
190
191
  )
191
192
  package_release.release
192
193
  end
@@ -0,0 +1,261 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'stringio'
19
+ require 'omnibus/packagers/mac_pkg'
20
+ require 'spec_helper'
21
+
22
+ describe Omnibus::Packagers::MacPkg do
23
+
24
+ let(:project_name) { 'myproject' }
25
+
26
+ let(:mac_pkg_identifier) { 'com.mycorp.myproject' }
27
+
28
+ let(:omnibus_root) { '/omnibus/project/root' }
29
+
30
+ let(:scripts_path) { "#{omnibus_root}/scripts" }
31
+
32
+ let(:package_dir) { '/home/someuser/omnibus-myproject/pkg' }
33
+
34
+ let(:package_tmp) { '/var/cache/omnibus/pkg-tmp' }
35
+
36
+ let(:files_path) { "#{omnibus_root}/files" }
37
+
38
+ let(:expected_distribution_content) do
39
+ <<-EOH
40
+ <?xml version="1.0" standalone="no"?>
41
+ <installer-gui-script minSpecVersion="1">
42
+ <title>Myproject</title>
43
+ <background file="background.png" alignment="bottomleft" mime-type="image/png"/>
44
+ <welcome file="welcome.html" mime-type="text/html"/>
45
+ <license file="license.html" mime-type="text/html"/>
46
+
47
+ <!-- Generated by productbuild - - synthesize -->
48
+ <pkg-ref id="com.mycorp.myproject"/>
49
+ <options customize="never" require-scripts="false"/>
50
+ <choices-outline>
51
+ <line choice="default">
52
+ <line choice="com.mycorp.myproject"/>
53
+ </line>
54
+ </choices-outline>
55
+ <choice id="default"/>
56
+ <choice id="com.mycorp.myproject" visible="false">
57
+ <pkg-ref id="com.mycorp.myproject"/>
58
+ </choice>
59
+ <pkg-ref id="com.mycorp.myproject" version="23.4.2" onConclusion="none">myproject-core.pkg</pkg-ref>
60
+ </installer-gui-script>
61
+ EOH
62
+ end
63
+
64
+ let(:expected_distribution_path) { '/var/cache/omnibus/pkg-tmp/mac-pkg/Distribution' }
65
+
66
+ let(:productbuild_argv) do
67
+ %W[
68
+ productbuild
69
+ --distribution #{expected_distribution_path}
70
+ --resources /omnibus/project/root/files/mac_pkg/Resources
71
+ /home/someuser/omnibus-myproject/pkg/myproject.pkg
72
+ ]
73
+ end
74
+
75
+ let(:pkgbuild_argv) do
76
+ %w[
77
+ pkgbuild
78
+ --identifier com.mycorp.myproject
79
+ --version 23.4.2
80
+ --scripts /omnibus/project/root/scripts
81
+ --root /opt/myproject
82
+ --install-location /opt/myproject
83
+ myproject-core.pkg
84
+ ]
85
+ end
86
+
87
+ let(:shellout_opts) do
88
+ {
89
+ timeout: 3600,
90
+ cwd: File.join(package_tmp, 'mac-pkg'),
91
+ }
92
+ end
93
+
94
+ let(:project) do
95
+ double Omnibus::Project,
96
+ name: project_name,
97
+ build_version: '23.4.2',
98
+ maintainer: "Joe's Software",
99
+ install_path: '/opt/myproject',
100
+ package_scripts_path: scripts_path,
101
+ files_path: files_path,
102
+ package_dir: package_dir,
103
+ package_tmp: package_tmp,
104
+ mac_pkg_identifier: mac_pkg_identifier
105
+ end
106
+
107
+ let(:packager) do
108
+ Omnibus::Packagers::MacPkg.new(project)
109
+ end
110
+
111
+ it "uses the project's version" do
112
+ expect(packager.version).to eq(project.build_version)
113
+ end
114
+
115
+ it "uses the project's name" do
116
+ expect(packager.name).to eq(project.name)
117
+ end
118
+
119
+ it "uses the project's mac_pkg_identifier" do
120
+ expect(packager.identifier).to eq(mac_pkg_identifier)
121
+ end
122
+
123
+ it "uses the project's install_path as the package root" do
124
+ expect(packager.pkg_root).to eq(project.install_path)
125
+ end
126
+
127
+ it "uses the project's install_path as the package install location" do
128
+ expect(packager.install_location).to eq(project.install_path)
129
+ end
130
+
131
+ it 'names the component package PROJECT_NAME-core.pkg' do
132
+ expect(packager.component_pkg_name).to eq('myproject-core.pkg')
133
+ end
134
+
135
+ it 'names the product package PROJECT_NAME.pkg' do
136
+ # NOTE: #package_name is used by Project, so it's part of the **PUBLIC**
137
+ # API.
138
+ expect(packager.package_name).to eq('myproject.pkg')
139
+ expect(packager.product_pkg_name).to eq('myproject.pkg')
140
+ end
141
+
142
+ it "use's the project's package_scripts_path" do
143
+ expect(packager.scripts).to eq(project.package_scripts_path)
144
+ end
145
+
146
+ it "makes a list of required files to generate the 'product' pkg file" do
147
+ project_file_path = '/omnibus/project/root/files/mac_pkg/Resources'
148
+ required_files = %w[background.png welcome.html license.html].map do |basename|
149
+ File.join(project_file_path, basename)
150
+ end
151
+
152
+ expect(packager.required_files).to match_array(required_files)
153
+ end
154
+
155
+ it 'validates that all required files are present' do
156
+ expected_error_text = <<-E
157
+ Your omnibus repo is missing the following files required to build Mac
158
+ packages:
159
+ * /omnibus/project/root/files/mac_pkg/Resources/background.png
160
+ * /omnibus/project/root/files/mac_pkg/Resources/license.html
161
+ * /omnibus/project/root/files/mac_pkg/Resources/welcome.html
162
+ E
163
+ # RSpec 2.14.1 doesn't do nice diffs of expected error strings, so do this
164
+ # the hard way for now.
165
+ e = nil
166
+ begin
167
+ packager.validate_omnibus_project!
168
+ rescue => e
169
+ end
170
+ expect(e).to be_a(Omnibus::MissingMacPkgResource)
171
+ expect(e.to_s).to eq(expected_error_text)
172
+ end
173
+
174
+ it 'clears and recreates the staging dir' do
175
+ expect(FileUtils).to receive(:rm_rf).with('/var/cache/omnibus/pkg-tmp/mac-pkg')
176
+ expect(FileUtils).to receive(:mkdir_p).with('/var/cache/omnibus/pkg-tmp/mac-pkg')
177
+ packager.setup_staging_dir!
178
+ end
179
+
180
+ it 'generates a pkgbuild command' do
181
+ expect(packager.pkgbuild_command).to eq(pkgbuild_argv)
182
+ end
183
+
184
+ it 'runs pkgbuild' do
185
+ expected_args = pkgbuild_argv + [shellout_opts]
186
+ expect(packager).to receive(:shellout!).with(*expected_args)
187
+ packager.build_component_pkg
188
+ end
189
+
190
+ it 'has a temporary staging location for the distribution file' do
191
+ expect(packager.staging_dir).to eq('/var/cache/omnibus/pkg-tmp/mac-pkg')
192
+ end
193
+
194
+ it 'generates a Distribution file describing the product package content' do
195
+ expect(packager.distribution).to eq(expected_distribution_content)
196
+ end
197
+
198
+ it 'generates a productbuild command' do
199
+ expect(packager.productbuild_command).to eq(productbuild_argv)
200
+ end
201
+
202
+ describe 'building the product package' do
203
+
204
+ let(:distribution_file) { StringIO.new }
205
+
206
+ before do
207
+ expect(File).to receive(:open)
208
+ .with(expected_distribution_path, File::RDWR | File::CREAT | File::EXCL, 0600)
209
+ .and_yield(distribution_file)
210
+ end
211
+
212
+ it 'writes the distribution file to the staging directory' do
213
+ packager.generate_distribution
214
+ expect(distribution_file.string).to eq(expected_distribution_content)
215
+ end
216
+
217
+ it 'generates the distribution and runs productbuild' do
218
+ expected_shellout_args = productbuild_argv + [shellout_opts]
219
+
220
+ expect(packager).to receive(:shellout!).with(*expected_shellout_args)
221
+ packager.build_product_pkg
222
+ expect(distribution_file.string).to eq(expected_distribution_content)
223
+ end
224
+
225
+ end
226
+ context "when the mac_pkg_identifier isn't specified by the project" do
227
+
228
+ let(:mac_pkg_identifier) { nil }
229
+ let(:project_name) { 'My $Project' }
230
+
231
+ it 'sanitizes the MAINTAINER name' do
232
+ expect(packager.sanitized_maintainer).to eq('joessoftware')
233
+ end
234
+
235
+ it 'sanitizes the project name' do
236
+ expect(packager.sanitized_name).to eq('myproject')
237
+ end
238
+
239
+ it 'uses com.example.PROJECT_NAME as the identifier' do
240
+ expect(packager.identifier).to eq('test.joessoftware.pkg.myproject')
241
+ end
242
+
243
+ end
244
+
245
+ context 'when the project has the required Resource files' do
246
+
247
+ before do
248
+ project_file_path = '/omnibus/project/root/files/mac_pkg/Resources'
249
+ %w[background.png welcome.html license.html].each do |basename|
250
+ path = File.join(project_file_path, basename)
251
+ File.stub(:exist?).with(path).and_return(true)
252
+ end
253
+ end
254
+
255
+ it 'validates the presence of the required files' do
256
+ expect(packager.validate_omnibus_project!).to be_true
257
+ end
258
+
259
+ end
260
+
261
+ end
@@ -0,0 +1,138 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 Noah Kantrowitz
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the 'License');
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an 'AS IS' BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'spec_helper'
19
+
20
+ require 'omnibus/project'
21
+
22
+ describe Omnibus::Project do
23
+ let(:project) do
24
+ Omnibus::Project.load(project_path('sample'))
25
+ end
26
+
27
+ subject { project }
28
+
29
+ describe 'basics' do
30
+ it 'should return a name' do
31
+ expect(project.name).to eq('sample')
32
+ end
33
+
34
+ it 'should return an install path' do
35
+ expect(project.install_path).to eq('/sample')
36
+ end
37
+
38
+ it 'should return a maintainer' do
39
+ expect(project.maintainer).to eq('Sample Devs')
40
+ end
41
+
42
+ it 'should return a homepage' do
43
+ expect(project.homepage).to eq('http://example.com/')
44
+ end
45
+
46
+ it 'should return a build version' do
47
+ expect(project.build_version).to eq('1.0')
48
+ end
49
+
50
+ it 'should return a build iteration' do
51
+ expect(project.build_iteration).to eq('1')
52
+ end
53
+
54
+ it 'should return an array of files and dirs' do
55
+ expect(project.extra_package_files).to eq(['/path/to/sample_dir', '/path/to/file.conf'])
56
+ end
57
+ end
58
+
59
+ describe '#iteration' do
60
+ let(:fauxhai_options) { Hash.new }
61
+ around(:each) do |example|
62
+ data = OHAI.data
63
+ begin
64
+ OHAI.data = Mash.new(Fauxhai.mock(fauxhai_options).data)
65
+ example.run
66
+ ensure
67
+ OHAI.data = data
68
+ end
69
+ end
70
+
71
+ context 'when on RHEL' do
72
+ let(:fauxhai_options) { { platform: 'redhat', version: '6.4' } }
73
+ it 'should return a RHEL iteration' do
74
+ expect(project.iteration).to eq('1.el6')
75
+ end
76
+ end
77
+
78
+ context 'when on Debian' do
79
+ let(:fauxhai_options) { { platform: 'debian', version: '7.2' } }
80
+ it 'should return a Debian iteration' do
81
+ expect(project.iteration).to eq('1')
82
+ end
83
+ end
84
+
85
+ context 'when on FreeBSD' do
86
+ let(:fauxhai_options) { { platform: 'freebsd', version: '9.1' } }
87
+ it 'should return a FreeBSD iteration' do
88
+ expect(project.iteration).to eq('1.freebsd.9.amd64')
89
+ end
90
+ end
91
+
92
+ context 'when on Windows' do
93
+ let(:fauxhai_options) { { platform: 'windows', version: '2008R2' } }
94
+ it 'should return a Windows iteration' do
95
+ expect(project.iteration).to eq('1.windows')
96
+ end
97
+ end
98
+
99
+ context 'when on OS X' do
100
+ let(:fauxhai_options) { { platform: 'mac_os_x', version: '10.8.2' } }
101
+ it 'should return a generic iteration' do
102
+ expect(project.iteration).to eq('1.mac_os_x.10.8.2')
103
+ end
104
+ end
105
+ end
106
+
107
+ describe '#overrides' do
108
+ let(:project) { Omnibus::Project.load(project_path('chefdk')) }
109
+
110
+ it 'should set an override for the zlib version' do
111
+ expect(project.overrides[:zlib][:version]).to eq('1.2.8')
112
+ end
113
+
114
+ it 'should access the zlib version through the #override method as well' do
115
+ expect(project.override(:zlib)[:version]).to eq('1.2.8')
116
+ end
117
+
118
+ it 'should set all the things through #overrides' do
119
+ project.overrides(thing: { version: '6.6.6' })
120
+ expect(project.override(:zlib)).to be_nil
121
+ end
122
+
123
+ it 'should retrieve the things set through #overrides' do
124
+ project.overrides(thing: { version: '6.6.6' })
125
+ expect(project.override(:thing)[:version]).to eq('6.6.6')
126
+ end
127
+
128
+ it 'should not set other things through setting a single #override' do
129
+ project.override(:thing, version: '6.6.6')
130
+ expect(project.override(:zlib)[:version]).to eq('1.2.8')
131
+ end
132
+
133
+ it 'should retrieve the things set through #overrides' do
134
+ project.override(:thing, version: '6.6.6')
135
+ expect(project.override(:thing)[:version]).to eq('6.6.6')
136
+ end
137
+ end
138
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2013 Opscode, Inc.
2
+ # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,22 +26,21 @@ describe Omnibus::S3Cache do
26
26
  let(:source_a) { double(source: { url: 'a' }) }
27
27
  let(:source_b) { double(source: { url: 'b' }) }
28
28
  let(:source_c) { double(source: {}) }
29
- let(:projects) { [
30
- double({ library: [source_a, source_c] }),
31
- double({ library: [source_c, source_b] })
32
- ] }
29
+ let(:projects) do
30
+ [
31
+ double(library: [source_a, source_c]),
32
+ double(library: [source_c, source_b]),
33
+ ]
34
+ end
33
35
  let(:software_with_urls) { [source_a, source_b] }
34
36
 
35
37
  before do
36
- Omnibus.stub(config: double({
37
- s3_bucket: 'test', s3_access_key: 'test', s3_secret_key: 'test'
38
- }))
39
-
38
+ Omnibus.stub(config: double(s3_bucket: 'test', s3_access_key: 'test', s3_secret_key: 'test'))
40
39
  Omnibus.stub(projects: projects)
41
40
  end
42
41
 
43
42
  it 'lists all software with urls' do
44
- tarball_software.should == software_with_urls
43
+ expect(tarball_software).to eq(software_with_urls)
45
44
  end
46
45
  end
47
46
  end