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
@@ -1,28 +1,93 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Omnibus::S3Cache do
4
-
5
- describe '#tarball_software' do
6
- subject(:tarball_software) { described_class.new.tarball_software }
7
-
8
- let(:source_a) { double(source: { url: 'a' }) }
9
- let(:source_b) { double(source: { url: 'b' }) }
10
- let(:source_c) { double(source: {}) }
11
- let(:projects) do
12
- [
13
- double(library: [source_a, source_c]),
14
- double(library: [source_c, source_b]),
15
- ]
3
+ module Omnibus
4
+ describe S3Cache do
5
+ let(:ruby_19) { double(name: 'ruby', version: '1.9.3', checksum: 'abcd1234') }
6
+ let(:python_27) { double(name: 'python', version: '2.7', checksum: 'defg5678') }
7
+
8
+ describe '.list' do
9
+ let(:keys) { %w(ruby-1.9.3-abcd1234 python-2.7.defg5678) }
10
+ let(:softwares) { [ruby_19, python_27] }
11
+
12
+ before do
13
+ allow(S3Cache).to receive(:keys).and_return(keys)
14
+ allow(S3Cache).to receive(:softwares).and_return(softwares)
15
+ end
16
+
17
+ it 'lists the software that is cached on S3' do
18
+ expect(S3Cache.list).to include(ruby_19)
19
+ expect(S3Cache.list).to_not include(python_27)
20
+ end
21
+ end
22
+
23
+ describe '.keys' do
24
+ let(:bucket) { double(:bucket, objects: []) }
25
+
26
+ before { S3Cache.stub(:bucket).and_return(bucket) }
27
+
28
+ it 'lists the keys on the S3 bucket' do
29
+ expect(bucket).to receive(:objects).with('/').once
30
+ S3Cache.keys
31
+ end
16
32
  end
17
- let(:software_with_urls) { [source_a, source_b] }
18
33
 
19
- before do
20
- Omnibus.stub(config: double(s3_bucket: 'test', s3_access_key: 'test', s3_secret_key: 'test'))
21
- Omnibus.stub(projects: projects)
34
+ describe '.missing' do
35
+ let(:keys) { %w(ruby-1.9.3-abcd1234 python-2.7.defg5678) }
36
+ let(:softwares) { [ruby_19, python_27] }
37
+
38
+ before do
39
+ allow(S3Cache).to receive(:keys).and_return(keys)
40
+ allow(S3Cache).to receive(:softwares).and_return(softwares)
41
+ end
42
+
43
+ it 'lists the software that is cached on S3' do
44
+ expect(S3Cache.missing).to_not include(ruby_19)
45
+ expect(S3Cache.missing).to include(python_27)
46
+ end
22
47
  end
23
48
 
24
- it 'lists all software with urls' do
25
- expect(tarball_software).to eq(software_with_urls)
49
+ describe '.populate' do
50
+ it 'pending a good samaritan to come along and write tests...'
51
+ end
52
+
53
+ describe '.fetch_missing' do
54
+ let(:softwares) { [ruby_19, python_27] }
55
+
56
+ before { S3Cache.stub(:missing).and_return(softwares) }
57
+
58
+ it 'fetches the missing software' do
59
+ expect(S3Cache).to receive(:fetch).with(ruby_19)
60
+ expect(S3Cache).to receive(:fetch).with(python_27)
61
+
62
+ S3Cache.fetch_missing
63
+ end
64
+ end
65
+
66
+ describe '.key_for' do
67
+ context 'when the package does not have a name' do
68
+ it 'raises an exception' do
69
+ expect { S3Cache.key_for(double(name: nil)) }
70
+ .to raise_error(InsufficientSpecification)
71
+ end
72
+ end
73
+
74
+ context 'when the package does not have a version' do
75
+ it 'raises an exception' do
76
+ expect { S3Cache.key_for(double(name: 'ruby', version: nil)) }
77
+ .to raise_error(InsufficientSpecification)
78
+ end
79
+ end
80
+
81
+ context 'when the package does not have a checksum' do
82
+ it 'raises an exception' do
83
+ expect { S3Cache.key_for(double(name: 'ruby', version: '1.9.3', checksum: nil)) }
84
+ .to raise_error(InsufficientSpecification)
85
+ end
86
+ end
87
+
88
+ it 'returns the correct string' do
89
+ expect(S3Cache.key_for(ruby_19)).to eq('ruby-1.9.3-abcd1234')
90
+ end
26
91
  end
