omnibus 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -1
  3. data/.travis.yml +11 -3
  4. data/CHANGELOG.md +39 -1
  5. data/Gemfile +0 -4
  6. data/README.md +10 -8
  7. data/Rakefile +18 -7
  8. data/bin/omnibus +3 -3
  9. data/docs/Building on Windows.md +98 -0
  10. data/features/commands/_deprecated.feature +46 -0
  11. data/features/commands/build.feature +9 -0
  12. data/features/commands/clean.feature +21 -0
  13. data/features/commands/list.feature +16 -0
  14. data/features/commands/new.feature +8 -0
  15. data/features/commands/version.feature +12 -0
  16. data/features/step_definitions/generator_steps.rb +28 -0
  17. data/features/support/env.rb +13 -0
  18. data/lib/omnibus.rb +319 -240
  19. data/lib/omnibus/artifact.rb +16 -0
  20. data/lib/omnibus/build_version.rb +39 -20
  21. data/lib/omnibus/build_version_dsl.rb +136 -0
  22. data/lib/omnibus/builder.rb +28 -23
  23. data/lib/omnibus/cleaner.rb +72 -0
  24. data/lib/omnibus/cli.rb +115 -11
  25. data/lib/omnibus/cli/base.rb +82 -81
  26. data/lib/omnibus/cli/cache.rb +80 -32
  27. data/lib/omnibus/cli/deprecated.rb +79 -0
  28. data/lib/omnibus/cli/release.rb +17 -21
  29. data/lib/omnibus/config.rb +38 -13
  30. data/lib/omnibus/exceptions.rb +70 -18
  31. data/lib/omnibus/fetcher.rb +18 -11
  32. data/lib/omnibus/fetchers/git_fetcher.rb +48 -53
  33. data/lib/omnibus/fetchers/net_fetcher.rb +29 -27
  34. data/lib/omnibus/fetchers/path_fetcher.rb +9 -12
  35. data/lib/omnibus/fetchers/s3_cache_fetcher.rb +5 -8
  36. data/lib/omnibus/generator.rb +131 -0
  37. data/lib/omnibus/{templates → generator_files}/.kitchen.local.yml.erb +0 -0
  38. data/lib/omnibus/{templates → generator_files}/.kitchen.yml.erb +0 -0
  39. data/lib/omnibus/{templates → generator_files}/Berksfile.erb +0 -0
  40. data/lib/omnibus/{templates → generator_files}/Gemfile.erb +2 -2
  41. data/lib/omnibus/{templates → generator_files}/README.md.erb +6 -7
  42. data/lib/omnibus/{templates → generator_files}/Vagrantfile.erb +0 -0
  43. data/lib/omnibus/{templates → generator_files}/gitignore.erb +0 -0
  44. data/lib/omnibus/{templates → generator_files}/mac_dmg/background.png +0 -0
  45. data/lib/omnibus/{templates → generator_files}/mac_dmg/icon.png +0 -0
  46. data/lib/omnibus/{templates → generator_files}/mac_pkg/background.png +0 -0
  47. data/lib/omnibus/{templates → generator_files}/mac_pkg/license.html.erb +0 -0
  48. data/lib/omnibus/{templates → generator_files}/mac_pkg/welcome.html.erb +0 -0
  49. data/lib/omnibus/{templates → generator_files}/omnibus.rb.example.erb +0 -0
  50. data/lib/omnibus/{templates → generator_files}/package_scripts/makeselfinst.erb +0 -0
  51. data/lib/omnibus/{templates → generator_files}/package_scripts/postinst.erb +0 -0
  52. data/lib/omnibus/{templates → generator_files}/package_scripts/postrm.erb +0 -0
  53. data/lib/omnibus/{templates → generator_files}/package_scripts/preinst.erb +0 -0
  54. data/lib/omnibus/{templates → generator_files}/package_scripts/prerm.erb +0 -0
  55. data/lib/omnibus/{templates → generator_files}/project.rb.erb +0 -1
  56. data/lib/omnibus/{templates → generator_files}/software/c-example.rb.erb +0 -0
  57. data/lib/omnibus/{templates → generator_files}/software/erlang-example.rb.erb +0 -0
  58. data/lib/omnibus/{templates → generator_files}/software/ruby-example.rb.erb +0 -0
  59. data/lib/omnibus/generator_files/windows_msi/assets/LICENSE.rtf +8 -0
  60. data/lib/omnibus/generator_files/windows_msi/assets/banner_background.bmp +0 -0
  61. data/lib/omnibus/generator_files/windows_msi/assets/dialog_background.bmp +0 -0
  62. data/lib/omnibus/generator_files/windows_msi/assets/project.ico +0 -0
  63. data/lib/omnibus/generator_files/windows_msi/assets/project_16x16.ico +0 -0
  64. data/lib/omnibus/generator_files/windows_msi/assets/project_32x32.ico +0 -0
  65. data/lib/omnibus/generator_files/windows_msi/localization-en-us.wxl.erb +20 -0
  66. data/lib/omnibus/generator_files/windows_msi/parameters.wxi.erb +9 -0
  67. data/lib/omnibus/generator_files/windows_msi/source.wxs.erb +74 -0
  68. data/lib/omnibus/health_check.rb +80 -40
  69. data/lib/omnibus/install_path_cache.rb +11 -12
  70. data/lib/omnibus/library.rb +30 -3
  71. data/lib/omnibus/logger.rb +47 -0
  72. data/lib/omnibus/logging.rb +60 -0
  73. data/lib/omnibus/null_builder.rb +23 -0
  74. data/lib/omnibus/ohai.rb +70 -0
  75. data/lib/omnibus/overrides.rb +69 -48
  76. data/lib/omnibus/package_release.rb +7 -14
  77. data/lib/omnibus/packagers/base.rb +66 -13
  78. data/lib/omnibus/packagers/mac_dmg.rb +23 -3
  79. data/lib/omnibus/packagers/mac_pkg.rb +20 -10
  80. data/lib/omnibus/packagers/windows_msi.rb +109 -0
  81. data/lib/omnibus/project.rb +136 -79
  82. data/lib/omnibus/reports.rb +1 -2
  83. data/lib/omnibus/{s3_cacher.rb → s3_cache.rb} +15 -37
  84. data/lib/omnibus/software.rb +77 -27
  85. data/lib/omnibus/software_s3_urls.rb +50 -0
  86. data/lib/omnibus/sugar.rb +1 -3
  87. data/lib/omnibus/util.rb +45 -18
  88. data/lib/omnibus/version.rb +2 -3
  89. data/omnibus.gemspec +5 -3
  90. data/spec/data/complicated/config/patches/bzip2/makefile_take_env_vars.patch +15 -0
  91. data/spec/data/complicated/config/patches/couchdb/patch_for_couchjs_stack.patch +19 -0
  92. data/spec/data/complicated/config/patches/gd/gd-2.0.33-configure-libpng.patch +100 -0
  93. data/spec/data/complicated/config/patches/keepalived/keepalived-1.2.9_opscode_centos_5.patch +15 -0
  94. data/spec/data/complicated/config/patches/libedit/freebsd-vi-fix.patch +24 -0
  95. data/spec/data/complicated/config/patches/libiconv/libiconv-1.14_srclib_stdio.in.h-remove-gets-declarations.patch +29 -0
  96. data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-makefile-dest-fix.patch +35 -0
  97. data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-malloc-fix.patch +13 -0
  98. data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-shared_lib_plus_plus-1.patch +1035 -0
  99. data/spec/data/complicated/config/patches/logrotate/logrotate_basedir_override.patch +12 -0
  100. data/spec/data/complicated/config/patches/ncurses/ncurses-5.9-solaris-xopen_source_extended-detection.patch +11 -0
  101. data/spec/data/complicated/config/patches/ncurses/ncurses-clang.patch +42 -0
  102. data/spec/data/complicated/config/patches/ncurses/patch-aa +23 -0
  103. data/spec/data/complicated/config/patches/ncurses/patch-ab +44 -0
  104. data/spec/data/complicated/config/patches/ncurses/patch-ac +40 -0
  105. data/spec/data/complicated/config/patches/ncurses/patch-ad +12 -0
  106. data/spec/data/complicated/config/patches/ncurses/patch-aix-configure +23 -0
  107. data/spec/data/complicated/config/patches/ncurses/patch-cxx_cursesf.h +22 -0
  108. data/spec/data/complicated/config/patches/ncurses/patch-cxx_cursesm.h +22 -0
  109. data/spec/data/complicated/config/patches/nrpe/fix_for_runit.patch +64 -0
  110. data/spec/data/complicated/config/patches/openssl/openssl-1.0.1f-do-not-build-docs.patch +101 -0
  111. data/spec/data/complicated/config/patches/postgresql/postgresql-9.1.2-configure-ncurses-fix.patch +12 -0
  112. data/spec/data/complicated/config/patches/ruby/patch-configure +103 -0
  113. data/spec/data/complicated/config/patches/ruby/ruby-aix-configure.patch +10 -0
  114. data/spec/data/complicated/config/patches/ruby/ruby-openssl-1.0.1c.patch +42 -0
  115. data/spec/data/complicated/config/patches/ruby/ruby_aix_1_9_3_448_ssl_EAGAIN.patch +57 -0
  116. data/spec/data/complicated/config/patches/ruby/rvm-cflags.patch +27 -0
  117. data/spec/data/complicated/config/projects/angrychef.rb +32 -0
  118. data/spec/data/complicated/config/projects/chef-windows.rb +32 -0
  119. data/spec/data/complicated/config/projects/chef.rb +32 -0
  120. data/spec/data/complicated/config/projects/chefdk-windows.rb +41 -0
  121. data/spec/data/complicated/config/projects/chefdk.rb +44 -0
  122. data/spec/data/complicated/config/software/appbundler.rb +25 -0
  123. data/spec/data/complicated/config/software/autoconf.rb +35 -0
  124. data/spec/data/complicated/config/software/automake.rb +39 -0
  125. data/spec/data/complicated/config/software/berkshelf.rb +44 -0
  126. data/{lib/omnibus/fetchers.rb → spec/data/complicated/config/software/bundler.rb} +8 -5
  127. data/spec/data/complicated/config/software/bzip2.rb +46 -0
  128. data/spec/data/complicated/config/software/cacerts.rb +44 -0
  129. data/spec/data/complicated/config/software/chef-client-msi.rb +88 -0
  130. data/spec/data/complicated/config/software/chef-gem.rb +26 -0
  131. data/spec/data/complicated/config/software/chef-vault.rb +43 -0
  132. data/spec/data/complicated/config/software/chef-windows.rb +158 -0
  133. data/spec/data/complicated/config/software/chef.rb +170 -0
  134. data/spec/data/complicated/config/software/chefdk.rb +103 -0
  135. data/spec/data/complicated/config/software/couchdb.rb +53 -0
  136. data/spec/data/complicated/config/software/curl.rb +48 -0
  137. data/spec/data/complicated/config/software/erlang.rb +65 -0
  138. data/spec/data/complicated/config/software/expat.rb +21 -0
  139. data/spec/data/complicated/config/software/fcgi.rb +56 -0
  140. data/spec/data/complicated/config/software/fcgiwrap.rb +41 -0
  141. data/spec/data/complicated/config/software/gd.rb +56 -0
  142. data/spec/data/complicated/config/software/gdbm.rb +40 -0
  143. data/spec/data/complicated/config/software/gecode.rb +48 -0
  144. data/spec/data/complicated/config/software/git.rb +40 -0
  145. data/spec/data/complicated/config/software/help2man.rb +30 -0
  146. data/spec/data/complicated/config/software/icu.rb +40 -0
  147. data/spec/data/complicated/config/software/jre.rb +48 -0
  148. data/spec/data/complicated/config/software/keepalived.rb +43 -0
  149. data/spec/data/complicated/config/software/libarchive.rb +50 -0
  150. data/spec/data/complicated/config/software/libedit.rb +69 -0
  151. data/spec/data/complicated/config/software/libffi.rb +71 -0
  152. data/spec/data/complicated/config/software/libgcc.rb +39 -0
  153. data/spec/data/complicated/config/software/libiconv.rb +66 -0
  154. data/spec/data/complicated/config/software/libjpeg.rb +39 -0
  155. data/spec/data/complicated/config/software/libpng.rb +38 -0
  156. data/spec/data/complicated/config/software/libtool.rb +52 -0
  157. data/spec/data/complicated/config/software/libwrap.rb +50 -0
  158. data/spec/data/complicated/config/software/libxml2.rb +51 -0
  159. data/spec/data/complicated/config/software/libxslt.rb +52 -0
  160. data/spec/data/complicated/config/software/libyaml-windows.rb +43 -0
  161. data/spec/data/complicated/config/software/libyaml.rb +62 -0
  162. data/spec/data/complicated/config/software/logrotate.rb +41 -0
  163. data/spec/data/complicated/config/software/makedepend.rb +73 -0
  164. data/spec/data/complicated/config/software/mysql2.rb +42 -0
  165. data/spec/data/complicated/config/software/nagios-plugins.rb +53 -0
  166. data/spec/data/complicated/config/software/nagios.rb +66 -0
  167. data/spec/data/complicated/config/software/ncurses.rb +149 -0
  168. data/spec/data/complicated/config/software/nginx.rb +40 -0
  169. data/spec/data/complicated/config/software/nodejs.rb +44 -0
  170. data/spec/data/complicated/config/software/nokogiri.rb +55 -0
  171. data/spec/data/complicated/config/software/nrpe.rb +61 -0
  172. data/spec/data/complicated/config/software/ohai.rb +64 -0
  173. data/spec/data/complicated/config/software/omnibus-ctl.rb +34 -0
  174. data/spec/data/complicated/config/software/openresty.rb +67 -0
  175. data/spec/data/complicated/config/software/openssl.rb +158 -0
  176. data/spec/data/complicated/config/software/pcre.rb +42 -0
  177. data/spec/data/complicated/config/software/perl-extutils-embed.rb +15 -0
  178. data/spec/data/complicated/config/software/perl-extutils-makemaker.rb +15 -0
  179. data/spec/data/complicated/config/software/perl.rb +48 -0
  180. data/spec/data/complicated/config/software/perl_pg_driver.rb +12 -0
  181. data/spec/data/complicated/config/software/php.rb +41 -0
  182. data/spec/data/complicated/config/software/pip.rb +30 -0
  183. data/spec/data/complicated/config/software/pkg-config.rb +66 -0
  184. data/spec/data/complicated/config/software/popt.rb +47 -0
  185. data/spec/data/complicated/config/software/postgresql.rb +51 -0
  186. data/spec/data/complicated/config/software/preparation.rb +30 -0
  187. data/spec/data/complicated/config/software/pygments.rb +25 -0
  188. data/spec/data/complicated/config/software/python.rb +49 -0
  189. data/spec/data/complicated/config/software/rabbitmq.rb +36 -0
  190. data/spec/data/complicated/config/software/rebar.rb +36 -0
  191. data/spec/data/complicated/config/software/redis.rb +33 -0
  192. data/spec/data/complicated/config/software/rsync.rb +48 -0
  193. data/spec/data/complicated/config/software/ruby-windows-devkit.rb +30 -0
  194. data/spec/data/complicated/config/software/ruby-windows.rb +30 -0
  195. data/spec/data/complicated/config/software/ruby.rb +162 -0
  196. data/spec/data/complicated/config/software/rubygems-customization.rb +57 -0
  197. data/spec/data/complicated/config/software/rubygems.rb +37 -0
  198. data/spec/data/complicated/config/software/runit.rb +118 -0
  199. data/spec/data/complicated/config/software/server-jre.rb +46 -0
  200. data/spec/data/complicated/config/software/setuptools.rb +30 -0
  201. data/spec/data/complicated/config/software/spawn-fcgi.rb +40 -0
  202. data/spec/data/complicated/config/software/sphinx.rb +26 -0
  203. data/spec/data/complicated/config/software/spidermonkey.rb +60 -0
  204. data/spec/data/complicated/config/software/sqitch.rb +24 -0
  205. data/spec/data/complicated/config/software/test-kitchen.rb +39 -0
  206. data/spec/data/complicated/config/software/unicorn.rb +27 -0
  207. data/spec/data/complicated/config/software/util-macros.rb +46 -0
  208. data/spec/data/complicated/config/software/version-manifest.rb +32 -0
  209. data/spec/data/complicated/config/software/xproto.rb +46 -0
  210. data/spec/data/complicated/config/software/yajl.rb +30 -0
  211. data/spec/data/complicated/config/software/zlib.rb +67 -0
  212. data/spec/data/projects/chefdk.rb +4 -4
  213. data/spec/data/projects/sample.rb +3 -0
  214. data/spec/data/software/erchef.rb +1 -1
  215. data/spec/fixtures/sample/files/windows_msi/Resources/assets/LICENSE.rtf +8 -0
  216. data/spec/fixtures/sample/files/windows_msi/Resources/assets/banner_background.bmp +0 -0
  217. data/spec/fixtures/sample/files/windows_msi/Resources/assets/dialog_background.bmp +0 -0
  218. data/spec/fixtures/sample/files/windows_msi/Resources/assets/project.ico +0 -0
  219. data/spec/fixtures/sample/files/windows_msi/Resources/assets/project_16x16.ico +0 -0
  220. data/spec/fixtures/sample/files/windows_msi/Resources/assets/project_32x32.ico +0 -0
  221. data/spec/fixtures/sample/files/windows_msi/Resources/localization-en-us.wxl +20 -0
  222. data/spec/fixtures/sample/files/windows_msi/Resources/parameters.wxi.erb +9 -0
  223. data/spec/fixtures/sample/files/windows_msi/Resources/source.wxs +74 -0
  224. data/spec/functional/packagers/mac_spec.rb +3 -20
  225. data/spec/functional/packagers/windows_spec.rb +69 -0
  226. data/spec/spec_helper.rb +79 -1
  227. data/spec/unit/artifact_spec.rb +0 -18
  228. data/spec/unit/build_version_dsl_spec.rb +136 -0
  229. data/spec/unit/build_version_spec.rb +185 -198
  230. data/spec/unit/config_spec.rb +18 -1
  231. data/spec/unit/fetchers/git_fetcher_spec.rb +55 -80
  232. data/spec/unit/fetchers/net_fetcher_spec.rb +11 -21
  233. data/spec/unit/install_path_cache_spec.rb +164 -136
  234. data/spec/unit/library_spec.rb +125 -5
  235. data/spec/unit/omnibus_spec.rb +25 -9
  236. data/spec/unit/overrides_spec.rb +2 -14
  237. data/spec/unit/package_release_spec.rb +0 -18
  238. data/spec/unit/packagers/base_spec.rb +84 -21
  239. data/spec/unit/packagers/mac_pkg_spec.rb +34 -24
  240. data/spec/unit/project_spec.rb +100 -102
  241. data/spec/unit/s3_cacher_spec.rb +0 -18
  242. data/spec/unit/software_spec.rb +152 -6
  243. data/spec/{sugar_spec.rb → unit/sugar_spec.rb} +0 -3
  244. metadata +365 -38
  245. data/lib/omnibus/cli/application.rb +0 -147
  246. data/lib/omnibus/cli/build.rb +0 -64
