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,88 +1,88 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::Dependency do
|
4
|
-
let(:cookbook_name) {
|
5
|
-
let(:berksfile) { double(
|
4
|
+
let(:cookbook_name) { "nginx" }
|
5
|
+
let(:berksfile) { double("berksfile", filepath: fixtures_path.join("Berksfile").to_s) }
|
6
6
|
|
7
7
|
describe "ClassMethods" do
|
8
8
|
describe "::new" do
|
9
9
|
let(:source) { described_class.new(berksfile, cookbook_name) }
|
10
10
|
|
11
|
-
context
|
12
|
-
it
|
11
|
+
context "given no location key (i.e. :git, :path, :site)" do
|
12
|
+
it "sets a nil valie for location" do
|
13
13
|
expect(source.location).to be_nil
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
context
|
18
|
-
it
|
17
|
+
context "given no value for :locked_version" do
|
18
|
+
it "returns a wildcard match for any version" do
|
19
19
|
expect(source.locked_version).to be_nil
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
context
|
24
|
-
it
|
25
|
-
expect(source.version_constraint.to_s).to eq(
|
23
|
+
context "given no value for :constraint" do
|
24
|
+
it "returns a wildcard match for any version" do
|
25
|
+
expect(source.version_constraint.to_s).to eq(">= 0.0.0")
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context
|
30
|
-
let(:source) { described_class.new(berksfile, cookbook_name, constraint:
|
29
|
+
context "given a value for :constraint" do
|
30
|
+
let(:source) { described_class.new(berksfile, cookbook_name, constraint: "~> 1.0.84") }
|
31
31
|
|
32
|
-
it
|
33
|
-
expect(source.version_constraint.to_s).to eq(
|
32
|
+
it "returns a Semverse::Constraint for the given version for version_constraint" do
|
33
|
+
expect(source.version_constraint.to_s).to eq("~> 1.0.84")
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
context
|
38
|
-
let(:url) {
|
37
|
+
context "given a location key :git" do
|
38
|
+
let(:url) { "https://url_to_git" }
|
39
39
|
let(:source) { described_class.new(berksfile, cookbook_name, git: url) }
|
40
40
|
|
41
|
-
it
|
41
|
+
it "initializes a GitLocation for location" do
|
42
42
|
expect(source.location).to be_a(Berkshelf::GitLocation)
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it "points to the given Git URL" do
|
46
46
|
expect(source.location.uri).to eq(url)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
context
|
51
|
-
context
|
52
|
-
let(:path) { fixtures_path.join(
|
50
|
+
context "given a location key :path" do
|
51
|
+
context "given a value for path that contains a cookbook" do
|
52
|
+
let(:path) { fixtures_path.join("cookbooks", "example_cookbook").to_s }
|
53
53
|
let(:location) { described_class.new(berksfile, cookbook_name, path: path).location }
|
54
54
|
|
55
|
-
it
|
55
|
+
it "initializes a PathLocation for location" do
|
56
56
|
expect(location).to be_a(Berkshelf::PathLocation)
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
59
|
+
it "points to the specified path" do
|
60
60
|
expect(location.options[:path]).to eq(path)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
context
|
64
|
+
context "given a group option containing a single group" do
|
65
65
|
let(:group) { :production }
|
66
66
|
let(:source) { described_class.new(berksfile, cookbook_name, group: group) }
|
67
67
|
|
68
|
-
it
|
68
|
+
it "assigns the single group to the groups attribute" do
|
69
69
|
expect(source.groups).to include(group)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
context
|
74
|
-
let(:groups) {
|
73
|
+
context "given a group option containing an array of groups" do
|
74
|
+
let(:groups) { %i{development test} }
|
75
75
|
let(:source) { described_class.new(berksfile, cookbook_name, group: groups) }
|
76
76
|
|
77
|
-
it
|
77
|
+
it "assigns all the groups to the group attribute" do
|
78
78
|
expect(source.groups).to eq(groups)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
context
|
82
|
+
context "given no group option" do
|
83
83
|
let(:source) { described_class.new(berksfile, cookbook_name) }
|
84
84
|
|
85
|
-
it
|
85
|
+
it "has the default group assigned" do
|
86
86
|
expect(source.groups).to include(:default)
|
87
87
|
end
|
88
88
|
end
|
@@ -92,40 +92,40 @@ describe Berkshelf::Dependency do
|
|
92
92
|
|
93
93
|
subject { described_class.new(berksfile, cookbook_name) }
|
94
94
|
|
95
|
-
describe
|
96
|
-
it
|
97
|
-
subject.add_group
|
98
|
-
expect(subject.groups).to eq(
|
95
|
+
describe "#add_group" do
|
96
|
+
it "stores strings as symbols" do
|
97
|
+
subject.add_group "foo"
|
98
|
+
expect(subject.groups).to eq(%i{default foo})
|
99
99
|
end
|
100
100
|
|
101
|
-
it
|
102
|
-
subject.add_group
|
103
|
-
subject.add_group
|
101
|
+
it "does not store duplicate groups" do
|
102
|
+
subject.add_group "bar"
|
103
|
+
subject.add_group "bar"
|
104
104
|
subject.add_group :bar
|
105
|
-
expect(subject.groups).to eq(
|
105
|
+
expect(subject.groups).to eq(%i{default bar})
|
106
106
|
end
|
107
107
|
|
108
|
-
it
|
109
|
-
subject.add_group
|
110
|
-
expect(subject.groups).to eq(
|
108
|
+
it "adds multiple groups" do
|
109
|
+
subject.add_group "baz", "quux"
|
110
|
+
expect(subject.groups).to eq(%i{default baz quux})
|
111
111
|
end
|
112
112
|
|
113
|
-
it
|
114
|
-
subject.add_group
|
115
|
-
expect(subject.groups).to eq(
|
113
|
+
it "handles multiple groups as an array" do
|
114
|
+
subject.add_group %w{baz quux}
|
115
|
+
expect(subject.groups).to eq(%i{default baz quux})
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
119
|
describe "#cached_cookbook"
|
120
120
|
describe "#download"
|
121
121
|
|
122
|
-
describe
|
123
|
-
it
|
124
|
-
allow(subject).to receive(:cached_cookbook) { double(
|
122
|
+
describe "#installed?" do
|
123
|
+
it "returns true if self.cached_cookbook is not nil" do
|
124
|
+
allow(subject).to receive(:cached_cookbook) { double("cb") }
|
125
125
|
expect(subject.installed?).to be(true)
|
126
126
|
end
|
127
127
|
|
128
|
-
it
|
128
|
+
it "returns false if self.cached_cookbook is nil" do
|
129
129
|
allow(subject).to receive(:cached_cookbook) { nil }
|
130
130
|
expect(subject.installed?).to be(false)
|
131
131
|
end
|
@@ -1,43 +1,200 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#try_download" do
|
12
|
-
let(:remote_cookbook) { double('remote-cookbook') }
|
13
|
-
let(:source) do
|
14
|
-
source = double('source')
|
15
|
-
allow(source).to receive(:cookbook) { remote_cookbook }
|
16
|
-
source
|
17
|
-
end
|
18
|
-
let(:name) { "fake" }
|
19
|
-
let(:version) { "1.0.0" }
|
20
|
-
|
21
|
-
it "supports the 'opscode' location type" do
|
22
|
-
allow(remote_cookbook).to receive(:location_type) { :opscode }
|
23
|
-
allow(remote_cookbook).to receive(:location_path) { "http://api.opscode.com" }
|
24
|
-
rest = double('community-rest')
|
25
|
-
expect(Berkshelf::CommunityREST).to receive(:new).with("http://api.opscode.com") { rest }
|
26
|
-
expect(rest).to receive(:download).with(name, version)
|
27
|
-
subject.try_download(source, name, version)
|
3
|
+
module Berkshelf
|
4
|
+
describe Downloader do
|
5
|
+
let(:berksfile) do
|
6
|
+
double(Berksfile,
|
7
|
+
lockfile: lockfile,
|
8
|
+
dependencies: [])
|
28
9
|
end
|
29
10
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
rest = double('community-rest')
|
34
|
-
expect(Berkshelf::CommunityREST).to receive(:new).with("http://api.supermarket.com") { rest }
|
35
|
-
expect(rest).to receive(:download).with(name, version)
|
36
|
-
subject.try_download(source, name, version)
|
11
|
+
let(:lockfile) do
|
12
|
+
double(Lockfile,
|
13
|
+
graph: graph)
|
37
14
|
end
|
38
15
|
|
39
|
-
|
16
|
+
let(:graph) { double(Lockfile::Graph, locks: {}) }
|
17
|
+
let(:self_signed_crt_path) { File.join(BERKS_SPEC_DATA, "trusted_certs") }
|
18
|
+
let(:self_signed_crt) { OpenSSL::X509::Certificate.new(IO.read("#{self_signed_crt_path}/example.crt")) }
|
19
|
+
let(:cert_store) { OpenSSL::X509::Store.new.add_cert(self_signed_crt) }
|
20
|
+
let(:ssl_policy) { double(SSLPolicy, store: cert_store) }
|
21
|
+
|
22
|
+
subject { described_class.new(berksfile) }
|
23
|
+
|
24
|
+
describe "#download" do
|
40
25
|
skip
|
41
26
|
end
|
27
|
+
|
28
|
+
describe "#try_download" do
|
29
|
+
let(:remote_cookbook) { double("remote-cookbook") }
|
30
|
+
let(:source) do
|
31
|
+
source = double("source")
|
32
|
+
allow(source).to receive(:cookbook) { remote_cookbook }
|
33
|
+
source
|
34
|
+
end
|
35
|
+
let(:name) { "fake" }
|
36
|
+
let(:version) { "1.0.0" }
|
37
|
+
|
38
|
+
it "supports the 'opscode' location type" do
|
39
|
+
allow(source).to receive(:type) { :supermarket }
|
40
|
+
allow(source).to receive(:options) { { ssl: {} } }
|
41
|
+
allow(remote_cookbook).to receive(:location_type) { :opscode }
|
42
|
+
allow(remote_cookbook).to receive(:location_path) { "http://api.opscode.com" }
|
43
|
+
rest = double("community-rest")
|
44
|
+
expect(CommunityREST).to receive(:new).with("http://api.opscode.com", { ssl: {} }) { rest }
|
45
|
+
expect(rest).to receive(:download).with(name, version)
|
46
|
+
subject.try_download(source, name, version)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "supports the 'supermarket' location type" do
|
50
|
+
allow(source).to receive(:type) { :supermarket }
|
51
|
+
allow(source).to receive(:options) { { ssl: {} } }
|
52
|
+
allow(remote_cookbook).to receive(:location_type) { :supermarket }
|
53
|
+
allow(remote_cookbook).to receive(:location_path) { "http://api.supermarket.com" }
|
54
|
+
rest = double("community-rest")
|
55
|
+
expect(CommunityREST).to receive(:new).with("http://api.supermarket.com", { ssl: {} }) { rest }
|
56
|
+
expect(rest).to receive(:download).with(name, version)
|
57
|
+
subject.try_download(source, name, version)
|
58
|
+
end
|
59
|
+
|
60
|
+
context "supports location paths" do
|
61
|
+
before(:each) do
|
62
|
+
allow(source).to receive(:type) { :supermarket }
|
63
|
+
allow(source).to receive(:options) { { ssl: {} } }
|
64
|
+
allow(source).to receive(:uri_string).and_return("http://localhost:8081/repository/chef-proxy")
|
65
|
+
allow(remote_cookbook).to receive(:location_type) { :opscode }
|
66
|
+
end
|
67
|
+
|
68
|
+
let(:rest) { double("community-rest") }
|
69
|
+
|
70
|
+
it "that are relative and prepends the source URI for the download" do
|
71
|
+
allow(remote_cookbook).to receive(:location_path) { "/api/v1" }
|
72
|
+
expect(CommunityREST).to receive(:new).with("http://localhost:8081/repository/chef-proxy/api/v1", { ssl: {} }) { rest }
|
73
|
+
expect(rest).to receive(:download).with(name, version)
|
74
|
+
subject.try_download(source, name, version)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "that are absolute and uses the given absolute URI" do
|
78
|
+
allow(remote_cookbook).to receive(:location_path) { "http://localhost:8081/repository/chef-proxy/api/v1" }
|
79
|
+
expect(CommunityREST).to receive(:new).with("http://localhost:8081/repository/chef-proxy/api/v1", { ssl: {} }) { rest }
|
80
|
+
expect(rest).to receive(:download).with(name, version)
|
81
|
+
subject.try_download(source, name, version)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "with an artifactory source" do
|
86
|
+
it "supports the 'opscode' location type" do
|
87
|
+
allow(source).to receive(:type) { :artifactory }
|
88
|
+
allow(source).to receive(:options) { { api_key: "secret", ssl: {} } }
|
89
|
+
allow(remote_cookbook).to receive(:location_type) { :opscode }
|
90
|
+
allow(remote_cookbook).to receive(:location_path) { "http://artifactory/" }
|
91
|
+
rest = double("community-rest")
|
92
|
+
expect(CommunityREST).to receive(:new).with("http://artifactory/", { ssl: {}, headers: { "X-Jfrog-Art-Api" => "secret" } }) { rest }
|
93
|
+
expect(rest).to receive(:download).with(name, version)
|
94
|
+
subject.try_download(source, name, version)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "supports the 'supermarket' location type" do
|
98
|
+
allow(source).to receive(:type) { :artifactory }
|
99
|
+
allow(source).to receive(:options) { { api_key: "secret", ssl: {} } }
|
100
|
+
allow(remote_cookbook).to receive(:location_type) { :supermarket }
|
101
|
+
allow(remote_cookbook).to receive(:location_path) { "http://artifactory/" }
|
102
|
+
rest = double("community-rest")
|
103
|
+
expect(CommunityREST).to receive(:new).with("http://artifactory/", { ssl: {}, headers: { "X-Jfrog-Art-Api" => "secret" } }) { rest }
|
104
|
+
expect(rest).to receive(:download).with(name, version)
|
105
|
+
subject.try_download(source, name, version)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "chef_server location type" do
|
110
|
+
let(:chef_server_url) { "http://configured-chef-server/" }
|
111
|
+
let(:ridley_client) do
|
112
|
+
instance_double(Berkshelf::RidleyCompat)
|
113
|
+
end
|
114
|
+
let(:chef_config) do
|
115
|
+
double(Berkshelf::ChefConfigCompat,
|
116
|
+
node_name: "fake-client",
|
117
|
+
client_key: "client-key",
|
118
|
+
chef_server_url: chef_server_url,
|
119
|
+
validation_client_name: "validator",
|
120
|
+
validation_key: "validator.pem",
|
121
|
+
artifactory_api_key: "secret",
|
122
|
+
cookbook_copyright: "user",
|
123
|
+
cookbook_email: "user@example.com",
|
124
|
+
cookbook_license: "apachev2",
|
125
|
+
trusted_certs_dir: self_signed_crt_path)
|
126
|
+
end
|
127
|
+
|
128
|
+
let(:berkshelf_config) do
|
129
|
+
double(Config,
|
130
|
+
ssl: double(verify: true),
|
131
|
+
chef: chef_config)
|
132
|
+
end
|
133
|
+
|
134
|
+
before do
|
135
|
+
allow(Berkshelf).to receive(:config).and_return(berkshelf_config)
|
136
|
+
allow(subject).to receive(:ssl_policy).and_return(ssl_policy)
|
137
|
+
allow(remote_cookbook).to receive(:location_type) { :chef_server }
|
138
|
+
allow(remote_cookbook).to receive(:location_path) { chef_server_url }
|
139
|
+
allow(source).to receive(:options) { { read_timeout: 30, open_timeout: 3, ssl: { verify: true, cert_store: cert_store } } }
|
140
|
+
end
|
141
|
+
|
142
|
+
it "uses the berkshelf config and provides a custom cert_store" do
|
143
|
+
credentials = {
|
144
|
+
server_url: chef_server_url,
|
145
|
+
client_name: chef_config.node_name,
|
146
|
+
client_key: chef_config.client_key,
|
147
|
+
ssl: {
|
148
|
+
verify: berkshelf_config.ssl.verify,
|
149
|
+
cert_store: cert_store,
|
150
|
+
},
|
151
|
+
}
|
152
|
+
expect(Berkshelf::RidleyCompat).to receive(:new_client).with(credentials) { ridley_client }
|
153
|
+
subject.try_download(source, name, version)
|
154
|
+
end
|
155
|
+
|
156
|
+
context "with a source option for client_name" do
|
157
|
+
before do
|
158
|
+
allow(source).to receive(:options) { { client_name: "other-client", read_timeout: 30, open_timeout: 3, ssl: { verify: true, cert_store: cert_store } } }
|
159
|
+
end
|
160
|
+
it "uses the override" do
|
161
|
+
credentials = {
|
162
|
+
server_url: chef_server_url,
|
163
|
+
client_name: "other-client",
|
164
|
+
client_key: chef_config.client_key,
|
165
|
+
ssl: {
|
166
|
+
verify: berkshelf_config.ssl.verify,
|
167
|
+
cert_store: cert_store,
|
168
|
+
},
|
169
|
+
}
|
170
|
+
expect(Berkshelf::RidleyCompat).to receive(:new_client).with(credentials) { ridley_client }
|
171
|
+
subject.try_download(source, name, version)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context "with a source option for client_key" do
|
176
|
+
before do
|
177
|
+
allow(source).to receive(:options) { { client_key: "other-key", read_timeout: 30, open_timeout: 3, ssl: { verify: true, cert_store: cert_store } } }
|
178
|
+
end
|
179
|
+
it "uses the override" do
|
180
|
+
credentials = {
|
181
|
+
server_url: chef_server_url,
|
182
|
+
client_name: chef_config.node_name,
|
183
|
+
client_key: "other-key",
|
184
|
+
ssl: {
|
185
|
+
verify: berkshelf_config.ssl.verify,
|
186
|
+
cert_store: cert_store,
|
187
|
+
},
|
188
|
+
}
|
189
|
+
expect(Berkshelf::RidleyCompat).to receive(:new_client).with(credentials) { ridley_client }
|
190
|
+
subject.try_download(source, name, version)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
it "supports the 'file_store' location type" do
|
196
|
+
skip
|
197
|
+
end
|
198
|
+
end
|
42
199
|
end
|
43
200
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::BerkshelfError do
|
4
4
|
skip
|
5
5
|
end
|
6
6
|
|
7
7
|
describe Berkshelf::CommunitySiteError do
|
8
|
-
let(:api_uri) {
|
9
|
-
let(:message) {
|
8
|
+
let(:api_uri) { "https://infra.as.code" }
|
9
|
+
let(:message) { "Cookbook name" }
|
10
10
|
|
11
11
|
subject { described_class.new(api_uri, message) }
|
12
12
|
|