27
92
  end
28
93
  end
@@ -1,250 +1,477 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Omnibus::Software do
4
- let(:project) do
5
- double(Omnibus::Project, install_path: '/monkeys', overrides: {})
6
- end
3
+ module Omnibus
4
+ describe Software do
5
+ let(:software_name) { 'erchef' }
6
+ let(:software_file) { software_path(software_name) }
7
7
 
8
- let(:software_name) { 'erchef' }
9
- let(:software_file) { software_path(software_name) }
8
+ let(:project) {
9
+ project = double(Project,
10
+ name: 'chef',
11
+ install_dir: '/monkeys',
12
+ shasum: 'ABCD1234',
13
+ overrides: {}
14
+ )
10
15
 
11
- let(:software) do
12
- Omnibus::Software.load(software_file, project)
13
- end
16
+ allow(project).to receive(:is_a?)
17
+ .with(Project)
18
+ .and_return(true)
14
19
 
15
- before do
16
- allow_any_instance_of(Omnibus::Software).to receive(:render_tasks)
17
- stub_ohai(platform: 'linux')
18
- end
20
+ project
21
+ }
22
+
23
+ subject { Software.load(project, software_file) }
19
24
 
20
- describe "path helpers" do
21
25
  before do
22
- stub_const("File::PATH_SEPARATOR", separator)
23
- ENV.stub(:[]).and_call_original
24
- ENV.stub(:[]).with("PATH").and_return(path)
26
+ allow_any_instance_of(Software).to receive(:render_tasks)
25
27
  end
26
28
 