@@ -6,7 +6,10 @@ module Omnibus
6
6
  expect(described_class).to be_a(Mixlib::Config)
7
7
  end
8
8
 
9
- before { described_class.reset }
9
+ before do
10
+ described_class.reset
11
+ stub_ohai(platform: 'linux')
12
+ end
10
13
 
11
14
  shared_examples 'a configurable' do |id, default|
12
15
  it "responds to .#{id}" do
@@ -40,5 +43,19 @@ module Omnibus
40
43
  include_examples 'a configurable', :solaris_compiler, nil
41
44
  include_examples 'a configurable', :append_timestamp, true
42
45
  include_examples 'a configurable', :build_retries, 3
46
+
47
+ context 'on Windows' do
48
+ before do
49
+ stub_ohai(platform: 'windows')
50
+ stub_const('File::ALT_SEPARATOR', '\\')
51
+ end
52
+
53
+ include_examples 'a configurable', :cache_dir, 'C:\\omnibus-ruby\\cache'
54
+ include_examples 'a configurable', :install_path_cache_dir, 'C:\\omnibus-ruby\\cache\\install_path'
55
+ include_examples 'a configurable', :source_dir, 'C:\\omnibus-ruby\\src'
56
+ include_examples 'a configurable', :build_dir, 'C:\\omnibus-ruby\\build'
57
+ include_examples 'a configurable', :package_dir, 'C:\\omnibus-ruby\\pkg'
58
+ include_examples 'a configurable', :package_tmp, 'C:\\omnibus-ruby\\pkg-tmp'
59
+ end
43
60
  end
