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,15 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::Resolver::Graph, :not_supported_on_windows do
|
4
|
+
let(:berksfile) { double("Berksfile", filepath: "/test/Berksfile") }
|
4
5
|
subject { described_class.new }
|
5
6
|
|
6
7
|
describe "#populate" do
|
7
|
-
let(:sources) { Berkshelf::Source.new("http://
|
8
|
+
let(:sources) { Berkshelf::Source.new(berksfile, "http://supermarket.getchef.com") }
|
8
9
|
|
9
10
|
before do
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
body_response = %q{{"ruby":{"1.0.0":{"endpoint_priority":0,"platforms":{},"dependencies":{"elixir":">= 0.1.0"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"},"2.0.0":{"endpoint_priority":0,"platforms":{},"dependencies":{},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}},"elixir":{"1.0.0":{"endpoint_priority":0,"platforms":{},"dependencies":{},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}}}}
|
12
|
+
stub_request(:get, "http://supermarket.getchef.com/universe")
|
13
|
+
.to_return(status: 200, body: body_response, headers: { "Content-Type" => "application/json; charset=utf-8" })
|
13
14
|
end
|
14
15
|
|
15
16
|
it "adds each dependency to the graph" do
|
@@ -24,11 +25,12 @@ describe Berkshelf::Resolver::Graph, :not_supported_on_windows do
|
|
24
25
|
end
|
25
26
|
|
26
27
|
describe "#universe" do
|
27
|
-
let(:sources) { Berkshelf::Source.new("http://
|
28
|
+
let(:sources) { Berkshelf::Source.new(berksfile, "http://supermarket.getchef.com") }
|
28
29
|
|
29
30
|
before do
|
30
|
-
|
31
|
-
|
31
|
+
body_response = %q{{"ruby":{"1.0.0":{"endpoint_priority":0,"platforms":{},"dependencies":{},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}},"elixir":{"1.0.0":{"endpoint_priority":0,"platforms":{},"dependencies":{},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}}}}
|
32
|
+
stub_request(:get, "http://supermarket.getchef.com/universe")
|
33
|
+
.to_return(status: 200, body: body_response, headers: { "Content-Type" => "application/json; charset=utf-8" })
|
32
34
|
end
|
33
35
|
|
34
36
|
it "returns an array of APIClient::RemoteCookbook" do
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::Resolver do
|
4
|
-
let(:berksfile) { double(
|
4
|
+
let(:berksfile) { double("berksfile") }
|
5
5
|
let(:demand) { Berkshelf::Dependency.new(berksfile, "mysql", constraint: "= 1.2.4") }
|
6
6
|
|
7
7
|
before(:each) do
|
@@ -11,7 +11,7 @@ describe Berkshelf::Resolver do
|
|
11
11
|
|
12
12
|
describe "ClassMethods" do
|
13
13
|
describe "::initialize" do
|
14
|
-
it
|
14
|
+
it "adds the specified dependencies to the dependencies hash" do
|
15
15
|
resolver = described_class.new(berksfile, demand)
|
16
16
|
expect(resolver).to have_demand(demand)
|
17
17
|
end
|
@@ -21,17 +21,17 @@ describe Berkshelf::Resolver do
|
|
21
21
|
subject { Berkshelf::Resolver.new(berksfile) }
|
22
22
|
|
23
23
|
describe "#add_demand" do
|
24
|
-
it
|
24
|
+
it "adds the demand to the instance of resolver" do
|
25
25
|
subject.add_demand(demand)
|
26
26
|
expect(subject.demands).to include(demand)
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it "raises a DuplicateDemand exception if a demand of the same name is added" do
|
30
30
|
expect(subject).to receive(:has_demand?).with(demand).and_return(true)
|
31
31
|
|
32
|
-
expect
|
32
|
+
expect do
|
33
33
|
subject.add_demand(demand)
|
34
|
-
|
34
|
+
end.to raise_error(Berkshelf::DuplicateDemand)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -44,44 +44,44 @@ describe Berkshelf::Resolver do
|
|
44
44
|
describe "#get_demand" do
|
45
45
|
before { subject.add_demand(demand) }
|
46
46
|
|
47
|
-
context
|
48
|
-
it
|
47
|
+
context "given a string representation of the demand to retrieve" do
|
48
|
+
it "returns a Berkshelf::Dependency of the same name" do
|
49
49
|
expect(subject.get_demand(demand.name)).to eq(demand)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
54
|
+
describe "#has_demand?" do
|
55
55
|
before { subject.add_demand(demand) }
|
56
56
|
|
57
|
-
it
|
57
|
+
it "returns true if the demand exists" do
|
58
58
|
expect(subject.has_demand?(demand.name)).to be(true)
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
62
|
-
expect(subject.has_demand?(
|
61
|
+
it "returns false if the demand does not exist" do
|
62
|
+
expect(subject.has_demand?("non-existent")).to be(false)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
describe "#resolve" do
|
67
|
-
describe
|
67
|
+
describe "given a missing required solver" do
|
68
68
|
before do
|
69
69
|
allow(berksfile).to receive(:required_solver).and_return(:xyzzy)
|
70
70
|
allow(berksfile).to receive(:preferred_solver).and_return(nil)
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
73
|
+
it "should raise an exception about missing required resolver :xyzzy" do
|
74
74
|
expect { subject.compute_solver_engine(berksfile) }.to raise_error(/Engine `xyzzy` is not supported/)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
describe
|
78
|
+
describe "given a missing preferred solver" do
|
79
79
|
before do
|
80
80
|
allow(berksfile).to receive(:required_solver).and_return(nil)
|
81
81
|
allow(berksfile).to receive(:preferred_solver).and_return(:xyzzy)
|
82
82
|
end
|
83
83
|
|
84
|
-
it
|
84
|
+
it "should not raise an exception about missing preferred resolver :xyzzy" do
|
85
85
|
expect { subject.compute_solver_engine(berksfile) }.not_to raise_error
|
86
86
|
end
|
87
87
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "chef/cookbook_manifest"
|
3
|
+
|
4
|
+
describe Berkshelf::RidleyCompat do
|
5
|
+
let(:opts) { {} }
|
6
|
+
|
7
|
+
subject { described_class.new(**opts) }
|
8
|
+
|
9
|
+
context "default" do
|
10
|
+
it "has a cookbook version_class" do
|
11
|
+
expect(subject.options).to have_key(:version_class)
|
12
|
+
expect(subject.options[:version_class])
|
13
|
+
.to eq(Chef::CookbookManifestVersions)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Berkshelf
|
4
4
|
describe Shell do
|
5
|
-
let(:stdout) { double(
|
6
|
-
let(:stderr) { double(
|
5
|
+
let(:stdout) { double("stdout", tty?: true) }
|
6
|
+
let(:stderr) { double("stderr") }
|
7
7
|
|
8
8
|
before do
|
9
9
|
allow_any_instance_of(described_class).to receive(:stdout)
|
@@ -13,119 +13,119 @@ module Berkshelf
|
|
13
13
|
.and_return(stderr)
|
14
14
|
end
|
15
15
|
|
16
|
-
describe
|
17
|
-
it
|
16
|
+
describe "#mute!" do
|
17
|
+
it "sets @mute to true" do
|
18
18
|
subject.mute!
|
19
19
|
expect(subject.instance_variable_get(:@mute)).to be(true)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
24
|
-
it
|
23
|
+
describe "#unmute!" do
|
24
|
+
it "sets @mute to false" do
|
25
25
|
subject.unmute!
|
26
26
|
expect(subject.instance_variable_get(:@mute)).to be(false)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe
|
31
|
-
context
|
30
|
+
describe "#say" do
|
31
|
+
context "when quiet?" do
|
32
32
|
before do
|
33
33
|
allow(subject).to receive(:quiet?).and_return(true)
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it "does not output anything", :not_supported_on_windows do
|
37
37
|
expect(stdout).to_not receive(:print)
|
38
38
|
expect(stdout).to_not receive(:puts)
|
39
|
-
subject.say
|
39
|
+
subject.say "message"
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
context
|
43
|
+
context "with not quiet?" do
|
44
44
|
before do
|
45
45
|
allow(subject).to receive(:quiet?).and_return(false)
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it "prints to stdout" do
|
49
49
|
expect(stdout).to receive(:print).once
|
50
50
|
expect(stdout).to receive(:flush).once
|
51
|
-
subject.say
|
51
|
+
subject.say "message"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
describe
|
57
|
-
context
|
56
|
+
describe "#say_status" do
|
57
|
+
context "when quiet?" do
|
58
58
|
before do
|
59
59
|
allow(subject).to receive(:quiet?).and_return(true)
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
62
|
+
it "does not output anything" do
|
63
63
|
expect(stdout).to_not receive(:print)
|
64
64
|
expect(stdout).to_not receive(:puts)
|
65
|
-
subject.say_status 5,
|
65
|
+
subject.say_status 5, "message"
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
context
|
69
|
+
context "with not quiet?" do
|
70
70
|
before do
|
71
71
|
allow(subject).to receive(:quiet?).and_return(false)
|
72
72
|
end
|
73
73
|
|
74
|
-
it
|
74
|
+
it "prints to stdout" do
|
75
75
|
expect(stdout).to receive(:print).once
|
76
76
|
expect(stdout).to receive(:flush).once
|
77
|
-
subject.say_status 5,
|
77
|
+
subject.say_status 5, "message"
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
describe
|
83
|
-
context
|
82
|
+
describe "#warn" do
|
83
|
+
context "when quiet?" do
|
84
84
|
before do
|
85
85
|
allow(subject).to receive(:quiet?).and_return(true)
|
86
86
|
end
|
87
87
|
|
88
|
-
it
|
88
|
+
it "does not output anything" do
|
89
89
|
expect(stdout).to_not receive(:print)
|
90
90
|
expect(stdout).to_not receive(:puts)
|
91
|
-
subject.warn
|
91
|
+
subject.warn "warning"
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
context
|
95
|
+
context "with not quiet?" do
|
96
96
|
before do
|
97
97
|
allow(subject).to receive(:quiet?).and_return(false)
|
98
98
|
end
|
99
99
|
|
100
|
-
it
|
100
|
+
it "calls #say with yellow coloring" do
|
101
101
|
expect(stdout).to receive(:print).once
|
102
102
|
expect(stdout).to receive(:flush).once
|
103
|
-
subject.warn
|
103
|
+
subject.warn "warning"
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
context
|
109
|
-
context
|
108
|
+
context "#error" do
|
109
|
+
context "when quiet?" do
|
110
110
|
before do
|
111
111
|
allow(subject).to receive(:quiet?).and_return(true)
|
112
112
|
end
|
113
113
|
|
114
114
|
it "outputs an error message", :not_supported_on_windows do
|
115
115
|
expect(stderr).to receive(:puts)
|
116
|
-
subject.error
|
116
|
+
subject.error "error!"
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
context
|
120
|
+
context "with not quiet?" do
|
121
121
|
before do
|
122
122
|
allow(subject).to receive(:quiet?).and_return(false)
|
123
123
|
end
|
124
124
|
|
125
|
-
it
|
125
|
+
it "prints to stderr" do
|
126
126
|
expect(stderr).to receive(:puts)
|
127
127
|
.with(windows? ? "error!" : "\e[31merror!\e[0m")
|
128
|
-
subject.error
|
128
|
+
subject.error "error!"
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
@@ -1,56 +1,222 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Berkshelf
|
4
4
|
describe Source do
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
let(:berksfile) { double("Berksfile", filepath: "/test/Berksfile") }
|
6
|
+
let(:arguments) { [] }
|
7
|
+
let(:kwargs) { {} }
|
8
|
+
let(:config) { Config.new }
|
9
|
+
subject(:instance) { described_class.new(berksfile, *arguments, **kwargs) }
|
10
|
+
before do
|
11
|
+
allow(Berkshelf::Config).to receive(:instance).and_return(config)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#type" do
|
15
|
+
subject { instance.type }
|
16
|
+
|
17
|
+
context "with a string argument" do
|
18
|
+
let(:arguments) { ["https://example.com"] }
|
19
|
+
it { is_expected.to eq :supermarket }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with a string argument and options" do
|
23
|
+
let(:arguments) { ["https://example.com" ] }
|
24
|
+
let(:kwargs) { { key: "value" } }
|
25
|
+
it { is_expected.to eq :supermarket }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with a symbol argument" do
|
29
|
+
let(:arguments) { [:chef_server] }
|
30
|
+
it { is_expected.to eq :chef_server }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with a symbol argument and options" do
|
34
|
+
let(:arguments) { [:chef_server ] }
|
35
|
+
let(:kwargs) { { key: "value" } }
|
36
|
+
it { is_expected.to eq :chef_server }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "with a hash argument" do
|
40
|
+
let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" }] }
|
41
|
+
it { is_expected.to eq :artifactory }
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with a hash argument and connected options" do
|
45
|
+
let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual", key: "value" }] }
|
46
|
+
it { is_expected.to eq :artifactory }
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with a hash argument and disconnected options" do
|
50
|
+
let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" }] }
|
51
|
+
let(:kwargs) { { key: "value" } }
|
52
|
+
it { is_expected.to eq :artifactory }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#uri" do
|
57
|
+
subject { instance.uri.to_s }
|
58
|
+
|
59
|
+
context "with a string argument" do
|
60
|
+
let(:arguments) { ["https://example.com"] }
|
61
|
+
it { is_expected.to eq "https://example.com" }
|
62
|
+
end
|
63
|
+
|
64
|
+
context "with a string argument and options" do
|
65
|
+
let(:arguments) { ["https://example.com" ] }
|
66
|
+
let(:kwargs) { { key: "value" } }
|
67
|
+
it { is_expected.to eq "https://example.com" }
|
68
|
+
end
|
69
|
+
|
70
|
+
context "with a symbol argument" do
|
71
|
+
let(:arguments) { [:chef_server] }
|
72
|
+
before { config.chef.chef_server_url = "https://chefserver/" }
|
73
|
+
it { is_expected.to eq "https://chefserver/" }
|
74
|
+
end
|
75
|
+
|
76
|
+
context "with a symbol argument and options" do
|
77
|
+
let(:arguments) { [:chef_server] }
|
78
|
+
let(:kwargs) { { key: "value" } }
|
79
|
+
before { config.chef.chef_server_url = "https://chefserver/" }
|
80
|
+
it { is_expected.to eq "https://chefserver/" }
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with a hash argument" do
|
84
|
+
let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" }] }
|
85
|
+
it { is_expected.to eq "https://example.com/api/chef/chef-virtual" }
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with a hash argument and connected options" do
|
89
|
+
let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual", key: "value" }] }
|
90
|
+
it { is_expected.to eq "https://example.com/api/chef/chef-virtual" }
|
91
|
+
end
|
92
|
+
|
93
|
+
context "with a hash argument and disconnected options" do
|
94
|
+
let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" } ] }
|
95
|
+
let(:kwargs) { { key: "value" } }
|
96
|
+
it { is_expected.to eq "https://example.com/api/chef/chef-virtual" }
|
97
|
+
end
|
98
|
+
|
99
|
+
context "with an invalid URI" do
|
100
|
+
let(:arguments) { ["ftp://example.com"] }
|
101
|
+
it { expect { subject }.to raise_error InvalidSourceURI }
|
102
|
+
end
|
103
|
+
|
104
|
+
context "with a chef_repo source" do
|
105
|
+
let(:arguments) { [{ chef_repo: "." }] }
|
106
|
+
it { is_expected.to eq(windows? ? "file://D/test" : "file:///test") }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#options" do
|
111
|
+
subject { instance.options }
|
112
|
+
|
113
|
+
context "with a string argument" do
|
114
|
+
let(:arguments) { ["https://example.com"] }
|
115
|
+
|
116
|
+
it { is_expected.to be_a(Hash) }
|
117
|
+
# Check all baseline values.
|
118
|
+
its([:timeout]) { is_expected.to eq 30 }
|
119
|
+
its([:open_timeout]) { is_expected.to eq 3 }
|
120
|
+
its(%i{ssl verify}) { is_expected.to be true }
|
121
|
+
its(%i{ssl ca_file}) { is_expected.to be_nil }
|
122
|
+
its(%i{ssl ca_path}) { is_expected.to be_nil }
|
123
|
+
its(%i{ssl client_cert}) { is_expected.to be_nil }
|
124
|
+
its(%i{ssl client_key}) { is_expected.to be_nil }
|
125
|
+
its(%i{ssl cert_store}) { is_expected.to be_a(OpenSSL::X509::Store) }
|
126
|
+
end
|
127
|
+
|
128
|
+
context "with a string argument and options" do
|
129
|
+
let(:arguments) { ["https://example.com"] }
|
130
|
+
let(:kwargs) { { key: "value" } }
|
131
|
+
its([:key]) { is_expected.to eq "value" }
|
132
|
+
end
|
133
|
+
|
134
|
+
context "with a symbol argument" do
|
135
|
+
let(:arguments) { [:chef_server] }
|
136
|
+
it { is_expected.to be_a(Hash) }
|
137
|
+
end
|
138
|
+
|
139
|
+
context "with a symbol argument and options" do
|
140
|
+
let(:arguments) { [:chef_server] }
|
141
|
+
let(:kwargs) { { key: "value" } }
|
142
|
+
its([:key]) { is_expected.to eq "value" }
|
143
|
+
end
|
144
|
+
|
145
|
+
context "with a hash argument" do
|
146
|
+
let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" }] }
|
147
|
+
it { is_expected.to be_a(Hash) }
|
148
|
+
end
|
149
|
+
|
150
|
+
context "with a hash argument and connected options" do
|
151
|
+
let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual", key: "value" }] }
|
152
|
+
its([:key]) { is_expected.to eq "value" }
|
153
|
+
end
|
154
|
+
|
155
|
+
context "with a hash argument and disconnected options" do
|
156
|
+
let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" } ] }
|
157
|
+
let(:kwargs) { { key: "value" } }
|
158
|
+
its([:key]) { is_expected.to eq "value" }
|
159
|
+
end
|
160
|
+
|
161
|
+
context "with an artifactory source and the API key in the Chef config" do
|
162
|
+
let(:arguments) { [{ artifactory: "https://example.com/api/chef/chef-virtual" }] }
|
163
|
+
before { config.chef.artifactory_api_key = "secret" }
|
164
|
+
its([:api_key]) { is_expected.to eq "secret" }
|
165
|
+
end
|
166
|
+
|
167
|
+
context "with a chef_repo source" do
|
168
|
+
let(:arguments) { [{ chef_repo: "." }] }
|
169
|
+
its([:path]) { is_expected.to eq(windows? ? "D:/test" : "/test") }
|
170
|
+
end
|
171
|
+
end
|
8
172
|
|
9
173
|
describe "#==" do
|
10
174
|
it "is the same if the uri matches" do
|
11
|
-
first = described_class.new("http://localhost:8080")
|
12
|
-
other = described_class.new("http://localhost:8080")
|
175
|
+
first = described_class.new(berksfile, "http://localhost:8080")
|
176
|
+
other = described_class.new(berksfile, "http://localhost:8080")
|
13
177
|
|
14
178
|
expect(first).to eq(other)
|
15
179
|
end
|
16
180
|
|
17
181
|
it "is not the same if the uri is different" do
|
18
|
-
first = described_class.new("http://localhost:8089")
|
19
|
-
other = described_class.new("http://localhost:8080")
|
182
|
+
first = described_class.new(berksfile, "http://localhost:8089")
|
183
|
+
other = described_class.new(berksfile, "http://localhost:8080")
|
20
184
|
|
21
185
|
expect(first).to_not eq(other)
|
22
186
|
end
|
23
187
|
end
|
24
188
|
|
25
|
-
describe
|
26
|
-
it
|
27
|
-
instance = described_class.new(Berksfile::DEFAULT_API_URL)
|
189
|
+
describe ".default?" do
|
190
|
+
it "returns true when the source is the default" do
|
191
|
+
instance = described_class.new(berksfile, Berksfile::DEFAULT_API_URL)
|
28
192
|
expect(instance).to be_default
|
29
193
|
end
|
30
194
|
|
31
|
-
it
|
32
|
-
instance = described_class.new(
|
195
|
+
it "returns true when the scheme is different" do
|
196
|
+
instance = described_class.new(berksfile, "http://supermarket.chef.io")
|
33
197
|
expect(instance).to be_default
|
34
198
|
end
|
35
199
|
|
36
|
-
it
|
37
|
-
instance = described_class.new(
|
200
|
+
it "returns false when the source is not the default" do
|
201
|
+
instance = described_class.new(berksfile, "http://localhost:8080")
|
38
202
|
expect(instance).to_not be_default
|
39
203
|
end
|
40
204
|
end
|
41
205
|
|
42
206
|
describe "#search" do
|
43
|
-
let
|
44
|
-
|
45
|
-
APIClient::RemoteCookbook.new("cb1","1.0.
|
46
|
-
|
207
|
+
let(:cookbooks) do
|
208
|
+
[
|
209
|
+
APIClient::RemoteCookbook.new("cb1", "1.0.8"),
|
210
|
+
APIClient::RemoteCookbook.new("cb1", "1.0.22"),
|
211
|
+
]
|
212
|
+
end
|
47
213
|
|
48
214
|
before do
|
49
215
|
allow_any_instance_of(APIClient::Connection).to receive(:universe).and_return(cookbooks)
|
50
216
|
end
|
51
217
|
|
52
218
|
it "returns the latest version" do
|
53
|
-
instance = described_class.new(Berksfile::DEFAULT_API_URL)
|
219
|
+
instance = described_class.new(berksfile, Berksfile::DEFAULT_API_URL)
|
54
220
|
expect(instance.search("cb1")).to eq [cookbooks[1]]
|
55
221
|
end
|
56
222
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Berkshelf::SSLPolicy do
|
4
|
+
let(:self_signed_crt_path) { File.join(BERKS_SPEC_DATA, "trusted_certs") }
|
5
|
+
let(:self_signed_crt_path_windows_backslashes) { "C:/users/vagrant\\.chef\\trusted_certs" }
|
6
|
+
let(:self_signed_crt_path_windows_forwardslashes) { "C:/users/vagrant/.chef/trusted_certs" }
|
7
|
+
|
8
|
+
let(:chef_config) do
|
9
|
+
double(Berkshelf::ChefConfigCompat,
|
10
|
+
node_name: "fake-client",
|
11
|
+
client_key: "client-key",
|
12
|
+
chef_server_url: "http://configured-chef-server/",
|
13
|
+
validation_client_name: "validator",
|
14
|
+
validation_key: "validator.pem",
|
15
|
+
artifactory_api_key: "secret",
|
16
|
+
cookbook_copyright: "user",
|
17
|
+
cookbook_email: "user@example.com",
|
18
|
+
cookbook_license: "apachev2",
|
19
|
+
trusted_certs_dir: self_signed_crt_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:berkshelf_config) do
|
23
|
+
double(Berkshelf::Config,
|
24
|
+
ssl: double(verify: true),
|
25
|
+
chef: chef_config)
|
26
|
+
end
|
27
|
+
|
28
|
+
subject do
|
29
|
+
Berkshelf::SSLPolicy.new
|
30
|
+
end
|
31
|
+
|
32
|
+
before do
|
33
|
+
allow(Berkshelf).to receive(:config).and_return(berkshelf_config)
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#initialize" do
|
37
|
+
it "sets up the store" do
|
38
|
+
expect(subject.store.class).to be(OpenSSL::X509::Store)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "sets up custom certificates for chef" do
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#trusted_certs_dir" do
|
46
|
+
it "uses the trusted_certs_dir from Berkshelf config" do
|
47
|
+
expect(subject.trusted_certs_dir).to eq(self_signed_crt_path)
|
48
|
+
end
|
49
|
+
|
50
|
+
context "trusted_certs_dir in Berkshelf" do
|
51
|
+
|
52
|
+
context "config is not set" do
|
53
|
+
before { allow(chef_config).to receive_messages(trusted_certs_dir: nil) }
|
54
|
+
|
55
|
+
it "defaults to ~/.chef/trusted_certs" do
|
56
|
+
expect(subject.trusted_certs_dir).to eq(
|
57
|
+
File.join(ENV["HOME"], ".chef", "trusted_certs")
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "config is set but does not exist" do
|
63
|
+
before { allow(chef_config).to receive_messages(trusted_certs_dir: "/fake") }
|
64
|
+
|
65
|
+
it "defaults to ~/.chef/trusted_certs" do
|
66
|
+
expect(subject.trusted_certs_dir).to eq(
|
67
|
+
File.join(ENV["HOME"], ".chef", "trusted_certs")
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "config has Windows backslashes in trusted_certs_dir path" do
|
73
|
+
before do
|
74
|
+
allow(chef_config).to receive_messages(trusted_certs_dir: self_signed_crt_path_windows_backslashes)
|
75
|
+
allow(File).to receive(:exist?).with(self_signed_crt_path_windows_forwardslashes).and_return(true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "replaces the backslashes in trusted_certs_dir from Berkshelf config with forwardslashes" do
|
79
|
+
expect(subject.trusted_certs_dir).to eq(
|
80
|
+
self_signed_crt_path_windows_forwardslashes
|
81
|
+
)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|