27
- context "on *NIX" do
28
- let(:separator) { ":" }
29
- let(:path) { "/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin" }
29
+ it_behaves_like 'a cleanroom getter', :project
30
+ it_behaves_like 'a cleanroom getter', :override_version
31
+ it_behaves_like 'a cleanroom setter', :name, 'libxml2'
32
+ it_behaves_like 'a cleanroom setter', :description, 'The XML magician'
33
+ it_behaves_like 'a cleanroom setter', :always_build, true
34
+ it_behaves_like 'a cleanroom setter', :dependency, 'libxslt'
35
+ it_behaves_like 'a cleanroom setter', :source, { url: 'https://source.example.com' }
36
+ it_behaves_like 'a cleanroom setter', :default_version, '1.2.3'
37
+ it_behaves_like 'a cleanroom setter', :version, '1.2.3'
38
+ it_behaves_like 'a cleanroom setter', :whitelist_file, '/opt/whatever'
39
+ it_behaves_like 'a cleanroom setter', :relative_path, '/path/to/extracted'
40
+ it_behaves_like 'a cleanroom setter', :dependencies, 'a', 'b', 'c'
41
+ it_behaves_like 'a cleanroom getter', :project_dir
42
+ it_behaves_like 'a cleanroom getter', :build_dir
43
+ it_behaves_like 'a cleanroom getter', :install_dir
44
+ it_behaves_like 'a cleanroom getter', :install_path
45
+ it_behaves_like 'a cleanroom getter', :platform
46
+ it_behaves_like 'a cleanroom getter', :architecture
47
+ it_behaves_like 'a cleanroom getter', :build
48
+ it_behaves_like 'a cleanroom getter', :with_standard_compiler_flags
49
+ it_behaves_like 'a cleanroom setter', :with_embedded_path, { 'foo' => 'bar' }
50
+ it_behaves_like 'a cleanroom setter', :prepend_path, { 'foo' => 'bar' }
51
+ it_behaves_like 'a cleanroom getter', :source_dir
52
+ it_behaves_like 'a cleanroom getter', :cache_dir
53
+ it_behaves_like 'a cleanroom getter', :config
54
+
55
+ describe "with_standard_compiler_flags helper" do
56
+ context "on ubuntu" do
57
+ before { stub_ohai(platform: 'ubuntu', version: '12.04') }
58
+
59
+ it "sets the defaults" do
60
+ expect(subject.with_standard_compiler_flags).to eq(
61
+ 'LDFLAGS' => '-Wl,-rpath,/monkeys/embedded/lib -L/monkeys/embedded/lib',
62
+ 'CFLAGS' => '-I/monkeys/embedded/include',
63
+ 'LD_RUN_PATH' => '/monkeys/embedded/lib',
64
+ 'PKG_CONFIG_PATH' => '/monkeys/embedded/lib/pkgconfig'
65
+ )
66
+ end
67
+ it 'ovesrride LDFLAGS' do
68
+ expect(subject.with_standard_compiler_flags('LDFLAGS' => 'foo')).to eq(
69
+ 'LDFLAGS' => '-Wl,-rpath,/monkeys/embedded/lib -L/monkeys/embedded/lib',
70
+ 'CFLAGS' => '-I/monkeys/embedded/include',
71
+ 'LD_RUN_PATH' => '/monkeys/embedded/lib',
72
+ 'PKG_CONFIG_PATH' => '/monkeys/embedded/lib/pkgconfig'
73
+ )
74
+ end
75
+ it 'ovesrride CFLAGS' do
76
+ expect(subject.with_standard_compiler_flags('CFLAGS'=>'foo')).to eq(
77
+ 'LDFLAGS' => '-Wl,-rpath,/monkeys/embedded/lib -L/monkeys/embedded/lib',
78
+ 'CFLAGS' => '-I/monkeys/embedded/include',
79
+ 'LD_RUN_PATH' => '/monkeys/embedded/lib',
80
+ 'PKG_CONFIG_PATH' => '/monkeys/embedded/lib/pkgconfig'
81
+ )
82
+ end
83
+ it 'presserve anything else' do
84
+ expect(subject.with_standard_compiler_flags('numberwang'=>4)).to eq(
85
+ 'numberwang' => 4,
86
+ 'LDFLAGS' => '-Wl,-rpath,/monkeys/embedded/lib -L/monkeys/embedded/lib',
87
+ 'CFLAGS' => '-I/monkeys/embedded/include',
88
+ 'LD_RUN_PATH' => '/monkeys/embedded/lib',
89
+ 'PKG_CONFIG_PATH' => '/monkeys/embedded/lib/pkgconfig'
90
+ )
91
+ end
92
+ end
93
+
94
+ context 'on solaris2' do
95
+ before do
96
+ stub_ohai(platform: 'solaris2', version: '5.11') do |data|
97
+ # For some reason, this isn't set in Fauxhai
98
+ data['platform'] = 'solaris2'
99
+ end
100
+ end
101
+
102
+ it 'sets the defaults' do
103
+ expect(subject.with_standard_compiler_flags).to eq(
104
+ 'LDFLAGS' => '-R/monkeys/embedded/lib -L/monkeys/embedded/lib -static-libgcc',
105
+ 'CFLAGS' => '-I/monkeys/embedded/include',
106
+ 'LD_RUN_PATH' => '/monkeys/embedded/lib',
107
+ 'LD_OPTIONS' => '-R/monkeys/embedded/lib',
108
+ 'PKG_CONFIG_PATH' => '/monkeys/embedded/lib/pkgconfig'
109
+ )
110
+ end
111
+ end
112
+
113
+ context 'on mac_os_x' do
114
+ before { stub_ohai(platform: 'mac_os_x', version: '10.9.2') }
30
115
 
31
- it "prepends a path to PATH" do
32
- expect(software.prepend_path("/foo/bar")).to eq("/foo/bar:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin")
116
+ it 'sets the defaults' do
117
+ expect(subject.with_standard_compiler_flags).to eq(
118
+ 'LDFLAGS' => '-L/monkeys/embedded/lib',
119
+ 'CFLAGS' => '-I/monkeys/embedded/include',
120
+ 'LD_RUN_PATH' => '/monkeys/embedded/lib',
121
+ 'PKG_CONFIG_PATH' => '/monkeys/embedded/lib/pkgconfig'
122
+ )
123
+ end
33
124
  end
34
125
 