44
61
  end
@@ -1,101 +1,76 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Omnibus::GitFetcher do
4
- let(:shell_out) do
5
- shell_out = double('Mixlib::ShellOut')
6
- stub_const('Mixlib::ShellOut', shell_out)
7
- shell_out
8
- end
9
- let(:software) do
10
- double('software').tap do |s|
11
- s.stub name: 'project',
12
- source: { git: 'git@example.com:test/project.git' },
13
- version: '0.0.1',
14
- project_dir: '/tmp/project'
3
+ module Omnibus
4
+ describe GitFetcher do
5
+ let(:software) do
6
+ double(Software,
7
+ name: 'project',
8
+ source: { git: 'git@example.com:test/project.git' },
9
+ version: '0.0.1',
10
+ project_dir: '/tmp/project',
11
+ )
15
12
  end
16
- end
17
-
18
- def expect_git_clone_and_ls_remote
19
- expect_git_clone
20
- expect_git_ls_remote
21
- end
22
13
 
23
- def expect_git_clone
24
- double('git_clone').tap do |g|
25
- expect(shell_out).to receive(:new)
26
- .with('git clone git@example.com:test/project.git /tmp/project', live_stream: STDOUT)
27
- .ordered
28
- .and_return(g)
29
- expect(g).to receive(:run_command).ordered
30
- expect(g).to receive(:error!).ordered
31
- end
32
- end
33
-
34
- def expect_git_ls_remote
35
- double('git_ls_remote').tap do |g|
36
- expect(shell_out).to receive(:new)
37
- .with('git ls-remote origin 0.0.1*', live_stream: STDOUT, cwd: '/tmp/project')
38
- .ordered
39
- .and_return(g)
40
- expect(g).to receive(:run_command).ordered
41
- expect(g).to receive(:error!).ordered
42
- g.stub(stdout: git_ls_remote_out)
43
- end
44
- end
45
-
46
- describe '#fetch' do
47
- context 'when the project is not cloned yet' do
48
- before do
49
- File.stub(:exist?).with('/tmp/project/.git').and_return(false)
50
- end
14
+ subject { described_class.new(software) }
51
15
 
