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
@@ -0,0 +1,157 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Berkshelf::APIClient::Connection do
|
4
|
+
let(:instance) { described_class.new("http://supermarket.getchef.com") }
|
5
|
+
|
6
|
+
describe "#universe" do
|
7
|
+
before do
|
8
|
+
body_response = %q{{"ruby":{"1.2.3":{"endpoint_priority":0,"platforms":{},"dependencies":{"build-essential":">= 1.2.2"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"},"2.0.0":{"endpoint_priority":0,"platforms":{},"dependencies":{"build-essential":">= 1.2.2"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}},"elixir":{"1.0.0":{"endpoint_priority":0,"platforms":{"CentOS":"= 6.0.0"},"dependencies":{},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}}}}
|
9
|
+
|
10
|
+
stub_request(:get, "http://supermarket.getchef.com/universe")
|
11
|
+
.to_return(status: 200, body: body_response, headers: { "Content-Type" => "application/json; charset=utf-8" })
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { instance.universe }
|
15
|
+
|
16
|
+
it "returns an array of APIClient::RemoteCookbook" do
|
17
|
+
expect(subject).to be_a(Array)
|
18
|
+
|
19
|
+
subject.each do |remote|
|
20
|
+
expect(remote).to be_a(Berkshelf::APIClient::RemoteCookbook)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "contains a item for each dependency" do
|
25
|
+
expect(subject.size).to eq(3)
|
26
|
+
expect(subject[0].name).to eql("ruby")
|
27
|
+
expect(subject[0].version).to eql("1.2.3")
|
28
|
+
expect(subject[1].name).to eql("ruby")
|
29
|
+
expect(subject[1].version).to eql("2.0.0")
|
30
|
+
expect(subject[2].name).to eql("elixir")
|
31
|
+
expect(subject[2].version).to eql("1.0.0")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has the dependencies for each" do
|
35
|
+
expect(subject[0].dependencies).to include("build-essential" => ">= 1.2.2")
|
36
|
+
expect(subject[1].dependencies).to include("build-essential" => ">= 1.2.2")
|
37
|
+
expect(subject[2].dependencies).to be_empty
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has the platforms for each" do
|
41
|
+
expect(subject[0].platforms).to be_empty
|
42
|
+
expect(subject[1].platforms).to be_empty
|
43
|
+
expect(subject[2].platforms).to include("CentOS" => "= 6.0.0")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has a location_path for each" do
|
47
|
+
subject.each do |remote|
|
48
|
+
expect(remote.location_path).to_not be_nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "has a location_type for each" do
|
53
|
+
subject.each do |remote|
|
54
|
+
expect(remote.location_type).to_not be_nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "disabling ssl validation on requests" do
|
60
|
+
let(:instance) { described_class.new("https://supermarket.getchef.com", ssl: { verify: false }) }
|
61
|
+
|
62
|
+
before do
|
63
|
+
body_response = %q{{"ruby":{"1.2.3":{"endpoint_priority":0,"platforms":{},"dependencies":{"build-essential":">= 1.2.2"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"},"2.0.0":{"endpoint_priority":0,"platforms":{},"dependencies":{"build-essential":">= 1.2.2"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}},"elixir":{"1.0.0":{"endpoint_priority":0,"platforms":{"CentOS":"= 6.0.0"},"dependencies":{},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}}}}
|
64
|
+
|
65
|
+
stub_request(:get, "https://supermarket.getchef.com/universe")
|
66
|
+
.to_return(status: 200, body: body_response, headers: { "Content-Type" => "application/json; charset=utf-8" })
|
67
|
+
end
|
68
|
+
|
69
|
+
subject { instance.universe }
|
70
|
+
|
71
|
+
it "correctly disables SSL validation" do
|
72
|
+
expect_any_instance_of(Net::HTTP).to receive(:use_ssl=).with(true).and_call_original
|
73
|
+
expect_any_instance_of(Net::HTTP).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE).and_call_original
|
74
|
+
expect(subject).to be_a(Array)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "enabling ssl validation on requests" do
|
79
|
+
let(:instance) { described_class.new("https://supermarket.getchef.com", ssl: { verify: true }) }
|
80
|
+
|
81
|
+
before do
|
82
|
+
body_response = %q{{"ruby":{"1.2.3":{"endpoint_priority":0,"platforms":{},"dependencies":{"build-essential":">= 1.2.2"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"},"2.0.0":{"endpoint_priority":0,"platforms":{},"dependencies":{"build-essential":">= 1.2.2"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}},"elixir":{"1.0.0":{"endpoint_priority":0,"platforms":{"CentOS":"= 6.0.0"},"dependencies":{},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}}}}
|
83
|
+
|
84
|
+
stub_request(:get, "https://supermarket.getchef.com/universe")
|
85
|
+
.to_return(status: 200, body: body_response, headers: { "Content-Type" => "application/json; charset=utf-8" })
|
86
|
+
end
|
87
|
+
|
88
|
+
subject { instance.universe }
|
89
|
+
|
90
|
+
it "correctly disables SSL validation" do
|
91
|
+
expect_any_instance_of(Net::HTTP).to receive(:use_ssl=).with(true).and_call_original
|
92
|
+
expect_any_instance_of(Net::HTTP).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER).and_call_original
|
93
|
+
expect(subject).to be_a(Array)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "enabling ssl validation by default" do
|
98
|
+
let(:instance) { described_class.new("https://supermarket.getchef.com") }
|
99
|
+
|
100
|
+
before do
|
101
|
+
body_response = %q{{"ruby":{"1.2.3":{"endpoint_priority":0,"platforms":{},"dependencies":{"build-essential":">= 1.2.2"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"},"2.0.0":{"endpoint_priority":0,"platforms":{},"dependencies":{"build-essential":">= 1.2.2"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}},"elixir":{"1.0.0":{"endpoint_priority":0,"platforms":{"CentOS":"= 6.0.0"},"dependencies":{},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}}}}
|
102
|
+
|
103
|
+
stub_request(:get, "https://supermarket.getchef.com/universe")
|
104
|
+
.to_return(status: 200, body: body_response, headers: { "Content-Type" => "application/json; charset=utf-8" })
|
105
|
+
end
|
106
|
+
|
107
|
+
subject { instance.universe }
|
108
|
+
|
109
|
+
it "correctly disables SSL validation" do
|
110
|
+
expect_any_instance_of(Net::HTTP).to receive(:use_ssl=).with(true).and_call_original
|
111
|
+
expect_any_instance_of(Net::HTTP).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER).and_call_original
|
112
|
+
expect(subject).to be_a(Array)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "non-200s" do
|
117
|
+
before do
|
118
|
+
Chef::Config[:http_retry_delay] = 0.001
|
119
|
+
Chef::Config[:http_retry_count] = 0
|
120
|
+
end
|
121
|
+
|
122
|
+
subject { instance.universe }
|
123
|
+
|
124
|
+
it "follows 301 redirects correctly" do
|
125
|
+
stub_request(:get, "http://supermarket.getchef.com/universe").to_return(status: 301, headers: { "Location" => "http://arglebargle.com/universe" })
|
126
|
+
body_response = %q{{"ruby":{"1.2.3":{"endpoint_priority":0,"platforms":{},"dependencies":{"build-essential":">= 1.2.2"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"},"2.0.0":{"endpoint_priority":0,"platforms":{},"dependencies":{"build-essential":">= 1.2.2"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}},"elixir":{"1.0.0":{"endpoint_priority":0,"platforms":{"CentOS":"= 6.0.0"},"dependencies":{},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}}}}
|
127
|
+
stub_request(:get, "http://arglebargle.com/universe")
|
128
|
+
.to_return(status: 200, body: body_response, headers: { "Content-Type" => "application/json; charset=utf-8" })
|
129
|
+
expect(subject.size).to eq(3)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "raises Berkshelf::APIClient::ServiceUnavailable for 500s" do
|
133
|
+
stub_request(:get, "http://supermarket.getchef.com/universe").to_return(status: 500, body: "Internal Server Error")
|
134
|
+
expect { subject }.to raise_error(Berkshelf::APIClient::ServiceUnavailable)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "raises Berkshelf::APIClient::ServiceNotFound for 404s" do
|
138
|
+
stub_request(:get, "http://supermarket.getchef.com/universe").to_return(status: 404, body: "Not Found")
|
139
|
+
expect { subject }.to raise_error(Berkshelf::APIClient::ServiceNotFound)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "raises Net::HTTPBadRequest for 400s" do
|
143
|
+
stub_request(:get, "http://supermarket.getchef.com/universe").to_return(status: 400, body: "Bad Request")
|
144
|
+
expect { subject }.to raise_error(Berkshelf::APIClient::BadResponse)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "raises Berkshelf::APIClient::TimeoutError for timeouts" do
|
148
|
+
stub_request(:get, "http://supermarket.getchef.com/universe").to_timeout
|
149
|
+
expect { subject }.to raise_error(Berkshelf::APIClient::TimeoutError)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "raises Berkshelf::APIClient::TimeoutError for timeouts" do
|
153
|
+
stub_request(:get, "http://supermarket.getchef.com/universe").to_raise(Errno::ECONNREFUSED)
|
154
|
+
expect { subject }.to raise_error(Berkshelf::APIClient::ServiceUnavailable)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Berkshelf::APIClient::RemoteCookbook do
|
4
|
+
let(:name) { "ruby" }
|
5
|
+
let(:version) { "1.2.3" }
|
6
|
+
let(:dependencies) { double("dependencies") }
|
7
|
+
let(:platforms) { double("platforms") }
|
8
|
+
let(:location_type) { "chef_server" }
|
9
|
+
let(:location_path) { "http://localhost:8080" }
|
10
|
+
|
11
|
+
let(:attributes) do
|
12
|
+
{ dependencies: dependencies, platforms: platforms, location_path: location_path, location_type: location_type }
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { described_class.new(name, version, attributes) }
|
16
|
+
|
17
|
+
its(:name) { should eql(name) }
|
18
|
+
its(:version) { should eql(version) }
|
19
|
+
its(:dependencies) { should eql(dependencies) }
|
20
|
+
its(:platforms) { should eql(platforms) }
|
21
|
+
its(:location_type) { should eql(:chef_server) }
|
22
|
+
its(:location_path) { should eql(location_path) }
|
23
|
+
end
|
@@ -1,48 +1,48 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::CachedCookbook do
|
4
4
|
describe "ClassMethods" do
|
5
|
-
describe
|
6
|
-
let(:path) { fixtures_path.join(
|
5
|
+
describe "::from_store_path" do
|
6
|
+
let(:path) { fixtures_path.join("cookbooks", "example_cookbook-0.5.0") }
|
7
7
|
let(:cached) { described_class.from_path(path) }
|
8
8
|
|
9
|
-
it
|
9
|
+
it "returns a CachedCookbook" do
|
10
10
|
expect(cached).to be_a(described_class)
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
expect(cached.version).to eq(
|
13
|
+
it "sets a version number" do
|
14
|
+
expect(cached.version).to eq("0.5.0")
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
expect(cached.metadata.name).to eq(
|
17
|
+
it "sets the metadata.name value to the cookbook_name" do
|
18
|
+
expect(cached.metadata.name).to eq("example_cookbook")
|
19
19
|
end
|
20
20
|
|
21
|
-
context
|
22
|
-
it
|
21
|
+
context "given a path that does not contain a cookbook" do
|
22
|
+
it "returns nil" do
|
23
23
|
expect(described_class.from_store_path(tmp_path)).to be_nil
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
context
|
28
|
-
it
|
29
|
-
path = fixtures_path.join(
|
27
|
+
context "given a path that does not match the CachedCookbook dirname format" do
|
28
|
+
it "returns nil" do
|
29
|
+
path = fixtures_path.join("cookbooks", "example_cookbook")
|
30
30
|
expect(described_class.from_store_path(path)).to be_nil
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
context
|
34
|
+
context "given an already cached cookbook" do
|
35
35
|
let!(:cached) { described_class.from_store_path(path) }
|
36
36
|
|
37
|
-
it
|
37
|
+
it "returns the cached cookbook instance" do
|
38
38
|
expect(described_class.from_store_path(path)).to eq(cached)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
describe
|
44
|
-
it
|
45
|
-
path = fixtures_path.join(
|
43
|
+
describe "::checksum" do
|
44
|
+
it "returns a checksum of the given filepath" do
|
45
|
+
path = fixtures_path.join("cookbooks", "example_cookbook-0.5.0", "README.md")
|
46
46
|
expected_md5 = if IO.binread(path).include?("\r\n")
|
47
47
|
# On windows, with git configured for auto crlf
|
48
48
|
"2414583f86c9eb68bdbb0be391939341"
|
@@ -52,53 +52,51 @@ describe Berkshelf::CachedCookbook do
|
|
52
52
|
expect(described_class.checksum(path)).to eq(expected_md5)
|
53
53
|
end
|
54
54
|
|
55
|
-
context
|
56
|
-
it
|
57
|
-
expect
|
58
|
-
described_class.checksum(fixtures_path.join(
|
59
|
-
|
55
|
+
context "given path does not exist" do
|
56
|
+
it "raises an Errno::ENOENT error" do
|
57
|
+
expect do
|
58
|
+
described_class.checksum(fixtures_path.join("notexisting.file"))
|
59
|
+
end.to raise_error(Errno::ENOENT)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
let(:dependencies) { {
|
66
|
-
let(:recommendations) { {
|
65
|
+
let(:dependencies) { { "mysql" => "= 1.2.0", "ntp" => ">= 0.0.0" } }
|
66
|
+
let(:recommendations) { { "database" => ">= 0.0.0" } }
|
67
67
|
let(:path) do
|
68
68
|
generate_cookbook(Berkshelf.cookbook_store.storage_path,
|
69
|
-
|
69
|
+
"sparkle", "0.1.0", dependencies: dependencies, recommendations: recommendations)
|
70
70
|
end
|
71
71
|
|
72
72
|
subject { Berkshelf::CachedCookbook.from_store_path(path) }
|
73
73
|
|
74
|
-
describe
|
75
|
-
it
|
74
|
+
describe "#dependencies" do
|
75
|
+
it "contains depends from the cookbook metadata" do
|
76
76
|
expect(subject.dependencies).to include(dependencies)
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
80
|
-
expect(subject.dependencies).to include(recommendations)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'returns a hash' do
|
79
|
+
it "returns a hash" do
|
84
80
|
expect(subject.dependencies).to be_a(Hash)
|
85
81
|
end
|
86
82
|
end
|
87
83
|
|
88
|
-
describe
|
89
|
-
shared_examples
|
84
|
+
describe "#pretty_hash" do
|
85
|
+
shared_examples "a pretty_hash string cookbook attribute" do |attribute, key|
|
90
86
|
it "is not present when the `#{attribute}` attribute is nil" do
|
91
87
|
allow(subject).to receive(attribute.to_sym).and_return(nil)
|
92
88
|
expect(subject.pretty_hash).to_not have_key((key || attribute).to_sym)
|
93
89
|
end
|
94
90
|
|
95
91
|
it "is not present when the `#{attribute}` attribute is an empty string" do
|
96
|
-
allow(subject).to receive(attribute.to_sym).and_return(
|
92
|
+
allow(subject).to receive(attribute.to_sym).and_return("")
|
97
93
|
expect(subject.pretty_hash).to_not have_key((key || attribute).to_sym)
|
98
94
|
end
|
95
|
+
end
|
99
96
|
|
100
|
-
|
101
|
-
|
97
|
+
shared_examples "a pretty_hash hash cookbook attribute" do |attribute, key|
|
98
|
+
it "is not present when the `#{attribute}` attribute is nil" do
|
99
|
+
allow(subject).to receive(attribute.to_sym).and_return(nil)
|
102
100
|
expect(subject.pretty_hash).to_not have_key((key || attribute).to_sym)
|
103
101
|
end
|
104
102
|
|
@@ -108,18 +106,18 @@ describe Berkshelf::CachedCookbook do
|
|
108
106
|
end
|
109
107
|
|
110
108
|
it "is present when the `#{attribute}` attribute has a Hash value" do
|
111
|
-
allow(subject).to receive(attribute.to_sym).and_return(foo:
|
109
|
+
allow(subject).to receive(attribute.to_sym).and_return(foo: "bar")
|
112
110
|
expect(subject.pretty_hash).to have_key((key || attribute).to_sym)
|
113
111
|
end
|
114
112
|
end
|
115
113
|
|
116
|
-
it_behaves_like
|
117
|
-
it_behaves_like
|
118
|
-
it_behaves_like
|
119
|
-
it_behaves_like
|
120
|
-
it_behaves_like
|
121
|
-
it_behaves_like
|
122
|
-
it_behaves_like
|
123
|
-
it_behaves_like
|
114
|
+
it_behaves_like "a pretty_hash string cookbook attribute", "cookbook_name", "name"
|
115
|
+
it_behaves_like "a pretty_hash string cookbook attribute", "version"
|
116
|
+
it_behaves_like "a pretty_hash string cookbook attribute", "description"
|
117
|
+
it_behaves_like "a pretty_hash string cookbook attribute", "maintainer", "author"
|
118
|
+
it_behaves_like "a pretty_hash string cookbook attribute", "maintainer_email", "email"
|
119
|
+
it_behaves_like "a pretty_hash string cookbook attribute", "license"
|
120
|
+
it_behaves_like "a pretty_hash hash cookbook attribute", "platforms"
|
121
|
+
it_behaves_like "a pretty_hash hash cookbook attribute", "dependencies"
|
124
122
|
end
|
125
123
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Berkshelf
|
4
|
+
describe ChefRepoUniverse do
|
5
|
+
let(:fixture) { nil }
|
6
|
+
let(:fixture_path) { File.expand_path("../../../fixtures/#{fixture}", __FILE__) }
|
7
|
+
subject { described_class.new("file://#{fixture_path}", path: fixture_path).universe }
|
8
|
+
|
9
|
+
context "with cookbooks in ./" do
|
10
|
+
let(:fixture) { "cookbook-path" }
|
11
|
+
|
12
|
+
it "returns the correct universe" do
|
13
|
+
expect(subject.size).to eq 1
|
14
|
+
expect(subject[0].name).to eq "jenkins-config"
|
15
|
+
expect(subject[0].version).to eq "0.1.0"
|
16
|
+
expect(subject[0].dependencies).to eq "jenkins" => "~> 2.0"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with cookbooks in cookbooks/" do
|
21
|
+
let(:fixture) { "complex-cookbook-path" }
|
22
|
+
|
23
|
+
it "returns the correct universe" do
|
24
|
+
expect(subject.size).to eq 3
|
25
|
+
expect(subject[0].name).to eq "app"
|
26
|
+
expect(subject[0].version).to eq "1.2.3"
|
27
|
+
expect(subject[0].dependencies).to eq({})
|
28
|
+
expect(subject[1].name).to eq "jenkins"
|
29
|
+
expect(subject[1].version).to eq "2.0.1"
|
30
|
+
expect(subject[1].dependencies).to eq({})
|
31
|
+
expect(subject[2].name).to eq "jenkins-config"
|
32
|
+
expect(subject[2].version).to eq "0.1.0"
|
33
|
+
expect(subject[2].dependencies).to eq "jenkins" => "~> 2.0"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,24 +1,23 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Berkshelf
|
4
4
|
describe Cli do
|
5
5
|
let(:subject) { described_class.new }
|
6
|
-
let(:berksfile) { double(
|
7
|
-
let(:cookbooks) { [
|
6
|
+
let(:berksfile) { double("Berksfile") }
|
7
|
+
let(:cookbooks) { ["mysql"] }
|
8
8
|
|
9
9
|
before do
|
10
10
|
allow(Berksfile).to receive(:from_options).and_return(berksfile)
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
13
|
+
describe "#upload" do
|
14
|
+
it "calls to upload with params if passed in cli" do
|
15
15
|
expect(berksfile).to receive(:upload).with(cookbooks,
|
16
|
-
include(skip_syntax_check: true, freeze: false)
|
17
|
-
)
|
16
|
+
include(skip_syntax_check: true, freeze: false))
|
18
17
|
|
19
18
|
subject.options[:skip_syntax_check] = true
|
20
19
|
subject.options[:no_freeze] = true
|
21
|
-
subject.upload(
|
20
|
+
subject.upload("mysql")
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|