35
- it "prepends the embedded bin to PATH" do
36
- expect(software.path_with_embedded).to eq("/monkeys/bin:/monkeys/embedded/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin")
126
+ context 'on aix' do
127
+ before do
128
+ # There's no AIX in Fauxhai :(
129
+ stub_ohai(platform: 'solaris2', version: '5.11') do |data|
130
+ data['platform'] = 'aix'
131
+ end
132
+ end
133
+
134
+ it 'sets the defaults' do
135
+ expect(subject.with_standard_compiler_flags).to eq(
136
+ 'CC' => 'xlc -q64',
137
+ 'CXX' => 'xlC -q64',
138
+ 'CFLAGS' => '-q64 -I/monkeys/embedded/include -O',
139
+ 'LDFLAGS' => '-q64 -L/monkeys/embedded/lib -Wl,-blibpath:/monkeys/embedded/lib:/usr/lib:/lib',
140
+ 'LD' => 'ld -b64',
141
+ 'OBJECT_MODE' => '64',
142
+ 'ARFLAGS' => '-X64 cru',
143
+ 'LD_RUN_PATH' => '/monkeys/embedded/lib',
144
+ 'PKG_CONFIG_PATH' => '/monkeys/embedded/lib/pkgconfig'
145
+ )
146
+ end
37
147
  end
38
148
 
39
- it "prepends multiple paths to PATH" do
40
- expect(software.prepend_path("/foo/bar", "/foo/baz"))
41
- .to eq("/foo/bar:/foo/baz:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin")
149
+ context 'on aix with gcc' do
150
+ before do
151
+ # There's no AIX in Fauxhai :(
152
+ stub_ohai(platform: 'solaris2', version: '5.11') do |data|
153
+ data['platform'] = 'aix'
154
+ end
155
+ end
156
+
157
+ it 'sets the defaults' do
158
+ expect(subject.with_standard_compiler_flags(nil, aix: { use_gcc: true })).to eq(
159
+ 'CC' => 'gcc -maix64',
160
+ 'CXX' => 'g++ -maix64',
161
+ 'CFLAGS' => '-maix64 -O -I/monkeys/embedded/include',
162
+ 'LDFLAGS' => '-L/monkeys/embedded/lib -Wl,-blibpath:/monkeys/embedded/lib:/usr/lib:/lib',
163
+ 'LD' => 'ld -b64',
164
+ 'OBJECT_MODE' => '64',
165
+ 'ARFLAGS' => '-X64 cru',
166
+ 'LD_RUN_PATH' => '/monkeys/embedded/lib',
167
+ 'PKG_CONFIG_PATH' => '/monkeys/embedded/lib/pkgconfig'
168
+ )
169
+ end
42
170
  end
43
171
  end
44
172
 
45
- context "on Windows" do
173
+ describe 'path helpers' do
46
174
  before do
47
- project.stub(:install_path).and_return("c:/monkeys")
175
+ stub_const('File::PATH_SEPARATOR', separator)
176
+ stub_env('PATH', path)
48
177
  end
49
178
 
50
- let(:separator) { ";" }
51
- let(:path) { "c:/Ruby193/bin;c:/Windows/system32;c:/Windows;c:/Windows/System32/Wbem" }
179
+ context 'on *NIX' do
180
+ let(:separator) { ':' }
181
+ let(:path) { '/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin' }
52
182
 
53
- it "prepends a path to PATH" do
54
- expect(software.prepend_path("c:/foo/bar")).to eq("c:/foo/bar;c:/Ruby193/bin;c:/Windows/system32;c:/Windows;c:/Windows/System32/Wbem")
55
- end
183
+ it 'prepends a path to PATH' do
184
+ expect(subject.prepend_path('/foo/bar')).to eq(
185
+ '/foo/bar:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin'
186
+ )
187
+ end
56
188
 
57
- it "prepends the embedded bin to PATH" do
58
- expect(software.path_with_embedded).to eq("c:/monkeys/bin;c:/monkeys/embedded/bin;c:/Ruby193/bin;c:/Windows/system32;c:/Windows;c:/Windows/System32/Wbem")
59
- end
189
+ it 'prepends the embedded bin to PATH' do
190
+ expect(subject.with_embedded_path).to eq(
191
+ 'PATH' => '/monkeys/bin:/monkeys/embedded/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin'
192
+ )
193
+ end
60
194
 
61
- it "prepends multiple paths to PATH" do
62
- expect(software.prepend_path("c:/foo/bar", "c:/foo/baz"))
63
- .to eq("c:/foo/bar;c:/foo/baz;c:/Ruby193/bin;c:/Windows/system32;c:/Windows;c:/Windows/System32/Wbem")
195
+ it 'with_embedded_path merges with a hash argument' do
196
+ expect(subject.with_embedded_path('numberwang' => 4)).to eq(
197
+ 'numberwang' => 4,
198
+ 'PATH' => '/monkeys/bin:/monkeys/embedded/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin'
199
+ )
200
+ end
201
+
202
+ it 'prepends multiple paths to PATH' do
203
+ expect(subject.prepend_path('/foo/bar', '/foo/baz')).to eq(
204
+ '/foo/bar:/foo/baz:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin'
205
+ )
206
+ end
64
207
  end