52
- context 'when the source repository is accessible' do
53
- subject do
54
- Omnibus::GitFetcher.new software
16
+ describe '#fetch' do
17
+ context 'when the project is cloned' do
18
+ before do
19
+ subject.stub(:existing_git_clone?).and_return(true)
20
+ subject.stub(:fetch_updates)
55
21
  end
56
22
 
57
- context 'when the ref exists' do
58
- let(:git_ls_remote_out) do
59
- 'a2ed66c01f42514bcab77fd628149eccb4ecee28 refs/tags/0.0.1'
23
+ context 'when the rev matches' do
24
+ before { subject.stub(:current_rev_matches_target_rev?).and_return(true) }
25
+
26
+ it 'does not fetch updates' do
27
+ expect(subject).to_not receive(:fetch_updates)
28
+ subject.fetch
60
29
  end
30
+ end
61
31
 
62
- it 'should clone the Git repository and then check out the commit' do
63
- 1.times { expect_git_clone_and_ls_remote }
64
- double('git_checkout').tap do |g|
65
- expect(shell_out).to receive(:new)
66
- .with('git checkout a2ed66c01f42514bcab77fd628149eccb4ecee28', live_stream: STDOUT, cwd: '/tmp/project')
67
- .ordered
68
- .and_return(g)
69
- expect(g).to receive(:run_command).ordered
70
- expect(g).to receive(:error!).ordered
71
- end
32
+ context 'when the rev does not match' do
33
+ before { subject.stub(:current_rev_matches_target_rev?).and_return(false) }
72
34
 
