berkshelf 1.4.6 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +1 -5
- data/CONTRIBUTING.md +3 -1
- data/Gemfile +11 -1
- data/README.md +16 -0
- data/Thorfile +3 -1
- data/berkshelf.gemspec +26 -38
- data/features/apply_command.feature +32 -0
- data/features/configure_command.feature +31 -0
- data/features/contingent_command.feature +5 -5
- data/features/default_locations.feature +2 -2
- data/features/groups_install.feature +19 -20
- data/features/info_command.feature +13 -13
- data/features/install_command.feature +86 -83
- data/features/json_formatter.feature +60 -23
- data/features/list_command.feature +5 -11
- data/features/lockfile.feature +286 -6
- data/features/open_command.feature +8 -4
- data/features/outdated_command.feature +8 -15
- data/features/package_command.feature +39 -0
- data/features/show_command.feature +8 -9
- data/features/step_definitions/chef_server_steps.rb +20 -2
- data/features/step_definitions/cli_steps.rb +10 -2
- data/features/step_definitions/configure_cli_steps.rb +7 -0
- data/features/step_definitions/filesystem_steps.rb +19 -14
- data/features/step_definitions/json_steps.rb +22 -5
- data/features/step_definitions/utility_steps.rb +13 -1
- data/features/support/env.rb +10 -23
- data/features/update_command.feature +105 -24
- data/features/upload_command.feature +0 -14
- data/features/vendor_install.feature +3 -3
- data/generator_files/Vagrantfile.erb +11 -11
- data/lib/berkshelf.rb +6 -5
- data/lib/berkshelf/berksfile.rb +267 -99
- data/lib/berkshelf/cli.rb +70 -34
- data/lib/berkshelf/cli_commands/test_command.rb +11 -0
- data/lib/berkshelf/community_rest.rb +1 -1
- data/lib/berkshelf/config.rb +19 -2
- data/lib/berkshelf/cookbook_source.rb +41 -12
- data/lib/berkshelf/cookbook_store.rb +8 -4
- data/lib/berkshelf/errors.rb +61 -29
- data/lib/berkshelf/formatters.rb +13 -19
- data/lib/berkshelf/formatters/human_readable.rb +8 -0
- data/lib/berkshelf/formatters/json.rb +12 -1
- data/lib/berkshelf/formatters/null.rb +23 -0
- data/lib/berkshelf/init_generator.rb +22 -11
- data/lib/berkshelf/location.rb +8 -10
- data/lib/berkshelf/locations/chef_api_location.rb +4 -5
- data/lib/berkshelf/locations/git_location.rb +14 -12
- data/lib/berkshelf/locations/path_location.rb +16 -1
- data/lib/berkshelf/locations/site_location.rb +1 -3
- data/lib/berkshelf/lockfile.rb +230 -33
- data/lib/berkshelf/resolver.rb +2 -1
- data/lib/berkshelf/ui.rb +4 -8
- data/lib/berkshelf/version.rb +1 -1
- data/lib/thor/monkies/shell.rb +2 -5
- data/spec/fixtures/cassettes/Berkshelf_Resolver/{ClassMethods/_initialize → _initialize}/adds_the_dependencies_of_the_source_as_sources.yml +0 -0
- data/spec/fixtures/cookbooks/example_cookbook/.gitignore +2 -0
- data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +26 -0
- data/spec/fixtures/cookbooks/example_cookbook/Berksfile.lock +5 -0
- data/spec/fixtures/lockfiles/default.lock +11 -0
- data/spec/{config/knife.rb → knife.rb.sample} +2 -2
- data/spec/spec_helper.rb +15 -3
- data/spec/support/chef_api.rb +19 -5
- data/spec/support/chef_server.rb +4 -3
- data/spec/support/knife.rb +18 -0
- data/spec/unit/berkshelf/berksfile_spec.rb +332 -235
- data/spec/unit/berkshelf/cached_cookbook_spec.rb +40 -42
- data/spec/unit/berkshelf/chef/cookbook/chefignore_spec.rb +11 -15
- data/spec/unit/berkshelf/community_rest_spec.rb +16 -14
- data/spec/unit/berkshelf/config_spec.rb +36 -20
- data/spec/unit/berkshelf/cookbook_generator_spec.rb +6 -10
- data/spec/unit/berkshelf/cookbook_source_spec.rb +244 -183
- data/spec/unit/berkshelf/cookbook_store_spec.rb +72 -76
- data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +2 -2
- data/spec/unit/berkshelf/downloader_spec.rb +137 -157
- data/spec/unit/berkshelf/errors_spec.rb +1 -1
- data/spec/unit/berkshelf/formatters/null_spec.rb +17 -0
- data/spec/unit/berkshelf/formatters_spec.rb +83 -90
- data/spec/unit/berkshelf/git_spec.rb +219 -207
- data/spec/unit/berkshelf/init_generator_spec.rb +73 -73
- data/spec/unit/berkshelf/location_spec.rb +143 -162
- data/spec/unit/berkshelf/locations/chef_api_location_spec.rb +94 -89
- data/spec/unit/berkshelf/locations/git_location_spec.rb +75 -59
- data/spec/unit/berkshelf/locations/path_location_spec.rb +46 -30
- data/spec/unit/berkshelf/locations/site_location_spec.rb +4 -4
- data/spec/unit/berkshelf/lockfile_spec.rb +185 -1
- data/spec/unit/berkshelf/logger_spec.rb +6 -24
- data/spec/unit/berkshelf/mixin/logging_spec.rb +6 -8
- data/spec/unit/berkshelf/resolver_spec.rb +36 -38
- data/spec/unit/berkshelf/ui_spec.rb +9 -10
- data/spec/unit/berkshelf_spec.rb +41 -40
- data/spec/unit/chef/config_spec.rb +9 -11
- metadata +55 -203
- data/spec/config/berkshelf.pem +0 -27
- data/spec/config/validator.pem +0 -27
@@ -3,15 +3,14 @@ Feature: outdated command
|
|
3
3
|
I want to know what cookbooks are outdated before I run update
|
4
4
|
So that I can decide whether to update everything at once
|
5
5
|
|
6
|
-
@slow_process
|
7
6
|
Scenario: Running berks outdated with no version constraints
|
8
7
|
Given I write to "Berksfile" with:
|
9
8
|
"""
|
10
9
|
site :opscode
|
11
|
-
|
12
|
-
cookbook
|
10
|
+
|
11
|
+
cookbook 'berkshelf-cookbook-fixture'
|
13
12
|
"""
|
14
|
-
When I run `berks outdated`
|
13
|
+
When I successfully run `berks outdated`
|
15
14
|
Then the output should contain:
|
16
15
|
"""
|
17
16
|
Listing outdated cookbooks with newer versions available...
|
@@ -21,13 +20,12 @@ Feature: outdated command
|
|
21
20
|
All cookbooks up to date
|
22
21
|
"""
|
23
22
|
|
24
|
-
@slow_process
|
25
23
|
Scenario: Running berks outdated with satisfied version constraints
|
26
24
|
Given I write to "Berksfile" with:
|
27
25
|
"""
|
28
26
|
site :opscode
|
29
|
-
|
30
|
-
cookbook
|
27
|
+
|
28
|
+
cookbook 'berkshelf-cookbook-fixture', '>= 0.1'
|
31
29
|
"""
|
32
30
|
When I run `berks outdated`
|
33
31
|
Then the output should contain:
|
@@ -39,13 +37,12 @@ Feature: outdated command
|
|
39
37
|
All cookbooks up to date
|
40
38
|
"""
|
41
39
|
|
42
|
-
@slow_process
|
43
40
|
Scenario: Running berks outdated with unsatisfied version constraints
|
44
41
|
Given I write to "Berksfile" with:
|
45
42
|
"""
|
46
43
|
site :opscode
|
47
|
-
|
48
|
-
cookbook
|
44
|
+
|
45
|
+
cookbook 'berkshelf-cookbook-fixture', '~> 0.1'
|
49
46
|
"""
|
50
47
|
When I run `berks outdated`
|
51
48
|
Then the output should contain:
|
@@ -54,9 +51,5 @@ Feature: outdated command
|
|
54
51
|
"""
|
55
52
|
And the output should contain:
|
56
53
|
"""
|
57
|
-
Cookbook '
|
58
|
-
"""
|
59
|
-
And the output should contain:
|
60
|
-
"""
|
61
|
-
Cookbook 'build-essential (~> 0.7.0)' is outdated
|
54
|
+
Cookbook 'berkshelf-cookbook-fixture (~> 0.1)' is outdated
|
62
55
|
"""
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Feature: package command
|
2
|
+
As a user
|
3
|
+
I want to be able to package a cookbook
|
4
|
+
So that I can use it outside of Berkshelf
|
5
|
+
|
6
|
+
Scenario: Running the package command
|
7
|
+
Given I write to "Berksfile" with:
|
8
|
+
"""
|
9
|
+
site :opscode
|
10
|
+
cookbook 'berkshelf-cookbook-fixture', '~> 1.0.0'
|
11
|
+
"""
|
12
|
+
And I successfully run `berks install`
|
13
|
+
When I successfully run `berks package berkshelf-cookbook-fixture`
|
14
|
+
Then a file named "berkshelf-cookbook-fixture.tar.gz" should exist
|
15
|
+
And the output should contain "Cookbook 'berkshelf-cookbook-fixture' saved to "
|
16
|
+
And the exit status should be 0
|
17
|
+
|
18
|
+
Scenario: Running the package command with the --output option
|
19
|
+
Given I write to "Berksfile" with:
|
20
|
+
"""
|
21
|
+
site :opscode
|
22
|
+
cookbook 'berkshelf-cookbook-fixture', '~> 1.0.0'
|
23
|
+
"""
|
24
|
+
And I successfully run `berks install`
|
25
|
+
When I successfully run `berks package berkshelf-cookbook-fixture --output foo/bar`
|
26
|
+
Then a file named "foo/bar/berkshelf-cookbook-fixture.tar.gz" should exist
|
27
|
+
And the exit status should be 0
|
28
|
+
|
29
|
+
Scenario: Running the package command with an installed cookbook name
|
30
|
+
Given I write to "Berksfile" with:
|
31
|
+
"""
|
32
|
+
site :opscode
|
33
|
+
cookbook 'berkshelf-cookbook-fixture', '~> 1.0.0'
|
34
|
+
"""
|
35
|
+
And I successfully run `berks install`
|
36
|
+
When I run `berks package non-existent`
|
37
|
+
Then a file named "non-existent.tar.gz" should not exist
|
38
|
+
And the output should contain "Cookbook 'non-existent' is not in your Berksfile"
|
39
|
+
And the CLI should exit with the status code for error "CookbookNotFound"
|
@@ -4,24 +4,23 @@ Feature: show command
|
|
4
4
|
So that I can view the source and debug
|
5
5
|
|
6
6
|
Scenario: Running the show command with an installed cookbook name
|
7
|
-
Given
|
7
|
+
Given the cookbook store has the cookbooks:
|
8
|
+
| berkshelf-cookbook-fixture | 1.0.0 |
|
9
|
+
And I write to "Berksfile" with:
|
8
10
|
"""
|
9
11
|
site :opscode
|
10
|
-
cookbook
|
11
|
-
cookbook "chef-client", "1.2.0"
|
12
|
-
cookbook "mysql", "1.2.4"
|
12
|
+
cookbook 'berkshelf-cookbook-fixture', '1.0.0'
|
13
13
|
"""
|
14
|
-
|
15
|
-
|
16
|
-
Then the output should contain "berkshelf/tmp/berkshelf/cookbooks/build-essential-1.2.0"
|
14
|
+
When I successfully run `berks show berkshelf-cookbook-fixture`
|
15
|
+
Then the output should contain "berkshelf/tmp/berkshelf/cookbooks/berkshelf-cookbook-fixture-1.0.0"
|
17
16
|
And the exit status should be 0
|
18
17
|
|
19
18
|
Scenario: Running the show command with a not installed cookbook name
|
20
19
|
Given I write to "Berksfile" with:
|
21
20
|
"""
|
22
|
-
|
21
|
+
site :opscode
|
22
|
+
cookbook 'berkshelf-cookbook-fixture', '1.0.0'
|
23
23
|
"""
|
24
|
-
And I successfully run `berks install`
|
25
24
|
When I run `berks show build-essential`
|
26
25
|
Then the output should contain "Cookbook 'build-essential' was not installed by your Berksfile"
|
27
26
|
And the CLI should exit with the status code for error "CookbookNotFound"
|
@@ -16,12 +16,30 @@ end
|
|
16
16
|
|
17
17
|
Then /^the Chef server should have the cookbooks:$/ do |cookbooks|
|
18
18
|
cookbooks.raw.each do |name, version|
|
19
|
-
server_has_cookbook?(name, version).
|
19
|
+
expect(server_has_cookbook?(name, version)).to be_true
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
Then /^the Chef server should not have the cookbooks:$/ do |cookbooks|
|
24
24
|
cookbooks.raw.each do |name, version|
|
25
|
-
server_has_cookbook?(name, version).
|
25
|
+
expect(server_has_cookbook?(name, version)).to be_false
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
Given(/^I have an environment named "(.*?)"$/) do |environment_name|
|
30
|
+
delete_environment(environment_name)
|
31
|
+
begin
|
32
|
+
create_environment(environment_name)
|
33
|
+
rescue Ridley::Errors::HTTPConflict; end
|
34
|
+
end
|
35
|
+
|
36
|
+
Then(/^the version locks in "(.*?)" should be:$/) do |environment_name, version_locks|
|
37
|
+
environment_cookbook_versions = environment(environment_name).cookbook_versions
|
38
|
+
version_locks.hashes.each do |hash|
|
39
|
+
expect(environment_cookbook_versions[hash['cookbook']]).to eq(hash['version_lock'])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Given(/^I do not have an environment named "(.*?)"$/) do |environment_name|
|
44
|
+
delete_environment(environment_name) if environment_exists? environment_name
|
45
|
+
end
|
@@ -12,7 +12,7 @@ end
|
|
12
12
|
|
13
13
|
Then /^a file named "(.*?)" should exist in the current directory$/ do |filename|
|
14
14
|
in_current_dir do
|
15
|
-
File.exists?(filename).
|
15
|
+
expect(File.exists?(filename)).to be_true # not sure why Aruba's
|
16
16
|
# #check_file_presence
|
17
17
|
# doesn't work here. It
|
18
18
|
# looks in the wrong
|
@@ -22,7 +22,7 @@ end
|
|
22
22
|
|
23
23
|
Then /^the file "(.*?)" should contain in the current directory:$/ do |filename, string|
|
24
24
|
in_current_dir do
|
25
|
-
File.read(filename).
|
25
|
+
expect(File.read(filename)).to match(Regexp.new(string))
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -58,6 +58,14 @@ When /^I run the cookbook command to create "(.*?)"$/ do |name|
|
|
58
58
|
run_simple(unescape("berks cookbook #{name}"), false)
|
59
59
|
end
|
60
60
|
|
61
|
+
When /^I (successfully )?run the apply command on "(.*?)"$/ do |successfully, environment_name|
|
62
|
+
run_simple(unescape("berks apply #{environment_name}"), !!successfully)
|
63
|
+
end
|
64
|
+
|
65
|
+
When /^I (successfully )?run the apply command on "(.*?)" with flags:$/ do |successfully, environment_name, flags|
|
66
|
+
run_simple(unescape("berks apply #{environment_name} #{flags.raw.join(" ")}"), !!successfully)
|
67
|
+
end
|
68
|
+
|
61
69
|
When /^I run the cookbook command to create "(.*?)" with options:$/ do |name, options|
|
62
70
|
run_simple(unescape("berks cookbook #{name} #{options.raw.join(" ")}"))
|
63
71
|
end
|
@@ -6,6 +6,13 @@ end
|
|
6
6
|
|
7
7
|
Then /^a Berkshelf config file should exist and contain:$/ do |table|
|
8
8
|
config = Berkshelf::Config.from_file(Berkshelf::Config.path)
|
9
|
+
table.raw.each do |key, value|
|
10
|
+
expect(config.get_attribute(key)).to eq(value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Then /^a Berkshelf config file should exist at "(.+)" and contain:$/ do |path, table|
|
15
|
+
config = Berkshelf::Config.from_file(File.expand_path("tmp/aruba/#{path}"))
|
9
16
|
table.raw.each do |key, value|
|
10
17
|
config.get_attribute(key).should eql(value)
|
11
18
|
end
|
@@ -15,7 +15,7 @@ Given /^I do not have a Berksfile$/ do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
Given /^I do not have a Berksfile\.lock$/ do
|
18
|
-
in_current_dir { FileUtils.rm_f(Berkshelf::
|
18
|
+
in_current_dir { FileUtils.rm_f("#{Berkshelf::DEFAULT_FILENAME}.lock") }
|
19
19
|
end
|
20
20
|
|
21
21
|
Given /^I have a default Berkshelf config file$/ do
|
@@ -32,6 +32,11 @@ Given /^I do not have a Berkshelf config file$/ do
|
|
32
32
|
remove_file Berkshelf::Config.path if ::File.exists? Berkshelf::Config.path
|
33
33
|
end
|
34
34
|
|
35
|
+
Given /^I do not have a Berkshelf config file at "(.+)"$/ do |path|
|
36
|
+
remove_file(path) if File.exists?(path)
|
37
|
+
end
|
38
|
+
|
39
|
+
|
35
40
|
Given /^the cookbook "(.*?)" has the file "(.*?)" with:$/ do |cookbook_name, file_name, content|
|
36
41
|
write_file(::File.join(cookbook_name, file_name), content)
|
37
42
|
end
|
@@ -48,7 +53,7 @@ end
|
|
48
53
|
|
49
54
|
Then /^the cookbook store should have the cookbooks:$/ do |cookbooks|
|
50
55
|
cookbooks.raw.each do |name, version|
|
51
|
-
cookbook_store.
|
56
|
+
expect(cookbook_store).to have_structure {
|
52
57
|
directory "#{name}-#{version}" do
|
53
58
|
file "metadata.rb" do
|
54
59
|
contains version
|
@@ -60,7 +65,7 @@ end
|
|
60
65
|
|
61
66
|
Then /^the cookbook store should have the git cookbooks:$/ do |cookbooks|
|
62
67
|
cookbooks.raw.each do |name, version, sha1|
|
63
|
-
cookbook_store.
|
68
|
+
expect(cookbook_store).to have_structure {
|
64
69
|
directory "#{name}-#{sha1}" do
|
65
70
|
file "metadata.rb" do
|
66
71
|
contains version
|
@@ -72,19 +77,19 @@ end
|
|
72
77
|
|
73
78
|
Then /^the cookbook store should not have the cookbooks:$/ do |cookbooks|
|
74
79
|
cookbooks.raw.each do |name, version|
|
75
|
-
cookbook_store.
|
80
|
+
expect(cookbook_store).to_not have_structure {
|
76
81
|
directory "#{name}-#{version}"
|
77
82
|
}
|
78
83
|
end
|
79
84
|
end
|
80
85
|
|
81
86
|
Then /^I should have the cookbook "(.*?)"$/ do |name|
|
82
|
-
Pathname.new(current_dir).join(name).
|
87
|
+
expect(Pathname.new(current_dir).join(name)).to be_cookbook
|
83
88
|
end
|
84
89
|
|
85
90
|
Then /^I should have a new cookbook skeleton "(.*?)"$/ do |name|
|
86
91
|
cb_path = Pathname.new(current_dir).join(name)
|
87
|
-
cb_path.
|
92
|
+
expect(cb_path).to have_structure {
|
88
93
|
directory "attributes"
|
89
94
|
directory "definitions"
|
90
95
|
directory "files" do
|
@@ -119,7 +124,7 @@ Then /^I should have a new cookbook skeleton "(.*?)" with Chef-Minitest support$
|
|
119
124
|
steps %Q{ Then I should have a new cookbook skeleton "#{name}" }
|
120
125
|
|
121
126
|
cb_path = Pathname.new(current_dir).join(name)
|
122
|
-
cb_path.
|
127
|
+
expect(cb_path).to have_structure {
|
123
128
|
file "Berksfile" do
|
124
129
|
contains "cookbook \"minitest-handler\""
|
125
130
|
end
|
@@ -151,7 +156,7 @@ Then /^I should have a new cookbook skeleton "(.*?)" with Foodcritic support$/ d
|
|
151
156
|
steps %Q{ Then I should have a new cookbook skeleton "#{name}" }
|
152
157
|
|
153
158
|
cb_path = Pathname.new(current_dir).join(name)
|
154
|
-
cb_path.
|
159
|
+
expect(cb_path).to have_structure {
|
155
160
|
file "Gemfile" do
|
156
161
|
contains "gem 'thor-foodcritic'"
|
157
162
|
end
|
@@ -165,7 +170,7 @@ Then /^I should have a new cookbook skeleton "(.*?)" with SCMVersion support$/ d
|
|
165
170
|
steps %Q{ Then I should have a new cookbook skeleton "#{name}" }
|
166
171
|
|
167
172
|
cb_path = Pathname.new(current_dir).join(name)
|
168
|
-
cb_path.
|
173
|
+
expect(cb_path).to have_structure {
|
169
174
|
file "Gemfile" do
|
170
175
|
contains "gem 'thor-scmversion'"
|
171
176
|
end
|
@@ -177,7 +182,7 @@ end
|
|
177
182
|
|
178
183
|
Then /^I should have a new cookbook skeleton "(.*?)" with no Bundler support$/ do |name|
|
179
184
|
cb_path = Pathname.new(current_dir).join(name)
|
180
|
-
cb_path.
|
185
|
+
expect(cb_path).to have_structure {
|
181
186
|
directory "attributes"
|
182
187
|
directory "definitions"
|
183
188
|
directory "files" do
|
@@ -204,13 +209,13 @@ Then /^I should have a new cookbook skeleton "(.*?)" with no Bundler support$/ d
|
|
204
209
|
end
|
205
210
|
|
206
211
|
Then /^I should have a new cookbook skeleton "(.*?)" with no Git support$/ do |name|
|
207
|
-
Pathname.new(current_dir).join(name).
|
212
|
+
expect(Pathname.new(current_dir).join(name)).to have_structure {
|
208
213
|
no_file ".gitignore"
|
209
214
|
}
|
210
215
|
end
|
211
216
|
|
212
217
|
Then /^I should have a new cookbook skeleton "(.*?)" with no Vagrant support$/ do |name|
|
213
|
-
Pathname.new(current_dir).join(name).
|
218
|
+
expect(Pathname.new(current_dir).join(name)).to have_structure {
|
214
219
|
file "Gemfile" do
|
215
220
|
does_not_contain "gem 'vagrant'"
|
216
221
|
end
|
@@ -227,7 +232,7 @@ Then /^the cookbook "(.*?)" should not have the following files:$/ do |name, fil
|
|
227
232
|
end
|
228
233
|
|
229
234
|
Then /^the file "(.*?)" in the cookbook "(.*?)" should contain:$/ do |file_name, cookbook_name, content|
|
230
|
-
Pathname.new(current_dir).join(cookbook_name).
|
235
|
+
expect(Pathname.new(current_dir).join(cookbook_name)).to have_structure {
|
231
236
|
file "Berksfile" do
|
232
237
|
contains content
|
233
238
|
end
|
@@ -236,7 +241,7 @@ Then /^the file "(.*?)" in the cookbook "(.*?)" should contain:$/ do |file_name,
|
|
236
241
|
end
|
237
242
|
|
238
243
|
Then /^the resulting "(.+)" Vagrantfile should contain:$/ do |cookbook_name, content|
|
239
|
-
Pathname.new(current_dir).join(cookbook_name).
|
244
|
+
expect(Pathname.new(current_dir).join(cookbook_name)).to have_structure {
|
240
245
|
file "Vagrantfile" do
|
241
246
|
content.respond_to?(:raw) ?
|
242
247
|
content.raw.flatten.each { |string| contains string } :
|
@@ -1,10 +1,27 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
class Hash
|
2
|
+
def sort_by_key(&block)
|
3
|
+
self.keys.sort(&block).reduce({}) do |seed, key|
|
4
|
+
seed[key] = self[key]
|
5
|
+
if seed[key].is_a?(Hash)
|
6
|
+
seed[key] = seed[key].sort_by_key(&block)
|
7
|
+
elsif seed[key].is_a?(Array)
|
8
|
+
seed[key] = seed[key].map { |i| i.sort_by_key(&block) }
|
9
|
+
end
|
10
|
+
seed
|
11
|
+
end
|
12
|
+
end
|
3
13
|
end
|
4
14
|
|
5
15
|
Then /^the file "(.*?)" should contain JSON:$/ do |file, data|
|
6
|
-
target =
|
7
|
-
actual =
|
16
|
+
target = JSON.pretty_generate(JSON.parse(data).sort_by_key)
|
17
|
+
actual = JSON.pretty_generate(JSON.parse(File.read(File.join(current_dir, file))).sort_by_key)
|
8
18
|
|
9
|
-
|
19
|
+
expect(actual).to eq(target)
|
20
|
+
end
|
21
|
+
|
22
|
+
Then /^the output should contain JSON:$/ do |data|
|
23
|
+
target = JSON.pretty_generate(JSON.parse(ERB.new(data).result(binding)).sort_by_key)
|
24
|
+
actual = JSON.pretty_generate(JSON.parse(all_output).sort_by_key)
|
25
|
+
|
26
|
+
expect(actual).to eq(target)
|
10
27
|
end
|
@@ -2,6 +2,11 @@ Given /^pending\s+"([^\"]+)"$/ do |msg|
|
|
2
2
|
pending
|
3
3
|
end
|
4
4
|
|
5
|
+
Given(/^the BERKSHELF_EDITOR and VISUAL environment variables are not set$/) do
|
6
|
+
set_env "BERKSHELF_EDITOR", nil
|
7
|
+
set_env "VISUAL", nil
|
8
|
+
end
|
9
|
+
|
5
10
|
Given /^the environment variable (.+) is nil$/ do |variable|
|
6
11
|
set_env variable, nil
|
7
12
|
end
|
@@ -14,4 +19,11 @@ Then /^the output should be the same as \`(.+)\`$/ do |command|
|
|
14
19
|
run_simple(command)
|
15
20
|
output = output_from(command)
|
16
21
|
expect(all_output).to include(output)
|
17
|
-
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# The built-in regex matcher does not support multi-line matching :(
|
25
|
+
# @author Seth Vargo <sethvargo@gmail.com>
|
26
|
+
Then /^the output should match multiline:$/ do |expected|
|
27
|
+
regex = Regexp.new(expected.strip, Regexp::MULTILINE)
|
28
|
+
expect(regex).to match(all_output)
|
29
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler'
|
3
3
|
require 'spork'
|
4
|
-
require "json_spec/cucumber"
|
5
4
|
|
6
5
|
Spork.prefork do
|
7
6
|
require 'rspec'
|
@@ -12,48 +11,39 @@ Spork.prefork do
|
|
12
11
|
|
13
12
|
ENV['RUBY_ENV'] = 'test'
|
14
13
|
ENV['BERKSHELF_PATH'] = File.join(APP_ROOT, 'tmp', 'berkshelf')
|
15
|
-
ENV['BERKSHELF_CHEF_CONFIG'] = File.join(APP_ROOT, 'spec', '
|
14
|
+
ENV['BERKSHELF_CHEF_CONFIG'] = File.join(APP_ROOT, 'spec', 'knife.rb')
|
16
15
|
|
17
16
|
# Workaround for RSA Fingerprint prompt in Travis CI
|
18
17
|
git_ssh_path = '/tmp/git_ssh.sh'
|
19
18
|
unless File.exist? git_ssh_path
|
20
19
|
git_ssh = File.new(git_ssh_path, 'w+')
|
21
|
-
git_ssh.puts
|
20
|
+
git_ssh.puts 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $1 $2'
|
22
21
|
git_ssh.chmod 0775
|
23
22
|
git_ssh.flush
|
24
23
|
git_ssh.close
|
25
24
|
end
|
26
25
|
|
27
|
-
ENV[
|
26
|
+
ENV['GIT_SSH'] = git_ssh_path
|
28
27
|
|
29
|
-
Dir[File.join(APP_ROOT,
|
28
|
+
Dir[File.join(APP_ROOT, 'spec/support/**/*.rb')].each {|f| require f}
|
30
29
|
|
31
30
|
World(Berkshelf::TestGenerators)
|
32
31
|
|
33
32
|
Before do
|
34
33
|
set_env 'RUBY_ENV', 'test'
|
35
34
|
clean_cookbook_store
|
36
|
-
generate_berks_config(File.join(ENV[
|
35
|
+
generate_berks_config(File.join(ENV['BERKSHELF_PATH'], 'config.json'))
|
37
36
|
@aruba_io_wait_seconds = 5
|
38
|
-
@aruba_timeout_seconds =
|
37
|
+
@aruba_timeout_seconds = 16
|
39
38
|
end
|
40
39
|
|
41
40
|
Before('@slow_process') do
|
42
41
|
@aruba_timeout_seconds = 60
|
43
|
-
@aruba_io_wait_seconds =
|
44
|
-
end
|
45
|
-
|
46
|
-
# Chef Zero
|
47
|
-
require 'chef_zero/server'
|
48
|
-
@server = ChefZero::Server.new(port: 4000, generate_real_keys: false)
|
49
|
-
@server.start_background
|
50
|
-
|
51
|
-
at_exit do
|
52
|
-
@server.stop if @server && @server.running?
|
42
|
+
@aruba_io_wait_seconds = 30
|
53
43
|
end
|
54
44
|
|
55
45
|
def cookbook_store
|
56
|
-
Pathname.new(File.join(ENV[
|
46
|
+
Pathname.new(File.join(ENV['BERKSHELF_PATH'], 'cookbooks'))
|
57
47
|
end
|
58
48
|
|
59
49
|
def clean_cookbook_store
|
@@ -72,13 +62,10 @@ Spork.prefork do
|
|
72
62
|
def fixtures_path
|
73
63
|
app_root_path.join('spec/fixtures')
|
74
64
|
end
|
75
|
-
|
76
|
-
# Set the output json_spec will parse for testing JSON responses
|
77
|
-
def last_json
|
78
|
-
all_output
|
79
|
-
end
|
80
65
|
end
|
81
66
|
|
82
67
|
Spork.each_run do
|
68
|
+
Berkshelf::RSpec::Knife.load_knife_config(File.join(APP_ROOT, 'spec/knife.rb'))
|
69
|
+
|
83
70
|
require 'berkshelf'
|
84
71
|
end
|