65
- end
66
- end
67
208
 
68
- describe '#<=>' do
69
- it 'compares projects by name' do
70
- list = [
71
- Omnibus::Software.load(software_path('zlib'), project),
72
- Omnibus::Software.load(software_path('erchef'), project),
73
- ]
74
- expect(list.sort.map(&:name)).to eq(%w(erchef zlib))
75
- end
76
- end
209
+ context 'on Windows' do
210
+ before do
211
+ stub_ohai(platform: 'windows', version: '2012')
212
+ allow(project).to receive(:install_dir).and_return('c:/monkeys')
213
+ stub_env('Path', windows_path)
214
+ end
77
215
 
78
- describe '#whitelist_file' do
79
- it 'appends to the whitelist_files array' do
80
- expect(software.whitelist_files.size).to eq(0)
81
- software.whitelist_file(/foo\/bar/)
82
- expect(software.whitelist_files.size).to eq(1)
83
- end
216
+ let(:separator) { ';' }
217
+ let(:path) { 'c:/Ruby193/bin;c:/Windows/system32;c:/Windows;c:/Windows/System32/Wbem' }
218
+ let(:windows_path) { 'c:/Ruby999/bin;c:/Windows/system32;c:/Windows;c:/Windows/System32/Wbem' }
84
219
 
85
- it 'converts Strings to Regexp instances' do
86
- software.whitelist_file 'foo/bar'
87
- expect(software.whitelist_files.size).to eq(1)
88
- expect(software.whitelist_files.first).to be_kind_of(Regexp)
89
- end
90
- end
220
+ it "prepends a path to PATH" do
221
+ expect(subject.prepend_path('c:/foo/bar')).to eq(
222
+ 'c:/foo/bar;c:/Ruby999/bin;c:/Windows/system32;c:/Windows;c:/Windows/System32/Wbem'
223
+ )
224
+ end
91
225
 
92
- describe '#override_version' do
93
- it 'returns the override version' do
94
- software.stub(:overrides).and_return(version: '1.2.3')
95
- expect(software.override_version).to eq('1.2.3')
96
- end
226
+ it 'prepends the embedded bin to PATH' do
227
+ expect(subject.with_embedded_path).to eq(
228
+ 'Path' => 'c:/monkeys/bin;c:/monkeys/embedded/bin;c:/Ruby999/bin;c:/Windows/system32;c:/Windows;c:/Windows/System32/Wbem'
229
+ )
230
+ end
97
231
 
98
- it 'outputs a deprecation message' do
99
- output = capture_logging { software.override_version }
100
- expect(output).to include('DEPRECATED')
101
- end
102
- end
232
+ it 'with_embedded_path merges with a hash argument' do
233
+ expect(subject.with_embedded_path('numberwang' => 4)).to eq(
234
+ 'numberwang' => 4,
235
+ 'Path' => 'c:/monkeys/bin;c:/monkeys/embedded/bin;c:/Ruby999/bin;c:/Windows/system32;c:/Windows;c:/Windows/System32/Wbem'
236
+ )
237
+ end
103
238
 
104
- describe '#given_version' do
105
- it 'returns the version' do
106
- software.stub(:default_version).and_return('4.5.6')
107
- expect(software.given_version).to eq('4.5.6')
239
+ it 'prepends multiple paths to PATH' do
240
+ expect(subject.prepend_path('c:/foo/bar', 'c:/foo/baz')).to eq(
241
+ 'c:/foo/bar;c:/foo/baz;c:/Ruby999/bin;c:/Windows/system32;c:/Windows;c:/Windows/System32/Wbem'
242
+ )
243
+ end
244
+ end
108
245
  end
109
246
 
110
- it 'outputs a deprecation message' do
111
- output = capture_logging { software.given_version }
112
- expect(output).to include('DEPRECATED')
113
- end
114
- end
247
+ describe '#<=>' do
248
+ let(:zlib) { Software.new(project).tap { |s| s.name('zlib') } }
249
+ let(:erchef) { Software.new(project).tap { |s| s.name('erchef') } }
250
+ let(:bacon) { Software.new(project).tap { |s| s.name('bacon') } }
115
251
 