73
- expect { subject.fetch }.to_not raise_error
35
+ it 'fetches the updates' do
36
+ expect(subject).to receive(:fetch_updates).once
37
+ subject.fetch
74
38
  end
75
39
  end
40
+ end
41
+
42
+ context 'when the project is not cloned' do
43
+ before do
44
+ subject.stub(:existing_git_clone?).and_return(false)
45
+ subject.stub(:clone)
46
+ subject.stub(:checkout)
47
+ end
76
48
 
77
- context 'when the ref does not exist' do
78
- let(:git_ls_remote_out) { '' }
79
- let(:error_reporter) { double('ErrorReporter', explain: nil) }
49
+ it 'clones the project' do
50
+ expect(subject).to receive(:clone).once
51
+ subject.fetch
52
+ end
80
53
 
81
- before { Omnibus::Fetcher::ErrorReporter.stub(:new).and_return(error_reporter) }
54
+ it 'checkouts the ref' do
55
+ expect(subject).to receive(:checkout).once
56
+ subject.fetch
57
+ end
58
+ end
82
59
 
83
- it 'should clone the Git repository and then fail while retrying 3 times' do
84
- expect(error_reporter).to receive(:explain)
85
- .with(%(Failed to fetch git repository 'git@example.com:test/project.git'))
60
+ context 'when something fails' do
61
+ let(:error_reporter) { double(Fetcher::ErrorReporter, explain: nil) }
86
62
 
87
- 4.times do
88
- expect_git_clone
89
- end
63
+ before do
64
+ subject.stub(:existing_git_clone?).and_return(false)
65
+ subject.stub(:clone).and_raise(RuntimeError)
90
66
 
91
- expect_git_ls_remote
67
+ Fetcher::ErrorReporter.stub(:new).and_return(error_reporter)
68
+ end
92
69
 
93
- expect(subject).to receive(:log).with(/git ls\-remote failed/).at_least(1).times
94
- expect(subject).to receive(:log).with(/git clone\/fetch failed/).at_least(1).times
95
- # Prevent sleeping to run the spec fast
96
- subject.stub(:sleep)
97
- expect { subject.fetch }.to raise_error(Omnibus::UnresolvableGitReference)
98
- end
70
+ it 'retries 4 times' do
71
+ subject.stub(:sleep)
72
+ expect(subject).to receive(:clone).exactly(4).times
73
+ expect { subject.fetch }.to raise_error(RuntimeError)
99
74
  end
100
75
  end
101
76
  end
@@ -49,27 +49,17 @@ describe Omnibus::NetFetcher do
49
49
  source_dir: '/tmp/out',
50
50
  project_dir: '/tmp/project'
51
51
  @net_fetcher = Omnibus::NetFetcher.new(software_mock)
52
- env_vars = %w(HTTP_PROXY HTTP_PROXY_USER HTTP_PROXY_PASS http_proxy http_proxy_user http_proxy_pass)
53
- @orig_env = env_vars.reduce({}) do |h, var|
54
- h[var] = ENV.delete(var)
55
- h
56
- end
57
- end
58
-
59
- after(:each) do
60
- # restore ENV hash
61
- @orig_env.each { |var, val| ENV[var] = val }
62
52
  end
63
53
 
64
54
  describe 'get_env handles upper and lower case env vars' do
65
55
  it 'lower via upper' do
66
- ENV['lower'] = 'abc'
56
+ stub_env('lower', 'abc')
67
57
  expect(@net_fetcher.get_env('LOWER')).to eq('abc')
68
58
  expect(@net_fetcher.get_env('lower')).to eq('abc')
69
59
  end
70
60
 
71
61
  it 'upper via lower' do
72
- ENV['UPPER'] = 'abc'
62
+ stub_env('UPPER', 'abc')
73
63
  expect(@net_fetcher.get_env('upper')).to eq('abc')
74
64
  expect(@net_fetcher.get_env('UPPER')).to eq('abc')
75
65
  end
@@ -80,26 +70,26 @@ describe Omnibus::NetFetcher do
80
70
  end
81
71
 
82
72
  it 'should return a URI object when HTTP_PROXY is set' do
83
- ENV['HTTP_PROXY'] = 'http://my.proxy'
73
+ stub_env('HTTP_PROXY', 'http://my.proxy')
84
74
  expect(@net_fetcher.http_proxy).to eq(URI.parse('http://my.proxy'))
85
75
  end
86
76
 
87
77
  it 'sets user and pass from env when set' do
88
- ENV['HTTP_PROXY'] = 'my.proxy'
89
- ENV['HTTP_PROXY_USER'] = 'alex'
90
- ENV['HTTP_PROXY_PASS'] = 'sesame'
78
+ stub_env('HTTP_PROXY', 'my.proxy')
79
+ stub_env('HTTP_PROXY_USER', 'alex')
80
+ stub_env('HTTP_PROXY_PASS', 'sesame')
91
81
  expect(@net_fetcher.http_proxy).to eq(URI.parse('http://alex:sesame@my.proxy'))
