berkshelf 5.2.0 → 8.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +19 -47
  3. data/Rakefile +14 -4
  4. data/berkshelf.gemspec +61 -40
  5. data/bin/berks +2 -2
  6. data/lib/berkshelf/api-client.rb +1 -0
  7. data/lib/berkshelf/api_client/chef_server_connection.rb +29 -0
  8. data/lib/berkshelf/api_client/connection.rb +57 -0
  9. data/lib/berkshelf/api_client/errors.rb +10 -0
  10. data/lib/berkshelf/api_client/remote_cookbook.rb +56 -0
  11. data/lib/berkshelf/api_client/version.rb +5 -0
  12. data/lib/berkshelf/api_client.rb +24 -0
  13. data/lib/berkshelf/berksfile.rb +149 -122
  14. data/lib/berkshelf/cached_cookbook.rb +127 -24
  15. data/lib/berkshelf/chef_config_compat.rb +51 -0
  16. data/lib/berkshelf/chef_repo_universe.rb +47 -0
  17. data/lib/berkshelf/cli.rb +143 -174
  18. data/lib/berkshelf/commands/shelf.rb +20 -19
  19. data/lib/berkshelf/community_rest.rb +59 -94
  20. data/lib/berkshelf/config.rb +97 -127
  21. data/lib/berkshelf/cookbook_store.rb +7 -6
  22. data/lib/berkshelf/core_ext/file.rb +1 -1
  23. data/lib/berkshelf/core_ext/file_utils.rb +4 -4
  24. data/lib/berkshelf/core_ext.rb +1 -1
  25. data/lib/berkshelf/dependency.rb +25 -32
  26. data/lib/berkshelf/downloader.rb +66 -39
  27. data/lib/berkshelf/errors.rb +23 -17
  28. data/lib/berkshelf/file_syncer.rb +24 -47
  29. data/lib/berkshelf/formatters/human.rb +7 -5
  30. data/lib/berkshelf/formatters/json.rb +6 -6
  31. data/lib/berkshelf/installer.rb +120 -111
  32. data/lib/berkshelf/location.rb +14 -14
  33. data/lib/berkshelf/locations/base.rb +1 -1
  34. data/lib/berkshelf/locations/git.rb +16 -24
  35. data/lib/berkshelf/locations/github.rb +2 -2
  36. data/lib/berkshelf/locations/path.rb +2 -2
  37. data/lib/berkshelf/lockfile.rb +326 -328
  38. data/lib/berkshelf/logger.rb +64 -1
  39. data/lib/berkshelf/mixin/git.rb +6 -5
  40. data/lib/berkshelf/packager.rb +44 -10
  41. data/lib/berkshelf/resolver/graph.rb +1 -1
  42. data/lib/berkshelf/resolver.rb +4 -4
  43. data/lib/berkshelf/ridley_compat.rb +109 -0
  44. data/lib/berkshelf/shell.rb +2 -1
  45. data/lib/berkshelf/shell_out.rb +18 -0
  46. data/lib/berkshelf/source.rb +77 -33
  47. data/lib/berkshelf/source_uri.rb +4 -4
  48. data/lib/berkshelf/ssl_policies.rb +38 -0
  49. data/lib/berkshelf/thor.rb +1 -1
  50. data/lib/berkshelf/thor_ext/hash_with_indifferent_access.rb +1 -1
  51. data/lib/berkshelf/thor_ext.rb +1 -1
  52. data/lib/berkshelf/uploader.rb +106 -70
  53. data/lib/berkshelf/validator.rb +13 -5
  54. data/lib/berkshelf/version.rb +1 -1
  55. data/lib/berkshelf/visualizer.rb +16 -11
  56. data/lib/berkshelf.rb +106 -81
  57. data/spec/config/knife.rb +4 -4
  58. data/spec/data/trusted_certs/example.crt +22 -0
  59. data/spec/fixtures/Berksfile +3 -3
  60. data/spec/fixtures/complex-cookbook-path/cookbooks/app/metadata.rb +2 -0
  61. data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins/metadata.rb +2 -0
  62. data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins-config/metadata.rb +4 -0
  63. data/spec/fixtures/cookbook-path/jenkins-config/metadata.rb +3 -3
  64. data/spec/fixtures/cookbook-path-uploader/apt-2.3.6/metadata.rb +2 -0
  65. data/spec/fixtures/cookbook-path-uploader/build-essential-1.4.2/metadata.rb +2 -0
  66. data/spec/fixtures/cookbook-path-uploader/jenkins-2.0.3/metadata.rb +5 -0
  67. data/spec/fixtures/cookbook-path-uploader/jenkins-config-0.1.0/metadata.rb +4 -0
  68. data/spec/fixtures/cookbook-path-uploader/runit-1.5.8/metadata.rb +5 -0
  69. data/spec/fixtures/cookbook-path-uploader/yum-3.0.6/metadata.rb +2 -0
  70. data/spec/fixtures/cookbook-path-uploader/yum-epel-0.2.0/metadata.rb +3 -0
  71. data/spec/fixtures/cookbook-store/jenkins-2.0.3/metadata.rb +5 -5
  72. data/spec/fixtures/cookbook-store/jenkins-2.0.4/metadata.rb +4 -4
  73. data/spec/fixtures/cookbooks/example_cookbook/metadata.rb +3 -3
  74. data/spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb +3 -3
  75. data/spec/spec_helper.rb +56 -64
  76. data/spec/support/chef_api.rb +15 -16
  77. data/spec/support/chef_server.rb +71 -69
  78. data/spec/support/git.rb +59 -58
  79. data/spec/support/kitchen.rb +0 -14
  80. data/spec/support/matchers/file_system_matchers.rb +4 -5
  81. data/spec/support/matchers/filepath_matchers.rb +2 -2
  82. data/spec/support/path_helpers.rb +17 -17
  83. data/spec/support/shared_examples/formatter.rb +1 -1
  84. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/attributes/default.rb +0 -0
  85. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/files/default/file.h +0 -0
  86. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/metadata.rb +2 -0
  87. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/recipes/default.rb +0 -0
  88. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/templates/default/template.erb +0 -0
  89. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/attributes/default.rb +0 -0
  90. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/files/default/file.h +0 -0
  91. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/metadata.rb +2 -0
  92. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/recipes/default.rb +0 -0
  93. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/templates/default/template.erb +0 -0
  94. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/attributes/default.rb +0 -0
  95. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/files/default/file.h +0 -0
  96. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/metadata.rb +2 -0
  97. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/recipes/default.rb +0 -0
  98. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/templates/default/template.erb +0 -0
  99. data/spec/unit/berkshelf/berksfile_spec.rb +84 -105
  100. data/spec/unit/berkshelf/berkshelf/api_client/chef_server_connection_spec.rb +65 -0
  101. data/spec/unit/berkshelf/berkshelf/api_client/connection_spec.rb +157 -0
  102. data/spec/unit/berkshelf/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
  103. data/spec/unit/berkshelf/berkshelf/api_client_spec.rb +9 -0
  104. data/spec/unit/berkshelf/cached_cookbook_spec.rb +45 -47
  105. data/spec/unit/berkshelf/chef_repo_universe_spec.rb +37 -0
  106. data/spec/unit/berkshelf/cli_spec.rb +7 -8
  107. data/spec/unit/berkshelf/community_rest_spec.rb +82 -90
  108. data/spec/unit/berkshelf/config_spec.rb +51 -22
  109. data/spec/unit/berkshelf/cookbook_store_spec.rb +41 -41
  110. data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +7 -8
  111. data/spec/unit/berkshelf/core_ext/pathname_spec.rb +1 -1
  112. data/spec/unit/berkshelf/dependency_spec.rb +48 -48
  113. data/spec/unit/berkshelf/downloader_spec.rb +191 -34
  114. data/spec/unit/berkshelf/errors_spec.rb +3 -3
  115. data/spec/unit/berkshelf/file_syncer_spec.rb +87 -87
  116. data/spec/unit/berkshelf/formatters/base_spec.rb +23 -23
  117. data/spec/unit/berkshelf/formatters/human_spec.rb +2 -2
  118. data/spec/unit/berkshelf/formatters/json_spec.rb +2 -2
  119. data/spec/unit/berkshelf/formatters/null_spec.rb +3 -3
  120. data/spec/unit/berkshelf/installer_spec.rb +8 -8
  121. data/spec/unit/berkshelf/location_spec.rb +11 -11
  122. data/spec/unit/berkshelf/locations/base_spec.rb +35 -36
  123. data/spec/unit/berkshelf/locations/git_spec.rb +90 -93
  124. data/spec/unit/berkshelf/locations/path_spec.rb +40 -41
  125. data/spec/unit/berkshelf/lockfile_parser_spec.rb +71 -71
  126. data/spec/unit/berkshelf/lockfile_spec.rb +205 -211
  127. data/spec/unit/berkshelf/logger_spec.rb +3 -3
  128. data/spec/unit/berkshelf/mixin/logging_spec.rb +5 -5
  129. data/spec/unit/berkshelf/packager_spec.rb +2 -2
  130. data/spec/unit/berkshelf/resolver/graph_spec.rb +10 -8
  131. data/spec/unit/berkshelf/resolver_spec.rb +17 -17
  132. data/spec/unit/berkshelf/ridley_compat_spec.rb +16 -0
  133. data/spec/unit/berkshelf/shell_spec.rb +34 -34
  134. data/spec/unit/berkshelf/source_spec.rb +186 -20
  135. data/spec/unit/berkshelf/source_uri_spec.rb +1 -1
  136. data/spec/unit/berkshelf/ssl_policies_spec.rb +86 -0
  137. data/spec/unit/berkshelf/uploader_spec.rb +146 -64
  138. data/spec/unit/berkshelf/validator_spec.rb +23 -16
  139. data/spec/unit/berkshelf/visualizer_spec.rb +24 -15
  140. data/spec/unit/berkshelf_spec.rb +18 -18
  141. metadata +138 -289
  142. data/.gitignore +0 -29
  143. data/.travis.yml +0 -64
  144. data/CHANGELOG.legacy.md +0 -307
  145. data/CHANGELOG.md +0 -1358
  146. data/CONTRIBUTING.md +0 -64
  147. data/Gemfile.lock +0 -399
  148. data/Guardfile +0 -23
  149. data/PLUGINS.md +0 -25
  150. data/README.md +0 -70
  151. data/Thorfile +0 -61
  152. data/appveyor.yml +0 -31
  153. data/docs/berkshelf_for_newcomers.md +0 -65
  154. data/features/berksfile.feature +0 -46
  155. data/features/commands/apply.feature +0 -41
  156. data/features/commands/contingent.feature +0 -48
  157. data/features/commands/cookbook.feature +0 -35
  158. data/features/commands/info.feature +0 -99
  159. data/features/commands/init.feature +0 -27
  160. data/features/commands/install.feature +0 -636
  161. data/features/commands/list.feature +0 -78
  162. data/features/commands/outdated.feature +0 -130
  163. data/features/commands/package.feature +0 -17
  164. data/features/commands/search.feature +0 -17
  165. data/features/commands/shelf/list.feature +0 -32
  166. data/features/commands/shelf/show.feature +0 -143
  167. data/features/commands/shelf/uninstall.feature +0 -96
  168. data/features/commands/show.feature +0 -83
  169. data/features/commands/update.feature +0 -142
  170. data/features/commands/upload.feature +0 -426
  171. data/features/commands/vendor.feature +0 -111
  172. data/features/commands/verify.feature +0 -29
  173. data/features/commands/viz.feature +0 -66
  174. data/features/community_site.feature +0 -37
  175. data/features/config.feature +0 -111
  176. data/features/help.feature +0 -11
  177. data/features/json_formatter.feature +0 -161
  178. data/features/lifecycle.feature +0 -378
  179. data/features/lockfile.feature +0 -378
  180. data/features/step_definitions/berksfile_steps.rb +0 -39
  181. data/features/step_definitions/chef/config_steps.rb +0 -12
  182. data/features/step_definitions/chef_server_steps.rb +0 -60
  183. data/features/step_definitions/cli_steps.rb +0 -18
  184. data/features/step_definitions/config_steps.rb +0 -46
  185. data/features/step_definitions/environment_steps.rb +0 -7
  186. data/features/step_definitions/filesystem_steps.rb +0 -269
  187. data/features/step_definitions/gem_steps.rb +0 -13
  188. data/features/step_definitions/json_steps.rb +0 -23
  189. data/features/step_definitions/utility_steps.rb +0 -11
  190. data/features/support/aruba.rb +0 -12
  191. data/features/support/env.rb +0 -82
  192. data/generator_files/Berksfile.erb +0 -11
  193. data/generator_files/CHANGELOG.md.erb +0 -3
  194. data/generator_files/Gemfile.erb +0 -8
  195. data/generator_files/README.md.erb +0 -42
  196. data/generator_files/Thorfile.erb +0 -11
  197. data/generator_files/Vagrantfile.erb +0 -117
  198. data/generator_files/chefignore +0 -94
  199. data/generator_files/default_recipe.erb +0 -6
  200. data/generator_files/default_test.rb.erb +0 -11
  201. data/generator_files/gitignore.erb +0 -23
  202. data/generator_files/helpers.rb.erb +0 -7
  203. data/generator_files/licenses/apachev2.erb +0 -13
  204. data/generator_files/licenses/gplv2.erb +0 -15
  205. data/generator_files/licenses/gplv3.erb +0 -14
  206. data/generator_files/licenses/mit.erb +0 -20
  207. data/generator_files/licenses/reserved.erb +0 -3
  208. data/generator_files/metadata.rb.erb +0 -11
  209. data/lib/berkshelf/base_generator.rb +0 -43
  210. data/lib/berkshelf/commands/test_command.rb +0 -13
  211. data/lib/berkshelf/cookbook_generator.rb +0 -133
  212. data/lib/berkshelf/init_generator.rb +0 -195
  213. data/spec/fixtures/cookbooks/example_cookbook/.gitignore +0 -2
  214. data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +0 -26
  215. data/spec/unit/berkshelf/cookbook_generator_spec.rb +0 -110
  216. data/spec/unit/berkshelf/init_generator_spec.rb +0 -263