116
- describe '#version' do
117
- it 'sets the given version' do
118
- software.version('1.2.3')
119
- expect(software.given_version).to eq('1.2.3')
120
- end
252
+ it 'compares projects by name' do
253
+ list = [zlib, erchef, bacon]
121
254
 
122
- it 'outputs a deprecation message' do
123
- output = capture_logging { software.version('1.2.3') }
124
- expect(output).to include('DEPRECATED')
255
+ expect(list.sort.map(&:name)).to eq(%w(bacon erchef zlib))
256
+ end
125
257
  end
126
- end
127
-
128
- context 'testing repo-level version overrides' do
129
- let(:software_name) { 'zlib' }
130
- let(:default_version) { '1.2.6' }
131
- let(:expected_version) { '1.2.6' }
132
- let(:expected_override_version) { nil }
133
- let(:expected_md5) { '618e944d7c7cd6521551e30b32322f4a' }
134
- let(:expected_url) { 'http://downloads.sourceforge.net/project/libpng/zlib/1.2.6/zlib-1.2.6.tar.gz' }
135
258
 
136
- shared_examples_for 'a software definition' do
137
- it 'should have the same name' do
138
- expect(software.name).to eq(software_name)
259
+ describe '#whitelist_file' do
260
+ it 'appends to the whitelist_files array' do
261
+ expect(subject.whitelist_files.size).to eq(0)
262
+ subject.whitelist_file(/foo\/bar/)
263
+ expect(subject.whitelist_files.size).to eq(1)
139
264
  end
140
265
 
141
- it 'should have the same version' do
142
- expect(software.version).to eq(expected_version)
266
+ it 'converts Strings to Regexp instances' do
267
+ subject.whitelist_file 'foo/bar'
268
+ expect(subject.whitelist_files.size).to eq(1)
269
+ expect(subject.whitelist_files.first).to be_kind_of(Regexp)
143
270
  end
271
+ end
144
272
 
145
- it 'should have the right default_version' do
146
- expect(software.default_version).to eq(default_version)
273
+ describe '#override_version' do
274
+ it 'returns the override version' do
275
+ subject.stub(:overrides).and_return(version: '1.2.3')
276
+ expect(subject.override_version).to eq('1.2.3')
147
277
  end
148
278
 
149
- it 'should have nil for an override_version' do
150
- expect(software.override_version).to eq(expected_override_version)
279
+ it 'outputs a deprecation message' do
280
+ output = capture_logging { subject.override_version }
281
+ expect(output).to include('DEPRECATED')
151
282
  end
283
+ end
152
284
 
153
- it 'should have the right source md5' do
154
- expect(software.source[:md5]).to eq(expected_md5)
285
+ describe '#given_version' do
286
+ it 'returns the version' do
287
+ subject.stub(:default_version).and_return('4.5.6')
288
+ expect(subject.given_version).to eq('4.5.6')
155
289
  end
156
290
 
157
- it 'should have the right source url' do
158
- expect(software.source[:url]).to eq(expected_url)
291
+ it 'outputs a deprecation message' do
292
+ output = capture_logging { subject.given_version }
293
+ expect(output).to include('DEPRECATED')
159
294
  end
295
+ end
160
296
 
161
- it 'should have the right checksum' do
162
- expect(software.checksum).to eq(expected_md5)
297
+ describe '#version' do
298
+ it 'sets the given version' do
299
+ subject.version('1.2.3')
300
+ expect(subject.given_version).to eq('1.2.3')
163
301
  end
164
302
 
165
- it 'should have the right source_uri' do
166
- expect(software.source_uri).to eq(URI.parse(expected_url))
303
+ it 'outputs a deprecation message' do
304
+ output = capture_logging { subject.version('1.2.3') }
305
+ expect(output).to include('DEPRECATED')
167
306
  end
168
307
  end
169
308
 
170
- context 'without overrides' do
171
- it_behaves_like 'a software definition'
172
- end
309
+ context 'testing repo-level version overrides' do
310
+ let(:software_name) { 'zlib' }
311
+ let(:default_version) { '1.2.6' }
312
+ let(:expected_version) { '1.2.6' }
313
+ let(:expected_override_version) { nil }
314
+ let(:expected_md5) { '618e944d7c7cd6521551e30b32322f4a' }
315
+ let(:expected_url) { 'http://downloads.sourceforge.net/project/libpng/zlib/1.2.6/zlib-1.2.6.tar.gz' }
316
+
317
+ shared_examples_for 'a software definition' do
318
+ it 'should have the same name' do
319
+ expect(subject.name).to eq(software_name)
320
+ end
173
321
 