92
82
  end
93
83
 
94
84
  it 'uses user and pass in URL before those in env' do
95
- ENV['HTTP_PROXY'] = 'sally:peanut@my.proxy'
96
- ENV['HTTP_PROXY_USER'] = 'alex'
97
- ENV['HTTP_PROXY_PASS'] = 'sesame'
85
+ stub_env('HTTP_PROXY', 'sally:peanut@my.proxy')
86
+ stub_env('HTTP_PROXY_USER', 'alex')
87
+ stub_env('HTTP_PROXY_PASS', 'sesame')
98
88
  expect(@net_fetcher.http_proxy).to eq(URI.parse('http://sally:peanut@my.proxy'))
99
89
  end
100
90
 
101
91
  it "proxies if host doesn't match exclude list" do
102
- ENV['NO_PROXY'] = 'google.com,www.buz.org'
92
+ stub_env('NO_PROXY', 'google.com,www.buz.org')
103
93
  a_url = URI.parse('http://should.proxy.com/123')
104
94
  expect(@net_fetcher.excluded_from_proxy?(a_url.host)).to be_false
105
95
 
@@ -108,7 +98,7 @@ describe Omnibus::NetFetcher do
108
98
  end
109
99
 
110
100
  it 'does not proxy if host matches exclude list' do
111
- ENV['NO_PROXY'] = 'google.com,www.buz.org'
101
+ stub_env('NO_PROXY', 'google.com,www.buz.org')
112
102
  a_url = URI.parse('http://google.com/hello')
113
103
  expect(@net_fetcher.excluded_from_proxy?(a_url.host)).to be_true
114
104
 
@@ -1,175 +1,203 @@
1
1
  require 'spec_helper'
2
- require 'omnibus/util'
3
- require 'omnibus/install_path_cache'
4
-
5
- describe Omnibus::InstallPathCache do
6
- let(:install_path) { '/opt/chef' }
7
-
8
- let(:project) do
9
- raw_project = <<-EOH
10
- name "demo"
11
- install_path "/opt/demo"
12
- build_version "1.0.0"
13
- maintainer 'Chef Software, Inc'
14
- homepage 'http://getchef.com'
15
- dependency 'preparation'
16
- dependency 'snoopy'
17
- dependency 'zlib'
18
- EOH
19
- project = Omnibus::Project.new(raw_project, 'demo.rb')
20
- project
21
- end
22
-
23
- let(:fake_software_config_file) do
24
- File.join(Omnibus::RSpec::SPEC_DATA, 'software', 'zlib.rb')
25
- end
26
2
 
27
- let(:zlib) do
28
- software = Omnibus::Software.new('', fake_software_config_file, project)
29
- software.name('zlib')
30
- software.default_version('1.7.2')
31
- software
32
- end
3
+ module Omnibus
4
+ describe InstallPathCache do
5
+ before do
6
+ # Stub to prevent a real Ohai run for faster specs
7
+ Ohai.stub(:platform).and_return('linux')
8
+ end
33
9
 
34
- let(:snoopy) do
35
- software = Omnibus::Software.new('', 'snoopy.rb', project)
36
- software.name('snoopy')
37
- software.default_version('1.0.0')
38
- software
39
- end
10
+ let(:install_path) { '/opt/chef' }
40
11
 
41
- let(:preparation) do
42
- software = Omnibus::Software.new('', 'preparation.rb', project)
43
- software.name('preparation')
44
- software.default_version('1.0.0')
45
- software
46
- end
12
+ let(:project) do
13
+ raw_project = <<-EOH
14
+ name "demo"
15
+ install_path "/opt/demo"
16
+ build_version "1.0.0"
17
+ maintainer 'Chef Software, Inc'
18
+ homepage 'http://getchef.com'
19
+ dependency 'preparation'
20
+ dependency 'snoopy'
21
+ dependency 'zlib'
22
+ EOH
23
+ project = Omnibus::Project.new(raw_project, 'demo.rb')
24
+ project
25
+ end
47
26
 
48
- let(:cache_path) { "/var/cache/omnibus/cache/install_path#{install_path}" }
27
+ let(:fake_software_config_file) do
28
+ File.join(Omnibus::RSpec::SPEC_DATA, 'software', 'zlib.rb')
29
+ end
49
30
 
50
- let(:ipc) do
51
- project.library.component_added(preparation)
52
- project.library.component_added(snoopy)
53
- project.library.component_added(zlib)
54
- Omnibus::InstallPathCache.new(install_path, zlib)
55
- end
31
+ let(:zlib) do
32
+ software = Omnibus::Software.new('', fake_software_config_file, project)
33
+ software.name('zlib')
34
+ software.default_version('1.7.2')
35
+ software
36
+ end
56
37
 
57
- describe '#cache_path' do
58
- it 'returns the install path appended to the install_cache path' do
59
- expect(ipc.cache_path).to eq('/var/cache/omnibus/cache/install_path/opt/chef')
38
+ let(:snoopy) do
39
+ software = Omnibus::Software.new('', 'snoopy.rb', project)
40
+ software.name('snoopy')
41
+ software.default_version('1.0.0')
42
+ software
60
43
  end
61
- end
62
44
 
63
- describe '#cache_path_exists?' do
64
- it 'checks for existence' do
65
- expect(File).to receive(:directory?).with(ipc.cache_path)
66
- ipc.cache_path_exists?
45
+ let(:preparation) do
46
+ software = Omnibus::Software.new('', 'preparation.rb', project)
47
+ software.name('preparation')
48
+ software.default_version('1.0.0')
49
+ software
67
50
  end
68
- end
69
51
 