@@ -1,85 +1,83 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Berkshelf::Lockfile do
4
- let(:filepath) { fixtures_path.join('lockfiles/default.lock').to_s }
4
+ let(:filepath) { fixtures_path.join("lockfiles/default.lock").to_s }
5
5
  subject { Berkshelf::Lockfile.new(filepath: filepath) }
6
6
 
7
- describe '.from_berksfile' do
8
- let(:lock_path) { File.absolute_path('/path/to/Bacon') }
7
+ describe ".from_berksfile" do
8
+ let(:lock_path) { File.absolute_path("/path/to/Bacon") }
9
9
  let(:berksfile) do
10
- double('Berksfile',
11
- filepath: lock_path,
12
- )
10
+ double("Berksfile",
11
+ filepath: lock_path)
13
12
  end
14
13
 
15
14
  subject { described_class.from_berksfile(berksfile) }
16
15
 
17
- it 'uses the basename of the Berksfile' do
16
+ it "uses the basename of the Berksfile" do
18
17
  expect(subject.filepath).to eq("#{lock_path}.lock")
19
18
  end
20
19
  end
21
20
 
22
- describe '.initialize' do
21
+ describe ".initialize" do
23
22
  subject { described_class.new(filepath: filepath) }
24
23
 
25
- it 'sets the instance variables' do
24
+ it "sets the instance variables" do
26
25
  expect(subject.filepath).to eq(filepath)