174
- context 'with overrides for different software' do
175
- let(:overrides) { { 'chaos_monkey' => '1.2.8' } }
176
- let(:software) { Omnibus::Software.load(software_file, project, overrides) }
322
+ it 'should have the same version' do
323
+ expect(subject.version).to eq(expected_version)
324
+ end
177
325
 
178
- it_behaves_like 'a software definition'
179
- end
326
+ it 'should have the right default_version' do
327
+ expect(subject.default_version).to eq(default_version)
328
+ end
180
329
 
181
- context 'with overrides for this software' do
182
- let(:expected_version) { '1.2.8' }
183
- let(:expected_override_version) { '1.2.8' }
184
- let(:overrides) { { software_name => expected_override_version } }
185
- let(:software) { Omnibus::Software.load(software_file, project, overrides) }
186
- let(:expected_md5) { '44d667c142d7cda120332623eab69f40' }
187
- let(:expected_url) { 'http://downloads.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz' }
330
+ it 'should have nil for an override_version' do
331
+ expect(subject.override_version).to eq(expected_override_version)
332
+ end
188
333
 
189
- it_behaves_like 'a software definition'
190
- end
334
+ it 'should have the right source md5' do
335
+ expect(subject.source[:md5]).to eq(expected_md5)
336
+ end
337
+
338
+ it 'should have the right source url' do
339
+ expect(subject.source[:url]).to eq(expected_url)
340
+ end
341
+
342
+ it 'should have the right checksum' do
343
+ expect(subject.checksum).to eq(expected_md5)
344
+ end
191
345
 
192
- context 'with an overide in the project' do
193
- let(:project) do
194
- double(Omnibus::Project, install_path: 'monkeys', overrides: { zlib: { version: '1.2.8' } })
346
+ it 'should have the right source_uri' do
347
+ expect(subject.source_uri).to eq(URI.parse(expected_url))
348
+ end
195
349
  end
196
- let(:expected_version) { '1.2.8' }
197
- let(:expected_override_version) { '1.2.8' }
198
- let(:expected_md5) { '44d667c142d7cda120332623eab69f40' }
199
- let(:expected_url) { 'http://downloads.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz' }
200
350
 
201
- it_behaves_like 'a software definition'
351
+ context 'without overrides' do
352
+ it_behaves_like 'a software definition'
353
+ end
354
+
355
+ context 'with overrides for different software' do
356
+ let(:overrides) { { 'chaos_monkey' => '1.2.8' } }
357
+ subject { Software.load(project, software_file, overrides) }
358
+
359
+ it_behaves_like 'a software definition'
360
+ end
361
+
362
+ context 'with overrides for this software' do
363
+ let(:expected_version) { '1.2.8' }
364
+ let(:expected_override_version) { '1.2.8' }
365
+ let(:overrides) { { software_name => expected_override_version } }
366
+ let(:expected_md5) { '44d667c142d7cda120332623eab69f40' }
367
+ let(:expected_url) { 'http://downloads.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz' }
368
+
369
+ subject { Software.load(project, software_file, overrides) }
370
+
371
+ it_behaves_like 'a software definition'
372
+ end
202
373
 
203
- context 'with the source overridden' do
204
- let(:expected_md5) { '1234567890' }
205
- let(:expected_url) { 'http://foo.bar/zlib-1.2.8.tar.gz' }
206
- let(:project) do
207
- double(Omnibus::Project, install_path: 'monkeys', overrides: { zlib: { version: '1.2.8', source: { url: expected_url, md5: expected_md5 } } })
374
+ context 'with an overide in the project' do
375
+ let(:expected_version) { '1.2.8' }
376
+ let(:expected_override_version) { '1.2.8' }
377
+ let(:expected_md5) { '44d667c142d7cda120332623eab69f40' }
378
+ let(:expected_url) { 'http://downloads.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz' }
379
+
380
+ before do
381
+ allow(project).to receive(:overrides)
382
+ .and_return(zlib: { version: '1.2.8' })
208
383
  end
209
384
 
210
385
  it_behaves_like 'a software definition'