70
- describe '#tag' do
71
- # 13b3f7f2653e40b9d5b393659210775ac5b56f7e0009f82f85b83f5132409362
72
- #
73
- # Is the sha256sum of:
74
- # cat spec/data/software/zlib.rb > t
75
- # echo -n 'preparation-1.0.0-snoopy-1.0.0' >> t
76
- # sha256sum t
77
- it 'returns a tag with the softwares name, version, and hash of deps name+version' do
78
- expect(ipc.tag).to eql('zlib-1.7.2-13b3f7f2653e40b9d5b393659210775ac5b56f7e0009f82f85b83f5132409362')
52
+ let(:cache_path) { "/var/cache/omnibus/cache/install_path#{install_path}" }
53
+
54
+ let(:ipc) do
55
+ project.library.component_added(preparation)
56
+ project.library.component_added(snoopy)
57
+ project.library.component_added(zlib)
58
+ Omnibus::InstallPathCache.new(install_path, zlib)
79
59
  end
80
60
 
81
- describe 'with no deps' do
82
- let(:ipc) do
83
- Omnibus::InstallPathCache.new(install_path, zlib)
61
+ describe '#cache_path' do
62
+ it 'returns the install path appended to the install_cache path' do
63
+ expect(ipc.cache_path).to eq('/var/cache/omnibus/cache/install_path/opt/chef')
84
64
  end
65
+ end
85
66
 
86
- it 'uses the shasum of the software config file' do
87
- # gsha256sum spec/data/software/zlib.rb
88
- # 363e6cc2475fcdd6e18b2dc10f6022d1cab498b9961e8225d8a309d18ed3c94b spec/data/software/zlib.rb
89
- expect(ipc.tag).to eql('zlib-1.7.2-363e6cc2475fcdd6e18b2dc10f6022d1cab498b9961e8225d8a309d18ed3c94b')
67
+ describe '#cache_path_exists?' do
68
+ it 'checks for existence' do
69
+ expect(File).to receive(:directory?).with(ipc.cache_path)
70
+ ipc.cache_path_exists?
90
71
  end
91
72
  end
92
- end
93
73
 
94
- describe '#create_cache_path' do
95
- it 'runs git init if the cache path does not exist' do
96
- allow(File).to receive(:directory?).with(ipc.cache_path).and_return(false)
97
- allow(File).to receive(:directory?).with(File.dirname(ipc.cache_path)).and_return(false)
98
- expect(FileUtils).to receive(:mkdir_p).with(File.dirname(ipc.cache_path))
99
- expect(ipc).to receive(:shellout!).with("git --git-dir=#{cache_path} init -q")
100
- ipc.create_cache_path
101
- end
74
+ describe '#tag' do
75
+ # 13b3f7f2653e40b9d5b393659210775ac5b56f7e0009f82f85b83f5132409362
76
+ #
77
+ # Is the sha256sum of:
78
+ # cat spec/data/software/zlib.rb > t
79
+ # echo -n 'preparation-1.0.0-snoopy-1.0.0' >> t
80
+ # sha256sum t
81
+ it 'returns a tag with the softwares name, version, and hash of deps name+version' do
82
+ expect(ipc.tag).to eql('zlib-1.7.2-13b3f7f2653e40b9d5b393659210775ac5b56f7e0009f82f85b83f5132409362')
83
+ end
102
84
 
103
- it 'does not run git init if the cache path exists' do
104
- allow(File).to receive(:directory?).with(ipc.cache_path).and_return(true)
105
- allow(File).to receive(:directory?).with(File.dirname(ipc.cache_path)).and_return(true)
106
- expect(ipc).to_not receive(:shellout!).with("git --git-dir=#{cache_path} init -q")
107
- ipc.create_cache_path
108
- end
109
- end
85
+ describe 'with no deps' do
86
+ let(:ipc) do
87
+ Omnibus::InstallPathCache.new(install_path, zlib)
88
+ end
110
89
 
111
- describe '#incremental' do
112
- before(:each) do
113
- allow(ipc).to receive(:shellout!)
114
- allow(ipc).to receive(:create_cache_path)
90
+ it 'uses the shasum of the software config file' do
91
+ # gsha256sum spec/data/software/zlib.rb
92
+ # 363e6cc2475fcdd6e18b2dc10f6022d1cab498b9961e8225d8a309d18ed3c94b spec/data/software/zlib.rb
93
+ expect(ipc.tag).to eql('zlib-1.7.2-363e6cc2475fcdd6e18b2dc10f6022d1cab498b9961e8225d8a309d18ed3c94b')
94
+ end
95
+ end
115
96
  end
116
97
 
117
- it 'creates the cache path' do
118
- expect(ipc).to receive(:create_cache_path)
119
- ipc.incremental
120
- end
98
+ describe '#create_cache_path' do
99
+ it 'runs git init if the cache path does not exist' do
100
+ allow(File).to receive(:directory?)
101
+ .with(ipc.cache_path)
102
+ .and_return(false)
103
+ allow(File).to receive(:directory?)
104
+ .with(File.dirname(ipc.cache_path))
105
+ .and_return(false)
106
+ expect(FileUtils).to receive(:mkdir_p)
107
+ .with(File.dirname(ipc.cache_path))
108
+ expect(ipc).to receive(:quiet_shellout!)
109
+ .with("git --git-dir=#{cache_path} init -q")
110
+ ipc.create_cache_path
111
+ end
121
112
 
122
- it 'adds all the changes to git' do
123
- expect(ipc).to receive(:shellout!).with("git --git-dir=#{cache_path} --work-tree=#{install_path} add -A -f")
124
- ipc.incremental
113
+ it 'does not run git init if the cache path exists' do
114
+ allow(File).to receive(:directory?)
115
+ .with(ipc.cache_path)
116
+ .and_return(true)
117
+ allow(File).to receive(:directory?)
118
+ .with(File.dirname(ipc.cache_path))
119
+ .and_return(true)
120
+ expect(ipc).to_not receive(:quiet_shellout!)
121
+ .with("git --git-dir=#{cache_path} init -q")
122
+ ipc.create_cache_path
123
+ end
125
124
  end
126
125
 