27
26
  expect(subject.dependencies).to be_a(Array)
28
27
  expect(subject.graph).to be_a(Berkshelf::Lockfile::Graph)
29
28
  end
30
29
 
31
- it 'has the correct dependencies' do
32
- expect(subject).to have_dependency('apt')
33
- expect(subject).to have_dependency('jenkins')
30
+ it "has the correct dependencies" do
31
+ expect(subject).to have_dependency("apt")
32
+ expect(subject).to have_dependency("jenkins")
34
33
  end
35
34
  end
36
35
 
37
- describe '#parse' do
38
- let(:parser) { double('parser', run: true) }
36
+ describe "#parse" do
37
+ let(:parser) { double("parser", run: true) }
39
38
 
40
39
  before do
41
40
  allow(Berkshelf::Lockfile::LockfileParser).to receive(:new).and_return(parser)
42
41
  end
43
42
 
44
- it 'creates a new parser object' do
43
+ it "creates a new parser object" do
45
44
  expect(Berkshelf::Lockfile::LockfileParser).to receive(:new).with(subject)
46
45
  expect(parser).to receive(:run)
47
46
  subject.parse
48
47
  end
49
48
 
50
- it 'returns true (always)' do
49
+ it "returns true (always)" do
51
50
  expect(subject.parse).to be(true)
