berkshelf 5.2.0 → 8.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +19 -47
- data/Rakefile +14 -4
- data/berkshelf.gemspec +61 -40
- data/bin/berks +2 -2
- data/lib/berkshelf/api-client.rb +1 -0
- data/lib/berkshelf/api_client/chef_server_connection.rb +29 -0
- data/lib/berkshelf/api_client/connection.rb +57 -0
- data/lib/berkshelf/api_client/errors.rb +10 -0
- data/lib/berkshelf/api_client/remote_cookbook.rb +56 -0
- data/lib/berkshelf/api_client/version.rb +5 -0
- data/lib/berkshelf/api_client.rb +24 -0
- data/lib/berkshelf/berksfile.rb +149 -122
- data/lib/berkshelf/cached_cookbook.rb +127 -24
- data/lib/berkshelf/chef_config_compat.rb +51 -0
- data/lib/berkshelf/chef_repo_universe.rb +47 -0
- data/lib/berkshelf/cli.rb +143 -174
- data/lib/berkshelf/commands/shelf.rb +20 -19
- data/lib/berkshelf/community_rest.rb +59 -94
- data/lib/berkshelf/config.rb +97 -127
- data/lib/berkshelf/cookbook_store.rb +7 -6
- data/lib/berkshelf/core_ext/file.rb +1 -1
- data/lib/berkshelf/core_ext/file_utils.rb +4 -4
- data/lib/berkshelf/core_ext.rb +1 -1
- data/lib/berkshelf/dependency.rb +25 -32
- data/lib/berkshelf/downloader.rb +66 -39
- data/lib/berkshelf/errors.rb +23 -17
- data/lib/berkshelf/file_syncer.rb +24 -47
- data/lib/berkshelf/formatters/human.rb +7 -5
- data/lib/berkshelf/formatters/json.rb +6 -6
- data/lib/berkshelf/installer.rb +120 -111
- data/lib/berkshelf/location.rb +14 -14
- data/lib/berkshelf/locations/base.rb +1 -1
- data/lib/berkshelf/locations/git.rb +16 -24
- data/lib/berkshelf/locations/github.rb +2 -2
- data/lib/berkshelf/locations/path.rb +2 -2
- data/lib/berkshelf/lockfile.rb +326 -328
- data/lib/berkshelf/logger.rb +64 -1
- data/lib/berkshelf/mixin/git.rb +6 -5
- data/lib/berkshelf/packager.rb +44 -10
- data/lib/berkshelf/resolver/graph.rb +1 -1
- data/lib/berkshelf/resolver.rb +4 -4
- data/lib/berkshelf/ridley_compat.rb +109 -0
- data/lib/berkshelf/shell.rb +2 -1
- data/lib/berkshelf/shell_out.rb +18 -0
- data/lib/berkshelf/source.rb +77 -33
- data/lib/berkshelf/source_uri.rb +4 -4
- data/lib/berkshelf/ssl_policies.rb +38 -0
- data/lib/berkshelf/thor.rb +1 -1
- data/lib/berkshelf/thor_ext/hash_with_indifferent_access.rb +1 -1
- data/lib/berkshelf/thor_ext.rb +1 -1
- data/lib/berkshelf/uploader.rb +106 -70
- data/lib/berkshelf/validator.rb +13 -5
- data/lib/berkshelf/version.rb +1 -1
- data/lib/berkshelf/visualizer.rb +16 -11
- data/lib/berkshelf.rb +106 -81
- data/spec/config/knife.rb +4 -4
- data/spec/data/trusted_certs/example.crt +22 -0
- data/spec/fixtures/Berksfile +3 -3
- data/spec/fixtures/complex-cookbook-path/cookbooks/app/metadata.rb +2 -0
- data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins/metadata.rb +2 -0
- data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins-config/metadata.rb +4 -0
- data/spec/fixtures/cookbook-path/jenkins-config/metadata.rb +3 -3
- data/spec/fixtures/cookbook-path-uploader/apt-2.3.6/metadata.rb +2 -0
- data/spec/fixtures/cookbook-path-uploader/build-essential-1.4.2/metadata.rb +2 -0
- data/spec/fixtures/cookbook-path-uploader/jenkins-2.0.3/metadata.rb +5 -0
- data/spec/fixtures/cookbook-path-uploader/jenkins-config-0.1.0/metadata.rb +4 -0
- data/spec/fixtures/cookbook-path-uploader/runit-1.5.8/metadata.rb +5 -0
- data/spec/fixtures/cookbook-path-uploader/yum-3.0.6/metadata.rb +2 -0
- data/spec/fixtures/cookbook-path-uploader/yum-epel-0.2.0/metadata.rb +3 -0
- data/spec/fixtures/cookbook-store/jenkins-2.0.3/metadata.rb +5 -5
- data/spec/fixtures/cookbook-store/jenkins-2.0.4/metadata.rb +4 -4
- data/spec/fixtures/cookbooks/example_cookbook/metadata.rb +3 -3
- data/spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb +3 -3
- data/spec/spec_helper.rb +56 -64
- data/spec/support/chef_api.rb +15 -16
- data/spec/support/chef_server.rb +71 -69
- data/spec/support/git.rb +59 -58
- data/spec/support/kitchen.rb +0 -14
- data/spec/support/matchers/file_system_matchers.rb +4 -5
- data/spec/support/matchers/filepath_matchers.rb +2 -2
- data/spec/support/path_helpers.rb +17 -17
- data/spec/support/shared_examples/formatter.rb +1 -1
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/attributes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/files/default/file.h +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/metadata.rb +2 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/recipes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/templates/default/template.erb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/attributes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/files/default/file.h +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/metadata.rb +2 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/recipes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/templates/default/template.erb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/attributes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/files/default/file.h +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/metadata.rb +2 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/recipes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/templates/default/template.erb +0 -0
- data/spec/unit/berkshelf/berksfile_spec.rb +84 -105
- data/spec/unit/berkshelf/berkshelf/api_client/chef_server_connection_spec.rb +65 -0
- data/spec/unit/berkshelf/berkshelf/api_client/connection_spec.rb +157 -0
- data/spec/unit/berkshelf/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
- data/spec/unit/berkshelf/berkshelf/api_client_spec.rb +9 -0
- data/spec/unit/berkshelf/cached_cookbook_spec.rb +45 -47
- data/spec/unit/berkshelf/chef_repo_universe_spec.rb +37 -0
- data/spec/unit/berkshelf/cli_spec.rb +7 -8
- data/spec/unit/berkshelf/community_rest_spec.rb +82 -90
- data/spec/unit/berkshelf/config_spec.rb +51 -22
- data/spec/unit/berkshelf/cookbook_store_spec.rb +41 -41
- data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +7 -8
- data/spec/unit/berkshelf/core_ext/pathname_spec.rb +1 -1
- data/spec/unit/berkshelf/dependency_spec.rb +48 -48
- data/spec/unit/berkshelf/downloader_spec.rb +191 -34
- data/spec/unit/berkshelf/errors_spec.rb +3 -3
- data/spec/unit/berkshelf/file_syncer_spec.rb +87 -87
- data/spec/unit/berkshelf/formatters/base_spec.rb +23 -23
- data/spec/unit/berkshelf/formatters/human_spec.rb +2 -2
- data/spec/unit/berkshelf/formatters/json_spec.rb +2 -2
- data/spec/unit/berkshelf/formatters/null_spec.rb +3 -3
- data/spec/unit/berkshelf/installer_spec.rb +8 -8
- data/spec/unit/berkshelf/location_spec.rb +11 -11
- data/spec/unit/berkshelf/locations/base_spec.rb +35 -36
- data/spec/unit/berkshelf/locations/git_spec.rb +90 -93
- data/spec/unit/berkshelf/locations/path_spec.rb +40 -41
- data/spec/unit/berkshelf/lockfile_parser_spec.rb +71 -71
- data/spec/unit/berkshelf/lockfile_spec.rb +205 -211
- data/spec/unit/berkshelf/logger_spec.rb +3 -3
- data/spec/unit/berkshelf/mixin/logging_spec.rb +5 -5
- data/spec/unit/berkshelf/packager_spec.rb +2 -2
- data/spec/unit/berkshelf/resolver/graph_spec.rb +10 -8
- data/spec/unit/berkshelf/resolver_spec.rb +17 -17
- data/spec/unit/berkshelf/ridley_compat_spec.rb +16 -0
- data/spec/unit/berkshelf/shell_spec.rb +34 -34
- data/spec/unit/berkshelf/source_spec.rb +186 -20
- data/spec/unit/berkshelf/source_uri_spec.rb +1 -1
- data/spec/unit/berkshelf/ssl_policies_spec.rb +86 -0
- data/spec/unit/berkshelf/uploader_spec.rb +146 -64
- data/spec/unit/berkshelf/validator_spec.rb +23 -16
- data/spec/unit/berkshelf/visualizer_spec.rb +24 -15
- data/spec/unit/berkshelf_spec.rb +18 -18
- metadata +138 -289
- data/.gitignore +0 -29
- data/.travis.yml +0 -64
- data/CHANGELOG.legacy.md +0 -307
- data/CHANGELOG.md +0 -1358
- data/CONTRIBUTING.md +0 -64
- data/Gemfile.lock +0 -399
- data/Guardfile +0 -23
- data/PLUGINS.md +0 -25
- data/README.md +0 -70
- data/Thorfile +0 -61
- data/appveyor.yml +0 -31
- data/docs/berkshelf_for_newcomers.md +0 -65
- data/features/berksfile.feature +0 -46
- data/features/commands/apply.feature +0 -41
- data/features/commands/contingent.feature +0 -48
- data/features/commands/cookbook.feature +0 -35
- data/features/commands/info.feature +0 -99
- data/features/commands/init.feature +0 -27
- data/features/commands/install.feature +0 -636
- data/features/commands/list.feature +0 -78
- data/features/commands/outdated.feature +0 -130
- data/features/commands/package.feature +0 -17
- data/features/commands/search.feature +0 -17
- data/features/commands/shelf/list.feature +0 -32
- data/features/commands/shelf/show.feature +0 -143
- data/features/commands/shelf/uninstall.feature +0 -96
- data/features/commands/show.feature +0 -83
- data/features/commands/update.feature +0 -142
- data/features/commands/upload.feature +0 -426
- data/features/commands/vendor.feature +0 -111
- data/features/commands/verify.feature +0 -29
- data/features/commands/viz.feature +0 -66
- data/features/community_site.feature +0 -37
- data/features/config.feature +0 -111
- data/features/help.feature +0 -11
- data/features/json_formatter.feature +0 -161
- data/features/lifecycle.feature +0 -378
- data/features/lockfile.feature +0 -378
- data/features/step_definitions/berksfile_steps.rb +0 -39
- data/features/step_definitions/chef/config_steps.rb +0 -12
- data/features/step_definitions/chef_server_steps.rb +0 -60
- data/features/step_definitions/cli_steps.rb +0 -18
- data/features/step_definitions/config_steps.rb +0 -46
- data/features/step_definitions/environment_steps.rb +0 -7
- data/features/step_definitions/filesystem_steps.rb +0 -269
- data/features/step_definitions/gem_steps.rb +0 -13
- data/features/step_definitions/json_steps.rb +0 -23
- data/features/step_definitions/utility_steps.rb +0 -11
- data/features/support/aruba.rb +0 -12
- data/features/support/env.rb +0 -82
- data/generator_files/Berksfile.erb +0 -11
- data/generator_files/CHANGELOG.md.erb +0 -3
- data/generator_files/Gemfile.erb +0 -8
- data/generator_files/README.md.erb +0 -42
- data/generator_files/Thorfile.erb +0 -11
- data/generator_files/Vagrantfile.erb +0 -117
- data/generator_files/chefignore +0 -94
- data/generator_files/default_recipe.erb +0 -6
- data/generator_files/default_test.rb.erb +0 -11
- data/generator_files/gitignore.erb +0 -23
- data/generator_files/helpers.rb.erb +0 -7
- data/generator_files/licenses/apachev2.erb +0 -13
- data/generator_files/licenses/gplv2.erb +0 -15
- data/generator_files/licenses/gplv3.erb +0 -14
- data/generator_files/licenses/mit.erb +0 -20
- data/generator_files/licenses/reserved.erb +0 -3
- data/generator_files/metadata.rb.erb +0 -11
- data/lib/berkshelf/base_generator.rb +0 -43
- data/lib/berkshelf/commands/test_command.rb +0 -13
- data/lib/berkshelf/cookbook_generator.rb +0 -133
- data/lib/berkshelf/init_generator.rb +0 -195
- data/spec/fixtures/cookbooks/example_cookbook/.gitignore +0 -2
- data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +0 -26
- data/spec/unit/berkshelf/cookbook_generator_spec.rb +0 -110
- data/spec/unit/berkshelf/init_generator_spec.rb +0 -263
@@ -1,6 +1,6 @@
|
|
1
|
-
name
|
2
|
-
version
|
1
|
+
name "jenkins"
|
2
|
+
version "2.0.3"
|
3
3
|
|
4
|
-
depends
|
5
|
-
depends
|
6
|
-
depends
|
4
|
+
depends "apt", "~> 2.0"
|
5
|
+
depends "runit", "~> 1.5"
|
6
|
+
depends "yum", "~> 3.0"
|
@@ -1,5 +1,5 @@
|
|
1
|
-
name
|
2
|
-
version
|
1
|
+
name "jenkins"
|
2
|
+
version "2.0.4"
|
3
3
|
|
4
|
-
depends
|
5
|
-
depends
|
4
|
+
depends "apt", "~> 2.0"
|
5
|
+
depends "runit", "~> 1.5"
|
@@ -1,3 +1,3 @@
|
|
1
|
-
name
|
2
|
-
maintainer
|
3
|
-
version
|
1
|
+
name "example_cookbook"
|
2
|
+
maintainer "Berkshelf Core"
|
3
|
+
version "0.5.0"
|
@@ -1,3 +1,3 @@
|
|
1
|
-
name
|
2
|
-
maintainer
|
3
|
-
version
|
1
|
+
name "example_cookbook"
|
2
|
+
maintainer "Berkshelf Core"
|
3
|
+
version "0.5.0"
|
data/spec/spec_helper.rb
CHANGED
@@ -1,87 +1,79 @@
|
|
1
|
-
require 'spork'
|
2
|
-
|
3
1
|
def windows?
|
4
2
|
!!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
|
5
3
|
end
|
6
4
|
|
7
|
-
|
8
|
-
require 'rspec'
|
9
|
-
require 'cleanroom/rspec'
|
10
|
-
require 'webmock/rspec'
|
11
|
-
require 'berkshelf/api/rspec' unless windows?
|
5
|
+
BERKS_SPEC_DATA = File.expand_path("data", __dir__)
|
12
6
|
|
13
|
-
|
7
|
+
require "rspec"
|
8
|
+
require "cleanroom/rspec"
|
9
|
+
require "webmock/rspec"
|
10
|
+
require "rspec/its"
|
14
11
|
|
15
|
-
|
16
|
-
config.include Berkshelf::RSpec::FileSystemMatchers
|
17
|
-
config.include Berkshelf::RSpec::ChefAPI
|
18
|
-
config.include Berkshelf::RSpec::ChefServer
|
19
|
-
config.include Berkshelf::RSpec::Git
|
20
|
-
config.include Berkshelf::RSpec::PathHelpers
|
21
|
-
config.include Berkshelf::API::RSpec unless windows?
|
12
|
+
Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) }
|
22
13
|
|
23
|
-
|
24
|
-
|
25
|
-
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.include Berkshelf::RSpec::FileSystemMatchers
|
16
|
+
config.include Berkshelf::RSpec::ChefAPI
|
17
|
+
config.include Berkshelf::RSpec::ChefServer
|
18
|
+
config.include Berkshelf::RSpec::Git
|
19
|
+
config.include Berkshelf::RSpec::PathHelpers
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
config.run_all_when_everything_filtered = true
|
21
|
+
config.expect_with :rspec do |c|
|
22
|
+
c.syntax = :expect
|
23
|
+
end
|
31
24
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
25
|
+
config.mock_with :rspec
|
26
|
+
config.filter_run focus: true
|
27
|
+
config.filter_run_excluding not_supported_on_windows: windows?
|
28
|
+
config.run_all_when_everything_filtered = true
|
37
29
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
30
|
+
config.before(:each) do
|
31
|
+
Berkshelf.logger = Berkshelf::Logger.new(nil)
|
32
|
+
Berkshelf.set_format(:null)
|
33
|
+
Berkshelf.ui.mute!
|
34
|
+
end
|
43
35
|
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
config.before(:suite) do
|
37
|
+
WebMock.disable_net_connect!(allow_localhost: false, net_http_connect_on_start: true)
|
38
|
+
Berkshelf::RSpec::ChefServer.start
|
39
|
+
end
|
47
40
|
|
48
|
-
|
49
|
-
|
50
|
-
clean_tmp_path
|
51
|
-
Berkshelf.initialize_filesystem
|
52
|
-
Berkshelf::CookbookStore.instance.initialize_filesystem
|
53
|
-
reload_configs
|
54
|
-
end
|
41
|
+
config.before(:all) do
|
42
|
+
ENV["BERKSHELF_PATH"] = berkshelf_path.to_s
|
55
43
|
end
|
56
44
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
eval("$#{stream} = #{stream.upcase}")
|
65
|
-
end
|
45
|
+
config.before(:each) do
|
46
|
+
clean_tmp_path
|
47
|
+
Berkshelf.initialize_filesystem
|
48
|
+
Berkshelf::CookbookStore.instance.initialize_filesystem
|
49
|
+
reload_configs
|
50
|
+
end
|
51
|
+
end
|
66
52
|
|
67
|
-
|
53
|
+
def capture(stream)
|
54
|
+
begin
|
55
|
+
stream = stream.to_s
|
56
|
+
eval "$#{stream} = StringIO.new"
|
57
|
+
yield
|
58
|
+
result = eval("$#{stream}").string
|
59
|
+
ensure
|
60
|
+
eval("$#{stream} = #{stream.upcase}")
|
68
61
|
end
|
62
|
+
|
63
|
+
result
|
69
64
|
end
|
70
65
|
|
71
|
-
|
72
|
-
require 'berkshelf'
|
66
|
+
require "berkshelf"
|
73
67
|
|
74
|
-
|
75
|
-
|
76
|
-
|
68
|
+
module Berkshelf
|
69
|
+
class GitLocation
|
70
|
+
include Berkshelf::RSpec::Git
|
77
71
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
real_clone
|
84
|
-
end
|
72
|
+
alias :real_clone :clone
|
73
|
+
def clone
|
74
|
+
fake_remote = generate_fake_git_remote(uri, tags: @branch ? [@branch] : [])
|
75
|
+
@uri = "file://#{fake_remote}"
|
76
|
+
real_clone
|
85
77
|
end
|
86
78
|
end
|
87
79
|
end
|
data/spec/support/chef_api.rb
CHANGED
@@ -58,13 +58,13 @@ module Berkshelf
|
|
58
58
|
"files/default",
|
59
59
|
"attributes",
|
60
60
|
"providers",
|
61
|
-
"resources"
|
61
|
+
"resources",
|
62
62
|
]
|
63
63
|
files = [
|
64
64
|
"recipes/default.rb",
|
65
65
|
"templates/default/template.erb",
|
66
66
|
"files/default/file.h",
|
67
|
-
"attributes/default.rb"
|
67
|
+
"attributes/default.rb",
|
68
68
|
]
|
69
69
|
|
70
70
|
directories.each do |directory|
|
@@ -82,20 +82,19 @@ module Berkshelf
|
|
82
82
|
a << "" # ensure newline
|
83
83
|
end.join("\n")
|
84
84
|
|
85
|
-
|
86
85
|
if options[:dependencies]
|
87
|
-
options[:dependencies].each do |
|
88
|
-
metadata << "depends '#{
|
86
|
+
options[:dependencies].each do |dep_name, constraint|
|
87
|
+
metadata << "depends '#{dep_name}', '#{constraint}'\n"
|
89
88
|
end
|
90
89
|
end
|
91
90
|
|
92
91
|
if options[:recommendations]
|
93
|
-
options[:recommendations].each do |
|
94
|
-
metadata << "recommends '#{
|
92
|
+
options[:recommendations].each do |rec_name, constraint|
|
93
|
+
metadata << "recommends '#{rec_name}', '#{constraint}'\n"
|
95
94
|
end
|
96
95
|
end
|
97
96
|
|
98
|
-
File.open(cookbook_path.join("metadata.rb"),
|
97
|
+
File.open(cookbook_path.join("metadata.rb"), "w+") do |f|
|
99
98
|
f.write metadata
|
100
99
|
end
|
101
100
|
|
@@ -120,14 +119,14 @@ module Berkshelf
|
|
120
119
|
|
121
120
|
private
|
122
121
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
122
|
+
def ridley
|
123
|
+
@ridley ||= Ridley.new(
|
124
|
+
server_url: Berkshelf::RSpec::ChefServer.server_url,
|
125
|
+
client_name: Berkshelf.chef_config[:node_name],
|
126
|
+
client_key: Berkshelf.chef_config[:client_key],
|
127
|
+
ssl: { verify: false }
|
128
|
+
)
|
129
|
+
end
|
131
130
|
end
|
132
131
|
end
|
133
132
|
end
|
data/spec/support/chef_server.rb
CHANGED
@@ -1,99 +1,101 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "chef_zero/server"
|
2
|
+
require "json"
|
3
3
|
|
4
|
-
module Berkshelf
|
5
|
-
module
|
6
|
-
|
4
|
+
module Berkshelf
|
5
|
+
module RSpec
|
6
|
+
module ChefServer
|
7
|
+
PORT = 4000
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
class << self
|
10
|
+
attr_reader :server
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def clear_request_log
|
13
|
+
@request_log = []
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def request_log
|
17
|
+
@request_log ||= []
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def server_url
|
21
|
+
@server && @server.url
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
def start(options = {})
|
25
|
+
return @server if @server
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
options = { port: PORT }.merge(options)
|
28
|
+
options[:generate_real_keys] = false
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
@server = ChefZero::Server.new(options)
|
31
|
+
@server.start_background
|
32
|
+
@server.on_response do |request, response|
|
33
|
+
request_log << [ request, response ]
|
34
|
+
end
|
35
|
+
clear_request_log
|
36
|
+
|
37
|
+
@server
|
33
38
|
end
|
34
|
-
clear_request_log
|
35
39
|
|
36
|
-
|
37
|
-
|
40
|
+
def stop
|
41
|
+
@server.stop if running?
|
42
|
+
end
|
38
43
|
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
def running?
|
45
|
+
@server && @server.running?
|
46
|
+
end
|
42
47
|
|
43
|
-
|
44
|
-
|
48
|
+
def reset!
|
49
|
+
@server && @server.clear_data
|
50
|
+
end
|
45
51
|
end
|
46
52
|
|
47
|
-
def
|
48
|
-
|
53
|
+
def chef_server
|
54
|
+
ChefServer.server
|
49
55
|
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def chef_server
|
53
|
-
ChefServer.server
|
54
|
-
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
def chef_client(name, hash = {})
|
58
|
+
load_data(:clients, name, hash)
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
61
|
+
def chef_cookbook(name, hash = {})
|
62
|
+
chef_server.load_data({ "cookbooks" => { name => hash } })
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
def chef_cookbooks
|
66
|
+
chef_server.data_store.list(%w{organizations chef cookbooks}).inject({}) do |hash, name|
|
67
|
+
hash[name] = chef_server.data_store.list(["organizations", "chef", "cookbooks", name])
|
68
|
+
hash
|
69
|
+
end
|
68
70
|
end
|
69
|
-
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
def chef_data_bag(name, hash = {})
|
73
|
+
chef_server.load_data({ "data" => { name => hash } })
|
74
|
+
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
def chef_environment(name, hash = {})
|
77
|
+
load_data(:environments, name, hash)
|
78
|
+
end
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
def chef_environment_locks(name)
|
81
|
+
JSON.parse(chef_server.data_store.get(["organizations", "chef", "environments", name]))["cookbook_versions"]
|
82
|
+
rescue ChefZero::DataStore::DataNotFoundError
|
83
|
+
{}
|
84
|
+
end
|
84
85
|
|
85
|
-
|
86
|
-
|
87
|
-
|
86
|
+
def chef_node(name, hash = {})
|
87
|
+
load_data(:nodes, name, hash)
|
88
|
+
end
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
def chef_role(name, hash = {})
|
91
|
+
load_data(:roles, name, hash)
|
92
|
+
end
|
92
93
|
|
93
|
-
|
94
|
+
private
|
94
95
|
|
95
96
|
def load_data(key, name, hash)
|
96
|
-
chef_server.load_data({ key.to_s => { name => JSON.generate(hash) }})
|
97
|
+
chef_server.load_data({ key.to_s => { name => JSON.generate(hash) } })
|
97
98
|
end
|
99
|
+
end
|
98
100
|
end
|
99
101
|
end
|
data/spec/support/git.rb
CHANGED
@@ -1,19 +1,16 @@
|
|
1
1
|
module Berkshelf
|
2
2
|
module RSpec
|
3
3
|
module Git
|
4
|
-
|
5
|
-
include Buff::ShellOut
|
6
|
-
|
7
|
-
require_relative 'path_helpers'
|
4
|
+
require_relative "path_helpers"
|
8
5
|
include Berkshelf::RSpec::PathHelpers
|
9
6
|
|
10
7
|
def git_origin_for(repo, options = {})
|
11
|
-
"file://#{generate_fake_git_remote("git@github.com/
|
8
|
+
"file://#{generate_fake_git_remote("git@github.com/chef/#{repo}.git", options)}/.git"
|
12
9
|
end
|
13
10
|
|
14
11
|
def generate_fake_git_remote(uri, options = {})
|
15
|
-
name = uri.split(
|
16
|
-
name = name.gsub(
|
12
|
+
name = uri.split("/").last || "rspec_cookbook"
|
13
|
+
name = name.gsub(".git", "")
|
17
14
|
path = remotes.join(name)
|
18
15
|
|
19
16
|
capture(:stdout) do
|
@@ -25,20 +22,24 @@ module Berkshelf
|
|
25
22
|
shell_out "git add ."
|
26
23
|
shell_out "git commit -am \"A commit.\""
|
27
24
|
|
28
|
-
options[:tags]
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
25
|
+
if options[:tags]
|
26
|
+
options[:tags].each do |tag|
|
27
|
+
shell_out "echo \"#{tag}\" > content_file"
|
28
|
+
shell_out "git add content_file"
|
29
|
+
shell_out "git commit -am \"#{tag} content\""
|
30
|
+
shell_out "git tag \"#{tag}\""
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if options[:branches]
|
35
|
+
options[:branches].each do |branch|
|
36
|
+
shell_out "git checkout -b #{branch} master"
|
37
|
+
shell_out "echo \"#{branch}\" > content_file"
|
38
|
+
shell_out "git add content_file"
|
39
|
+
shell_out "git commit -am \"#{branch} content\""
|
40
|
+
shell_out "git checkout master"
|
41
|
+
end
|
42
|
+
end
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -83,46 +84,46 @@ module Berkshelf
|
|
83
84
|
|
84
85
|
private
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
87
|
+
# The path to store the local git clones.
|
88
|
+
#
|
89
|
+
# @return [Pathname]
|
90
|
+
def clones
|
91
|
+
ensure_and_return(tmp_path.join("clones"))
|
92
|
+
end
|
92
93
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
# The path to store the git remotes.
|
95
|
+
#
|
96
|
+
# @return [Pathname]
|
97
|
+
def remotes
|
98
|
+
ensure_and_return(tmp_path.join("remotes"))
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
101
|
+
# Generate a cookbook by the given name.
|
102
|
+
#
|
103
|
+
# @param [#to_s] name
|
104
|
+
# the name of the cookbook to create
|
105
|
+
# @param [Hash] options
|
106
|
+
# the list ooptions to pass to the generator
|
107
|
+
def generate_git_cookbook(name, options = {})
|
108
|
+
options = {
|
109
|
+
skip_vagrant: true,
|
110
|
+
skip_test_kitchen: true,
|
111
|
+
force: true,
|
112
|
+
}.merge(options)
|
113
|
+
|
114
|
+
Berkshelf::Cli.new.invoke(:cookbook, [name.to_s], options)
|
115
|
+
end
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
117
|
+
# Make sure the given path exists and return the path
|
118
|
+
#
|
119
|
+
# @param [#to_s] path
|
120
|
+
# the path to create and return
|
121
|
+
#
|
122
|
+
# @return [Pathname]
|
123
|
+
def ensure_and_return(path)
|
124
|
+
FileUtils.mkdir(path) unless File.exist?(path)
|
125
|
+
Pathname.new(path).expand_path
|
126
|
+
end
|
126
127
|
end
|
127
128
|
end
|
128
129
|
end
|
data/spec/support/kitchen.rb
CHANGED
@@ -1,14 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module RSpec
|
3
|
-
module Kitchen
|
4
|
-
require 'kitchen/generator/init'
|
5
|
-
|
6
|
-
def stub_kitchen!
|
7
|
-
generator = double('kitchen-generator', invoke_all: nil)
|
8
|
-
allow(::Kitchen::Generator::Init).to receive(:new)
|
9
|
-
.with(any_args())
|
10
|
-
.and_return(generator)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -23,11 +23,12 @@ module Berkshelf
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def matches?(root)
|
26
|
-
|
26
|
+
path = Pathname.glob(root.join(@name)).first
|
27
|
+
unless path.exist?
|
27
28
|
throw :failure, root.join(@name)
|
28
29
|
end
|
29
30
|
|
30
|
-
contents = File.read(
|
31
|
+
contents = File.read(path)
|
31
32
|
|
32
33
|
@contents.each do |string|
|
33
34
|
unless contents.include?(string)
|
@@ -58,9 +59,7 @@ module Berkshelf
|
|
58
59
|
end
|
59
60
|
|
60
61
|
def file(name, &block)
|
61
|
-
|
62
|
-
@tree[name] = FileMatcher.new(location(name), &block)
|
63
|
-
end
|
62
|
+
@tree[name] = FileMatcher.new(location(name), &block)
|
64
63
|
end
|
65
64
|
|
66
65
|
def no_file(name)
|