386
+
387
+ context 'with the source overridden' do
388
+ let(:expected_md5) { '1234567890' }
389
+ let(:expected_url) { 'http://foo.bar/zlib-1.2.8.tar.gz' }
390
+
391
+ before do
392
+ allow(project).to receive(:overrides)
393
+ .and_return(zlib: { version: '1.2.8', source: { url: expected_url, md5: expected_md5 } })
394
+ end
395
+
396
+ it_behaves_like 'a software definition'
397
+ end
211
398
  end
212
399
  end
213
- end
214
400
 
215
- context 'while getting version_for_cache' do
216
- let(:fetcher) { nil }
217
- let(:software_name) { 'zlib' }
218
- let(:default_version) { '1.2.6' }
401
+ context 'while getting version_for_cache' do
402
+ let(:fetcher) { nil }
403
+ let(:software_name) { 'zlib' }
404
+ let(:default_version) { '1.2.6' }
219
405
 
220
- def get_version_for_cache(expected_version)
221
- software.stub(:fetcher).and_return(fetcher)
222
- expect(software.version_for_cache).to eq(expected_version)
223
- end
406
+ def get_version_for_cache(expected_version)
407
+ subject.instance_variable_set(:@fetcher, fetcher)
408
+ expect(subject.version_for_cache).to eq(expected_version)
409
+ end
224
410
 
225
- context 'without a fetcher' do
226
- it 'should return the default version' do
227
- get_version_for_cache('1.2.6')
411
+ context 'without a fetcher' do
412
+ it 'should return the default version' do
413
+ get_version_for_cache('1.2.6')
414
+ end
228
415
  end
229
- end
230
416
 
231
- context 'with a NetFetcher' do
232
- let(:fetcher) { Omnibus::NetFetcher.new(software) }
417
+ context 'with a NetFetcher' do
418
+ let(:fetcher) { NetFetcher.new(subject) }
233
419
 
234
- it 'should return the default version' do
235
- get_version_for_cache('1.2.6')
420
+ it 'should return the default version' do
421
+ get_version_for_cache('1.2.6')
422
+ end
423
+ end
424
+
425
+ context 'with a GitFetcher' do
426
+ let(:fetcher) do
427
+ a = GitFetcher.new(subject)
428
+ a.stub(:target_revision).and_return('4b19a96d57bff9bbf4764d7323b92a0944009b9e')
429
+ a
430
+ end
431
+
432
+ it 'should return the git sha' do
433
+ get_version_for_cache('4b19a96d57bff9bbf4764d7323b92a0944009b9e')
434
+ end
236
435
  end
237
436
  end
238
437
 
239
- context 'with a GitFetcher' do
240
- let(:fetcher) do
241
- a = Omnibus::GitFetcher.new(software)
242
- a.stub(:target_revision).and_return('4b19a96d57bff9bbf4764d7323b92a0944009b9e')
243
- a
438
+ describe '#shasum' do
439
+ context 'when a filepath is given' do
440
+ let(:path) { '/software.rb' }
441
+ let(:file) { double(File) }
442
+
443
+ subject do
444
+ software = described_class.new(project, {}, path)
445
+ software.name('software')
446
+ software.version('1.0.0')
447
+ software
448
+ end
449
+
450
+ before do
451
+ allow(File).to receive(:exist?)
452
+ .with(path)
453
+ .and_return(true)
454
+ allow(File).to receive(:open)
455
+ .with(path)
456
+ .and_return(file)
457
+ end
458
+
459
+ it 'returns the correct shasum' do
460
+ expect(subject.shasum).to eq('f128eaa53ccff2e31d224a0a4a0a80d764298750d20bff22c24402eb046b82c1')
461
+ end
244
462
  end
245
463
 
246
- it 'should return the git sha' do
247
- get_version_for_cache('4b19a96d57bff9bbf4764d7323b92a0944009b9e')
464
+ context 'when a filepath is not given' do
465
+ subject do
466
+ software = described_class.new(project, {})
467
+ software.name('software')
468
+ software.version('1.0.0')
469
+ software
470
+ end
471
+
472
+ it 'returns the correct shasum' do
473
+ expect(subject.shasum).to eq('8a3e36a40f75c868de0cda82a8a9df2c86beaf42528d09eabb0b78a398db8678')
474
+ end
248
475
  end
249
476
  end
250
477
  end