52
51
  end
53
52
  end
54
53
 
55
- describe '#present?' do
56
- it 'returns true when the file exists' do
54
+ describe "#present?" do
55
+ it "returns true when the file exists" do
57
56
  expect(subject.present?).to be(true)
58
57
  end
59
58
 
60
- it 'returns false when the file does not exist' do
61
- allow(File).to receive(:exists?).and_return(false)
59
+ it "returns false when the file does not exist" do
60
+ allow(File).to receive(:exist?).and_return(false)
62
61
  expect(subject.present?).to be(false)
63
62
  end
64
63
 
65
- it 'returns false when the file is empty' do
66
- allow(File).to receive(:read).and_return('')
64
+ it "returns false when the file is empty" do
65
+ allow(File).to receive(:read).and_return("")
67
66
  expect(subject.present?).to be(false)
68
67
  end
69
68
  end
70
69
 
71
- describe '#trusted?' do
72
- it 'returns true when the lockfile is trusted' do
73
- cookbook = double('apt-1.0.0', dependencies: {})
74
- apt = double('apt',
75
- name: 'apt',
76
- version_constraint: Semverse::Constraint.new('>= 0.0.0'),
77
- version: '1.0.0',
78
- location: 'api',
70
+ describe "#trusted?" do
71
+ it "returns true when the lockfile is trusted" do
72
+ cookbook = double("apt-1.0.0", dependencies: {})
73
+ apt = double("apt",
74
+ name: "apt",
75
+ version_constraint: Semverse::Constraint.new(">= 0.0.0"),
76
+ version: "1.0.0",
77
+ location: "api",
79
78
  dependencies: {},
80
- cached_cookbook: cookbook,
81
- )
82
- berksfile = double('berksfile', dependencies: [apt])
79
+ cached_cookbook: cookbook)
80
+ berksfile = double("berksfile", dependencies: [apt])
83
81
  subject.instance_variable_set(:@berksfile, berksfile)
84
82
  allow(subject).to receive(:find).with(apt).and_return(apt)
85
83
  allow(subject.graph).to receive(:find).with(apt).and_return(apt)
@@ -87,63 +85,59 @@ describe Berkshelf::Lockfile do
87
85
  expect(subject.trusted?).to be(true)
88
86
  end
89
87
 
90
- it 'returns true when the lockfile is trusted with transitive dependencies' do
91
- cookbook = double('apt-1.0.0', dependencies: { 'bacon' => '1.0.0' })
92
- apt = double('apt',
93
- name: 'apt',
94
- version_constraint: Semverse::Constraint.new('>= 0.0.0'),
95
- version: '1.0.0',
96
- location: 'api',
97
- dependencies: { 'bacon' => '1.0.0' },
98
- cached_cookbook: cookbook,
99
- )
100
- bacon = double(name: 'bacon', version: '1.0.0', dependencies: {})
101
- berksfile = double('berksfile', dependencies: [apt])
88
+ it "returns true when the lockfile is trusted with transitive dependencies" do
89
+ cookbook = double("apt-1.0.0", dependencies: { "bacon" => "1.0.0" })
90
+ apt = double("apt",
91
+ name: "apt",
92
+ version_constraint: Semverse::Constraint.new(">= 0.0.0"),
93
+ version: "1.0.0",
94
+ location: "api",
95
+ dependencies: { "bacon" => "1.0.0" },
96
+ cached_cookbook: cookbook)
97
+ bacon = double(name: "bacon", version: "1.0.0", dependencies: {})
98
+ berksfile = double("berksfile", dependencies: [apt])
102
99
  subject.instance_variable_set(:@berksfile, berksfile)
103
100
  allow(subject).to receive(:find).with(apt).and_return(apt)
104
- allow(subject.graph).to receive(:find).with('bacon').and_return(bacon)
101
+ allow(subject.graph).to receive(:find).with("bacon").and_return(bacon)
105
102
  allow(subject.graph).to receive(:find).with(apt).and_return(apt)
106
103
 
107
104
  expect(subject.trusted?).to be(true)
108
105
  end
109
106
 