127
- it 'commits the backup for the software' do
128
- expect(ipc).to receive(:shellout!).with("git --git-dir=#{cache_path} --work-tree=#{install_path} commit -q -m 'Backup of #{ipc.tag}'")
129
- ipc.incremental
130
- end
126
+ describe '#incremental' do
127
+ before(:each) do
128
+ allow(ipc).to receive(:quiet_shellout!)
129
+ allow(ipc).to receive(:create_cache_path)
130
+ end
131
131
 
132
- it 'tags the software backup' do
133
- expect(ipc).to receive(:shellout!).with("git --git-dir=#{cache_path} --work-tree=#{install_path} tag -f '#{ipc.tag}'")
134
- ipc.incremental
135
- end
136
- end
132
+ it 'creates the cache path' do
133
+ expect(ipc).to receive(:create_cache_path)
134
+ ipc.incremental
135
+ end
137
136
 
138
- describe '#restore' do
139
- let(:git_tag_output) { "#{ipc.tag}\n" }
137
+ it 'adds all the changes to git' do
138
+ expect(ipc).to receive(:quiet_shellout!)
139
+ .with("git --git-dir=#{cache_path} --work-tree=#{install_path} add -A -f")
140
+ ipc.incremental
141
+ end
140
142
 
141
- let(:tag_cmd) do
142
- cmd_double = double(Mixlib::ShellOut)
143
- allow(cmd_double).to receive(:stdout).and_return(git_tag_output)
144
- allow(cmd_double).to receive(:error!).and_return(cmd_double)
145
- cmd_double
146
- end
143
+ it 'commits the backup for the software' do
144
+ expect(ipc).to receive(:quiet_shellout!)
145
+ .with(%Q(git --git-dir=#{cache_path} --work-tree=#{install_path} commit -q -m "Backup of #{ipc.tag}"))
146
+ ipc.incremental
147
+ end
147
148
 
148
- before(:each) do
149
- allow(ipc).to receive(:shellout).with("git --git-dir=#{cache_path} --work-tree=#{install_path} tag -l #{ipc.tag}").and_return(tag_cmd)
150
- allow(ipc).to receive(:shellout!).with("git --git-dir=#{cache_path} --work-tree=#{install_path} checkout -f '#{ipc.tag}'")
151
- allow(ipc).to receive(:create_cache_path)
149
+ it 'tags the software backup' do
150
+ expect(ipc).to receive(:quiet_shellout!)
151
+ .with(%Q(git --git-dir=#{cache_path} --work-tree=#{install_path} tag -f "#{ipc.tag}"))
152
+ ipc.incremental
153
+ end
152
154
  end
153
155
 
154
- it 'creates the cache path' do
155
- expect(ipc).to receive(:create_cache_path)
156
- ipc.restore
157
- end
156
+ describe '#restore' do
157
+ let(:git_tag_output) { "#{ipc.tag}\n" }
158
158
 
159
- it 'checks for a tag with the software and version, and if it finds it, checks it out' do
160
- expect(ipc).to receive(:shellout).with("git --git-dir=#{cache_path} --work-tree=#{install_path} tag -l #{ipc.tag}").and_return(tag_cmd)
161
- expect(ipc).to receive(:shellout!).with("git --git-dir=#{cache_path} --work-tree=#{install_path} checkout -f '#{ipc.tag}'")
162
- ipc.restore
163
- end
159
+ let(:tag_cmd) do
160
+ cmd_double = double(Mixlib::ShellOut)
161
+ allow(cmd_double).to receive(:stdout).and_return(git_tag_output)
162
+ allow(cmd_double).to receive(:error!).and_return(cmd_double)
163
+ cmd_double
164
+ end
165
+
166
+ before(:each) do
167
+ allow(ipc).to receive(:quiet_shellout)
168
+ .with(%Q(git --git-dir=#{cache_path} --work-tree=#{install_path} tag -l "#{ipc.tag}"))
169
+ .and_return(tag_cmd)
170
+ allow(ipc).to receive(:quiet_shellout!)
171
+ .with(%Q(git --git-dir=#{cache_path} --work-tree=#{install_path} checkout -f "#{ipc.tag}"))
172
+ allow(ipc).to receive(:create_cache_path)
173
+ end
164
174
 
165
- describe 'if the tag does not exist' do
166
- let(:git_tag_output) { "\n" }
175
+ it 'creates the cache path' do
176
+ expect(ipc).to receive(:create_cache_path)
177
+ ipc.restore
178
+ end
167
179
 
168
- it 'does nothing' do
169
- expect(ipc).to receive(:shellout).with("git --git-dir=#{cache_path} --work-tree=#{install_path} tag -l #{ipc.tag}").and_return(tag_cmd)
170
- expect(ipc).to_not receive(:shellout!).with("git --git-dir=#{cache_path} --work-tree=#{install_path} checkout -f '#{ipc.tag}'")
180
+ it 'checks for a tag with the software and version, and if it finds it, checks it out' do
181
+ expect(ipc).to receive(:quiet_shellout)
182
+ .with(%Q(git --git-dir=#{cache_path} --work-tree=#{install_path} tag -l "#{ipc.tag}"))
183
+ .and_return(tag_cmd)
184
+ expect(ipc).to receive(:quiet_shellout!)
185
+ .with(%Q(git --git-dir=#{cache_path} --work-tree=#{install_path} checkout -f "#{ipc.tag}"))
171
186
  ipc.restore
172
187
  end
188
+
189
+ describe 'if the tag does not exist' do
190
+ let(:git_tag_output) { "\n" }
191
+
192
+ it 'does nothing' do
193
+ expect(ipc).to receive(:quiet_shellout)
194
+ .with(%Q(git --git-dir=#{cache_path} --work-tree=#{install_path} tag -l "#{ipc.tag}"))
195
+ .and_return(tag_cmd)
196
+ expect(ipc).to_not receive(:quiet_shellout!)
197
+ .with(%Q(git --git-dir=#{cache_path} --work-tree=#{install_path} checkout -f "#{ipc.tag}"))
198
+ ipc.restore
199
+ end
200
+ end
173
201
  end
174
202
  end
175
203
  end