110
- it 'returns true when the lockfile is trusted with cyclic transitive dependencies' do
111
- cookbook = double('apt-1.0.0', dependencies: { 'bacon' => '1.0.0' })
112
- apt = double('apt',
113
- name: 'apt',
114
- version_constraint: Semverse::Constraint.new('>= 0.0.0'),
115
- version: '1.0.0',
116
- location: 'api',
117
- dependencies: { 'bacon' => '1.0.0' },
118
- cached_cookbook: cookbook,
119
- )
120
- bacon = double('bacon',
121
- name: 'bacon',
122
- version_constraint: Semverse::Constraint.new('>= 0.0.0'),
123
- version: '1.0.0',
124
- location: 'api',
125
- dependencies: { 'apt' => '1.0.0' }
126
- )
127
- berksfile = double('berksfile', dependencies: [apt])
107
+ it "returns true when the lockfile is trusted with cyclic transitive dependencies" do
108
+ cookbook = double("apt-1.0.0", dependencies: { "bacon" => "1.0.0" })
109
+ apt = double("apt",
110
+ name: "apt",
111
+ version_constraint: Semverse::Constraint.new(">= 0.0.0"),
112
+ version: "1.0.0",
113
+ location: "api",
114
+ dependencies: { "bacon" => "1.0.0" },
115
+ cached_cookbook: cookbook)
116
+ bacon = double("bacon",
117
+ name: "bacon",
118
+ version_constraint: Semverse::Constraint.new(">= 0.0.0"),
119
+ version: "1.0.0",
120
+ location: "api",
121
+ dependencies: { "apt" => "1.0.0" })
122
+ berksfile = double("berksfile", dependencies: [apt])
128
123
  subject.instance_variable_set(:@berksfile, berksfile)
129
124
  allow(subject).to receive(:find).with(apt).and_return(apt)
130
- allow(subject.graph).to receive(:find).with('bacon').and_return(bacon)
125
+ allow(subject.graph).to receive(:find).with("bacon").and_return(bacon)
131
126
  allow(subject.graph).to receive(:find).with(apt).and_return(apt)
132
127
 
133
128
  expect(subject.trusted?).to be(true)
134
129
  end
135
130
 
136
- it 'returns false when the lockfile is not trusted because of transitive dependencies' do
137
- cookbook = double('apt-1.0.0', dependencies: { 'bacon' => '1.0.0', 'flip' => '2.0.0' })
138
- apt = double('apt',
139
- name: 'apt',
140
- version_constraint: Semverse::Constraint.new('>= 0.0.0'),
141
- version: '1.0.0',
142
- location: 'api',
143
- dependencies: { 'bacon' => '1.0.0' },
144
- cached_cookbook: cookbook,
145
- )
146
- berksfile = double('berksfile', dependencies: [apt])
131
+ it "returns false when the lockfile is not trusted because of transitive dependencies" do
132
+ cookbook = double("apt-1.0.0", dependencies: { "bacon" => "1.0.0", "flip" => "2.0.0" })
133
+ apt = double("apt",
134
+ name: "apt",
135
+ version_constraint: Semverse::Constraint.new(">= 0.0.0"),
136
+ version: "1.0.0",
137
+ location: "api",
138
+ dependencies: { "bacon" => "1.0.0" },
139
+ cached_cookbook: cookbook)
140
+ berksfile = double("berksfile", dependencies: [apt])
147
141
  subject.instance_variable_set(:@berksfile, berksfile)
148
142
  allow(subject).to receive(:find).with(apt).and_return(apt)
149
143
  allow(subject.graph).to receive(:find).with(apt).and_return(apt)
@@ -151,17 +145,17 @@ describe Berkshelf::Lockfile do
151
145
  expect(subject.trusted?).to be(false)
152
146
  end
153
147
 
154
- it 'returns false if the dependency is not in the lockfile' do
155
- apt = double('apt', name: 'apt', version_constraint: nil)
156
- berksfile = double('berksfile', dependencies: [apt])
148
+ it "returns false if the dependency is not in the lockfile" do
149
+ apt = double("apt", name: "apt", version_constraint: nil)
150
+ berksfile = double("berksfile", dependencies: [apt])
157
151
  subject.instance_variable_set(:@berksfile, berksfile)
158
152
 
159
153
  expect(subject.trusted?).to be(false)
160
154
  end
161
155
 
162
- it 'returns false if the dependency is not in the graph' do
163
- apt = double('apt', name: 'apt', version_constraint: nil)
164
- berksfile = double('berksfile', dependencies: [apt])
156
+ it "returns false if the dependency is not in the graph" do
157
+ apt = double("apt", name: "apt", version_constraint: nil)
158
+ berksfile = double("berksfile", dependencies: [apt])
165
159
  subject.instance_variable_set(:@berksfile, berksfile)
166
160
  allow(subject).to receive(:find).with(apt).and_return(true)
167
161
  allow(subject.graph).to receive(:find).with(apt).and_return(nil)
@@ -169,17 +163,16 @@ describe Berkshelf::Lockfile do
169
163
  expect(subject.trusted?).to be(false)
170
164
  end
171
165
 
172
- it 'returns false if the constraint is not satisfied' do
173
- cookbook = double('apt-1.0.0', dependencies: {})
174
- apt = double('apt',
175
- name: 'apt',
176
- version_constraint: Semverse::Constraint.new('< 1.0.0'),
177
- version: '1.0.0',
178
- location: 'api',
166
+ it "returns false if the constraint is not satisfied" do
167
+ cookbook = double("apt-1.0.0", dependencies: {})
168
+ apt = double("apt",
169
+ name: "apt",
170
+ version_constraint: Semverse::Constraint.new("< 1.0.0"),
171
+ version: "1.0.0",
172
+ location: "api",
179
173
  dependencies: {},
180
- cached_cookbook: cookbook,
181
- )
182
- berksfile = double('berksfile', dependencies: [apt])
174
+ cached_cookbook: cookbook)
175
+ berksfile = double("berksfile", dependencies: [apt])
183
176
  subject.instance_variable_set(:@berksfile, berksfile)
184
177
  allow(subject).to receive(:find).with(apt).and_return(apt)
185
178
  allow(subject.graph).to receive(:find).with(apt).and_return(apt)
@@ -187,20 +180,19 @@ describe Berkshelf::Lockfile do
187
180
  expect(subject.trusted?).to be(false)
188
181
  end
189
182
 
190
- it 'returns false if the locations are different' do
191
- cookbook = double('apt-1.0.0', dependencies: {})
192
- apt = double('apt',
193
- name: 'apt',
194
- version_constraint: Semverse::Constraint.new('< 1.0.0'),
195
- version: '1.0.0',
196
- location: 'api',
183
+ it "returns false if the locations are different" do
184
+ cookbook = double("apt-1.0.0", dependencies: {})
185
+ apt = double("apt",
186
+ name: "apt",
187
+ version_constraint: Semverse::Constraint.new("< 1.0.0"),
188
+ version: "1.0.0",
189
+ location: "api",
197
190
  dependencies: {},
198
- cached_cookbook: cookbook,
199
- )
191
+ cached_cookbook: cookbook)
200
192
  apt_master = apt.dup
201
- allow(apt_master).to receive_messages(location: 'github')
193
+ allow(apt_master).to receive_messages(location: "github")
202
194
  allow(apt_master).to receive_messages(cached_cookbook: cookbook)
203
- berksfile = double('berksfile', dependencies: [apt])
195
+ berksfile = double("berksfile", dependencies: [apt])
204
196
  subject.instance_variable_set(:@berksfile, berksfile)
205
197
  allow(subject).to receive(:find).with(apt).and_return(apt_master)
206
198
  allow(subject.graph).to receive(:find).with(apt).and_return(apt)
@@ -209,169 +201,172 @@ describe Berkshelf::Lockfile do
209
201
  end
210
202
  end
211
203
 
212
- describe '#apply' do
204
+ describe "#apply" do
213
205
  before do
214
- apt = double(name: 'apt', locked_version: '1.0.0')
215
- jenkins = double(name: 'jenkins', locked_version: '1.4.5')
216
- allow(subject.graph).to receive(:locks).and_return('apt' => apt, 'jenkins' => jenkins)
206
+ apt = double(name: "apt", locked_version: "1.0.0")
207
+ jenkins = double(name: "jenkins", locked_version: "1.4.5")
208
+ allow(subject.graph).to receive(:locks).and_return("apt" => apt, "jenkins" => jenkins)
217
209
  end
218
210
 
219
- describe 'when :envfile option is not used' do
220
- let(:connection) { double('connection') }
211
+ describe "when :envfile option is not used" do
212
+ let(:connection) { double("connection") }
221
213
 
222
214
  before do
223
215
  allow(Berkshelf).to receive(:ridley_connection).and_yield(connection)
224
216
  end
225
217
 
226
- context 'when the Chef environment does not exist' do
227
- it 'raises an exception' do
228
- allow(connection).to receive(:environment).and_return(double(find: nil))
229
- expect {
230
- subject.apply('production')
231
- }.to raise_error(Berkshelf::EnvironmentNotFound)
218
+ context "when the Chef environment does not exist" do
219
+ it "raises an exception" do
220
+ allow(connection).to receive(:get).and_raise(Berkshelf::APIClient::ServiceNotFound)
221
+ expect do
222
+ subject.apply("production")
223
+ end.to raise_error(Berkshelf::EnvironmentNotFound)
232
224
  end
233
225
  end
234
226
 
235
- it 'locks the environment cookbook versions on chef server' do
236
- environment = double('environment', :cookbook_versions= => nil, save: true)
237
- allow(connection).to receive(:environment).and_return(double(find: environment))
227
+ it "locks the environment cookbook versions on chef server" do
228
+ environment = instance_double(Chef::Environment)
229
+ env_hash = double(Hash)
230
+ expect(connection).to receive(:get).with("environments/production").and_return(env_hash)
231
+ expect(Chef::Environment).to receive(:from_hash).with(env_hash).and_return(environment)
238
232
 
239
- expect(environment).to receive(:cookbook_versions=).with(
240
- 'apt' => '= 1.0.0',
241
- 'jenkins' => '= 1.4.5',
233
+ expect(environment).to receive(:cookbook_versions).with(
234
+ {"apt" => "= 1.0.0",
235
+ "jenkins" => "= 1.4.5"}
242
236
  )
243
237
 
244
- subject.apply('production')
238
+ expect(environment).to receive(:save)
239
+ subject.apply("production")
245
240
  end
246
241
  end
247
-
248
- describe 'when :envfile option is used' do
249
- it 'locks the environment cookbook version into envfile' do
250
- locks = {
251
- 'apt' => '= 1.0.0',
252
- 'jenkins' => '= 1.4.5'
253
- }
254
-
255
- expect(subject).to receive(:update_environment_file).with('/working/path', locks)
256
-
257
- subject.apply('production', envfile: '/working/path')
242
+
243
+ describe "when :envfile option is used" do
244
+ it "locks the environment cookbook version into envfile" do
245
+ locks = {
246
+ "apt" => "= 1.0.0",
247
+ "jenkins" => "= 1.4.5",
248
+ }
249
+
250
+ expect(subject).to receive(:update_environment_file).with("/working/path", locks)
251
+
252
+ subject.apply("production", envfile: "/working/path")
258
253
  end
259
254
  end
260
255
  end
261
256
 
262
- describe '#dependencies' do
263
- it 'returns an array' do
257
+ describe "#dependencies" do
258
+ it "returns an array" do
264
259
  expect(subject.dependencies).to be_a(Array)
265
260
  end
266
261
  end
267
262
 
268
- describe '#find' do
269
- it 'returns a matching cookbook' do
270
- expect(subject.find('apt').name).to eq('apt')
263
+ describe "#find" do
264
+ it "returns a matching cookbook" do
265
+ expect(subject.find("apt").name).to eq("apt")
271
266
  end
272
267
 
273
- it 'returns nil for a missing cookbook' do
274
- expect(subject.find('foo')).to be_nil
268
+ it "returns nil for a missing cookbook" do
269
+ expect(subject.find("foo")).to be_nil
275
270
  end
276
271
  end
277
272
 
278
- describe '#has_dependency?' do
279
- it 'returns true if a matching cookbook is found' do
280
- expect(subject).to have_dependency('apt')
273
+ describe "#has_dependency?" do
274
+ it "returns true if a matching cookbook is found" do
275
+ expect(subject).to have_dependency("apt")
281
276
  end
282
277
 
283
- it 'returns false if no matching cookbook is found' do
284
- expect(subject).to_not have_dependency('foo')
278
+ it "returns false if no matching cookbook is found" do
279
+ expect(subject).to_not have_dependency("foo")
280
+ end
281
+ end
282
+
283
+ describe "#add" do
284
+ it "adds the dependency to the lockfile" do
285
+ subject.add("apache2")
286
+ expect(subject).to have_dependency("apache2")
285
287
  end
286
288
  end
287
289
 
288
- describe '#add' do
289
- it 'adds the dependency to the lockfile' do
290
- subject.add('apache2')
291
- expect(subject).to have_dependency('apache2')
290
+ describe "#update_environment_file" do
291
+ it "raises an exception when environment file does not exist" do
292
+ allow(File).to receive(:exist?).and_return(false)
293
+ expect do
294
+ subject.update_environment_file("/broken/path", nil)
295
+ end.to raise_error(Berkshelf::EnvironmentFileNotFound)
296
+ end
297
+
298
+ it "updates the environment file with cookbook versions" do
299
+ file = instance_spy("File")
300
+ locks = {
301
+ "apt" => "1.0.0",
302
+ "jenkins" => "1.4.5",
303
+ }
304
+
305
+ allow(File).to receive(:exist?).and_return(true)
306
+ allow(File).to receive(:read).and_return("{}")
307
+ allow(File).to receive(:open).and_yield(file)
308
+
309
+ subject.update_environment_file("/working/path.json", locks)
310
+
311
+ expect(file).to have_received(:puts) do |arg|
312
+ expect(JSON.parse(arg)).to eq({
313
+ "cookbook_versions" => locks,
314
+ })
315
+ end
292
316
  end
293
317
  end
294
318
 
295
- describe '#update_environment_file' do
296
- it 'raises an exception when environment file does not exist' do
297
- allow(File).to receive(:exists?).and_return(false)
298
- expect {
299
- subject.update_environment_file('/broken/path', nil)
300
- }.to raise_error(Berkshelf::EnvironmentFileNotFound)
301
- end
302
-
303
- it 'updates the environment file with cookbook versions' do
304
- file = instance_spy('File')
305
- locks = {
306
- 'apt' => '1.0.0',
307
- 'jenkins' => '1.4.5'
308
- }
309
-
310
- allow(File).to receive(:exists?).and_return(true)
311
- allow(File).to receive(:read).and_return("{}")
312
- allow(File).to receive(:open).and_yield(file)
313
-
314
- subject.update_environment_file('/working/path.json', locks)
315
-
316
- expect(file).to have_received(:puts) do |arg|
317
- expect(JSON.parse(arg)).to eq({
318
- 'cookbook_versions' => locks
319
- })
320
- end
321
- end
322
- end
323
-
324
- describe '#update' do
325
- it 'resets the dependencies' do
319
+ describe "#update" do
320
+ it "resets the dependencies" do
326
321
  subject.update([])
327
322
  expect(subject.dependencies).to be_empty
328
323
  end
329
324
 
330
- it 'appends each of the dependencies' do
331
- subject.update(['apache2'])
332
- expect(subject).to have_dependency('apache2')
325
+ it "appends each of the dependencies" do
326
+ subject.update(["apache2"])
327
+ expect(subject).to have_dependency("apache2")
333
328
  end
334
329
  end
335
330
 
336
- describe '#unlock' do
337
- it 'removes the dependency from the graph' do
338
- subject.add('apache2')
339
- subject.unlock('apache2')
340
- expect(subject).to_not have_dependency('apache2')
331
+ describe "#unlock" do
332
+ it "removes the dependency from the graph" do
333
+ subject.add("apache2")
334
+ subject.unlock("apache2")
335
+ expect(subject).to_not have_dependency("apache2")
341
336
  end
342
337
  end
343
338
 
344
- describe '#reduce!' do
345
- let(:berksfile_path) { fixtures_path.join('berksfiles/default').to_s }
339
+ describe "#reduce!" do
340
+ let(:berksfile_path) { fixtures_path.join("berksfiles/default").to_s }
346
341
  let(:berksfile) { Berkshelf::Berksfile.from_file(berksfile_path) }
347
342
 
348
- describe 'with some orphan dependencies' do
349
- let(:orphans_lock) { fixtures_path.join('lockfiles/orphans.lock').to_s }
343
+ describe "with some orphan dependencies" do
344
+ let(:orphans_lock) { fixtures_path.join("lockfiles/orphans.lock").to_s }
350
345
  subject { Berkshelf::Lockfile.new(filepath: orphans_lock, berksfile: berksfile) }
351
346
 
352
- it 'removes orphan dependencies' do
347
+ it "removes orphan dependencies" do
353
348
  graph = subject.graph.instance_variable_get(:@graph)
354
- expect(graph).to receive(:delete).with('yum-epel').and_call_original
355
- expect(graph).to receive(:delete).with('zum-foo').and_call_original
356
- expect(graph).to receive(:delete).with('yum').and_call_original
349
+ expect(graph).to receive(:delete).with("yum-epel").and_call_original
350
+ expect(graph).to receive(:delete).with("zum-foo").and_call_original
351
+ expect(graph).to receive(:delete).with("yum").and_call_original
357
352
  subject.reduce!
358
353
  end
359
354
  end
360
355
 
361
- describe 'minimizes updates' do
356
+ describe "minimizes updates" do
362
357
  subject { Berkshelf::Lockfile.new(filepath: filepath, berksfile: berksfile) }
363
358
 
364
359
  before(:each) do
365
- cs = fixtures_path.join('cookbook-store')
360
+ cs = fixtures_path.join("cookbook-store")
366
361
  allow(Berkshelf::CookbookStore.instance).to receive(:storage_path).and_return(cs)
367
362
  end
368
363
 
369
- it 'uses the cookbook version specified in the lockfile' do
364
+ it "uses the cookbook version specified in the lockfile" do
370
365
  subject.reduce!
371
- expect(subject.berksfile.dependencies[1].cached_cookbook.version).to eq('2.0.3')
366
+ expect(subject.berksfile.dependencies[1].cached_cookbook.version).to eq("2.0.3")
372
367
  end
373
368
 
374
- it 'does not remove locks unnecessarily' do
369
+ it "does not remove locks unnecessarily" do
375
370
  expect(subject).to_not receive(:unlock)
376
371
  subject.reduce!
377
372
  end
@@ -380,18 +375,17 @@ describe Berkshelf::Lockfile do
380
375
  end
381
376
 
382
377
  describe Berkshelf::Lockfile::Graph do
383
- let(:filepath) { fixtures_path.join('lockfiles/empty.lock').to_s }
378
+ let(:filepath) { fixtures_path.join("lockfiles/empty.lock").to_s }
384
379
  let(:lockfile) { Berkshelf::Lockfile.new(filepath: filepath) }
385
380
  subject { described_class.new(lockfile) }
386
381
 
387
- describe '#update' do
388
- it 'uses cookbook_name as GraphItem name' do
389
- cookbook = double('test',
390
- name: 'test-0.0.1',
391
- version: '0.0.1',
392
- cookbook_name: 'test',
393
- dependencies: {}
394
- )
382
+ describe "#update" do
383
+ it "uses cookbook_name as GraphItem name" do
384
+ cookbook = double("test",
385
+ name: "test-0.0.1",
386
+ version: "0.0.1",
387
+ cookbook_name: "test",
388
+ dependencies: {})
395
389
  subject.update([cookbook])
396
390
 
397
391
  expect(subject.locks.keys).to include(cookbook.cookbook_name)
@@ -1,9 +1,9 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Berkshelf::Logger do
4
- %w(info warn error fatal debug deprecate exception).each do |meth|
4
+ %w{info warn error fatal debug deprecate exception}.each do |meth|
5
5
  describe "##{meth}" do
6
- it 'responds' do
6
+ it "responds" do
7
7
  expect(subject).to respond_to(meth.to_sym)
8
8
  end
9
9
  end
@@ -1,18 +1,18 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Berkshelf::Mixin::Logging do
4
4
  subject do
5
5
  Class.new { include Berkshelf::Mixin::Logging }.new
6
6
  end
7
7
 
8
- describe '#logger' do
9
- it 'returns the Berkshelf::Logger' do
8
+ describe "#logger" do
9
+ it "returns the Berkshelf::Logger" do
10
10
  expect(subject.logger).to be_a(Berkshelf::Logger)
11
11
  end
12
12
  end
13
13
 
14
- describe '#log' do
15
- it 'returns the Berkshelf::Logger' do
14
+ describe "#log" do
15
+ it "returns the Berkshelf::Logger" do
16
16
  expect(subject.log).to be_a(Berkshelf::Logger)
17
17
  end
18
18
  end
@@ -1,10 +1,10 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Berkshelf::Packager do
4
4
  let(:target) { tmp_path.join("cookbooks.tar.gz").to_s }
5
5
  subject { described_class.new(target) }
6
6
 
7
- it 'has the correct out_file' do
7
+ it "has the correct out_file" do
8
8
  expect(subject.out_file).to eq(target)
9
9
  end
10
10