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,21 +1,21 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::CommunityREST do
|
4
4
|
describe "ClassMethods" do
|
5
5
|
describe "::unpack" do
|
6
|
-
let(:target) {
|
7
|
-
let(:destination) {
|
8
|
-
let(:file) { double(
|
9
|
-
let(:gzip_reader) { double(
|
10
|
-
let(:archive) { double(
|
6
|
+
let(:target) { "/foo/bar" }
|
7
|
+
let(:destination) { "/destination/bar" }
|
8
|
+
let(:file) { double("file") }
|
9
|
+
let(:gzip_reader) { double("gzip_reader") }
|
10
|
+
let(:archive) { double("mixlib_archive") }
|
11
11
|
|
12
12
|
before do
|
13
|
-
allow(File).to receive(:open).with(target,
|
13
|
+
allow(File).to receive(:open).with(target, "rb").and_return(file)
|
14
14
|
allow(archive).to receive(:extract).with(destination)
|
15
15
|
allow(Mixlib::Archive).to receive(:new).with(target).and_return(archive)
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it "unpacks the tar" do
|
19
19
|
expect(::IO).to receive(:binread).with(target, 2).and_return([0x1F, 0x8B].pack("C*"))
|
20
20
|
expect(Mixlib::Archive).to receive(:new).with(target).and_return(archive)
|
21
21
|
expect(archive).to receive(:extract).with(destination)
|
@@ -25,38 +25,38 @@ describe Berkshelf::CommunityREST do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "::uri_escape_version" do
|
28
|
-
it
|
28
|
+
it "returns a string" do
|
29
29
|
expect(Berkshelf::CommunityREST.uri_escape_version(nil)).to be_a(String)
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
33
|
-
expect(Berkshelf::CommunityREST.uri_escape_version(
|
32
|
+
it "converts a version to it's underscored version" do
|
33
|
+
expect(Berkshelf::CommunityREST.uri_escape_version("1.1.2")).to eq("1_1_2")
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
expect(Berkshelf::CommunityREST.uri_escape_version(
|
36
|
+
it "works when the version has more than three points" do
|
37
|
+
expect(Berkshelf::CommunityREST.uri_escape_version("1.1.1.2")).to eq("1_1_1_2")
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
41
|
-
expect(Berkshelf::CommunityREST.uri_escape_version(
|
40
|
+
it "works when the version has less than three points" do
|
41
|
+
expect(Berkshelf::CommunityREST.uri_escape_version("1.2")).to eq("1_2")
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe "::version_from_uri" do
|
46
|
-
it
|
46
|
+
it "returns a string" do
|
47
47
|
expect(Berkshelf::CommunityREST.version_from_uri(nil)).to be_a(String)
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
51
|
-
expect(Berkshelf::CommunityREST.version_from_uri(
|
50
|
+
it "extracts the version from the URL" do
|
51
|
+
expect(Berkshelf::CommunityREST.version_from_uri("/api/v1/cookbooks/nginx/versions/1_1_2")).to eq("1.1.2")
|
52
52
|
end
|
53
53
|
|
54
|
-
it
|
55
|
-
expect(Berkshelf::CommunityREST.version_from_uri(
|
54
|
+
it "works when the version has more than three points" do
|
55
|
+
expect(Berkshelf::CommunityREST.version_from_uri("/api/v1/cookbooks/nginx/versions/1_1_1_2")).to eq("1.1.1.2")
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
59
|
-
expect(Berkshelf::CommunityREST.version_from_uri(
|
58
|
+
it "works when the version has less than three points" do
|
59
|
+
expect(Berkshelf::CommunityREST.version_from_uri("/api/v1/cookbooks/nginx/versions/1_2")).to eq("1.2")
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -64,161 +64,153 @@ describe Berkshelf::CommunityREST do
|
|
64
64
|
let(:api_uri) { Berkshelf::CommunityREST::V1_API }
|
65
65
|
subject { Berkshelf::CommunityREST.new(api_uri) }
|
66
66
|
|
67
|
-
describe
|
68
|
-
|
69
|
-
it 'includes follow_redirects to prevent 301 from community, stopping some cookbooks installing' do
|
70
|
-
expect(subject.builder.handlers).to include(Ridley::Middleware::FollowRedirects)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#download' do
|
76
|
-
let(:archive) { double('archive', path: '/foo/bar', unlink: true) }
|
67
|
+
describe "#download" do
|
68
|
+
let(:archive) { double("archive", path: "/foo/bar", unlink: true) }
|
77
69
|
|
78
70
|
before do
|
79
|
-
allow(subject).to receive(:stream).with(any_args
|
71
|
+
allow(subject).to receive(:stream).with(any_args).and_return(archive)
|
80
72
|
allow(Berkshelf::CommunityREST).to receive(:unpack)
|
81
|
-
.and_return(
|
73
|
+
.and_return("/some/path")
|
82
74
|
end
|
83
75
|
|
84
|
-
it
|
76
|
+
it "unpacks the archive" do
|
85
77
|
stub_request(:get, "#{api_uri}/cookbooks/bacon/versions/1_0_0").to_return(
|
86
78
|
status: 200,
|
87
79
|
body: '{ "cookbook": "/path/to/cookbook", "version": "1.0.0" }',
|
88
|
-
headers: {
|
80
|
+
headers: { "Content-Type" => "application/json" }
|
89
81
|
)
|
90
82
|
|
91
83
|
expect(Berkshelf::CommunityREST).to receive(:unpack)
|
92
|
-
.with(
|
93
|
-
.and_return(
|
84
|
+
.with("/foo/bar", String)
|
85
|
+
.and_return("/foo/nginx")
|
94
86
|
.once
|
95
87
|
expect(archive).to receive(:unlink).once
|
96
88
|
|
97
|
-
subject.download(
|
89
|
+
subject.download("bacon", "1.0.0")
|
98
90
|
end
|
99
91
|
end
|
100
92
|
|
101
|
-
describe
|
102
|
-
it
|
93
|
+
describe "#find" do
|
94
|
+
it "returns the cookbook and version information" do
|
103
95
|
stub_request(:get, "#{api_uri}/cookbooks/bacon/versions/1_0_0").to_return(
|
104
96
|
status: 200,
|
105
97
|
body: '{ "cookbook": "/path/to/cookbook", "version": "1.0.0" }',
|
106
|
-
headers: {
|
98
|
+
headers: { "Content-Type" => "application/json" }
|
107
99
|
)
|
108
100
|
|
109
|
-
result = subject.find(
|
101
|
+
result = subject.find("bacon", "1.0.0")
|
110
102
|
|
111
|
-
expect(result
|
112
|
-
expect(result
|
103
|
+
expect(result["cookbook"]).to eq("/path/to/cookbook")
|
104
|
+
expect(result["version"]).to eq("1.0.0")
|
113
105
|
end
|
114
106
|
|
115
|
-
it
|
107
|
+
it "raises a CookbookNotFound error on a 404 response for a non-existent cookbook" do
|
116
108
|
stub_request(:get, "#{api_uri}/cookbooks/not_real/versions/1_0_0").to_return(
|
117
109
|
status: 404,
|
118
|
-
body:
|
110
|
+
body: "Not Found"
|
119
111
|
)
|
120
112
|
|
121
|
-
expect
|
122
|
-
subject.find(
|
123
|
-
|
113
|
+
expect do
|
114
|
+
subject.find("not_real", "1.0.0")
|
115
|
+
end.to raise_error(Berkshelf::CookbookNotFound)
|
124
116
|
end
|
125
117
|
|
126
|
-
it
|
118
|
+
it "raises a CommunitySiteError error on any non 200 or 404 response" do
|
127
119
|
stub_request(:get, "#{api_uri}/cookbooks/not_real/versions/1_0_0").to_return(
|
128
120
|
status: 500,
|
129
|
-
body: nil
|
121
|
+
body: nil
|
130
122
|
)
|
131
123
|
|
132
|
-
expect
|
133
|
-
subject.find(
|
134
|
-
|
124
|
+
expect do
|
125
|
+
subject.find("not_real", "1.0.0")
|
126
|
+
end.to raise_error(Berkshelf::CommunitySiteError)
|
135
127
|
end
|
136
128
|
end
|
137
129
|
|
138
|
-
describe
|
139
|
-
it
|
130
|
+
describe "#latest_version" do
|
131
|
+
it "returns the version number of the latest version of the cookbook" do
|
140
132
|
stub_request(:get, "#{api_uri}/cookbooks/bacon").to_return(
|
141
133
|
status: 200,
|
142
134
|
body: '{ "latest_version": "1.0.0" }',
|
143
|
-
headers: {
|
135
|
+
headers: { "Content-Type" => "application/json" }
|
144
136
|
)
|
145
137
|
|
146
|
-
latest = subject.latest_version(
|
147
|
-
expect(latest).to eq(
|
138
|
+
latest = subject.latest_version("bacon")
|
139
|
+
expect(latest).to eq("1.0.0")
|
148
140
|
end
|
149
141
|
|
150
|
-
it
|
142
|
+
it "raises a CookbookNotFound error on a 404 response" do
|
151
143
|
stub_request(:get, "#{api_uri}/cookbooks/not_real").to_return(
|
152
144
|
status: 404,
|
153
|
-
body:
|
145
|
+
body: "Not Found"
|
154
146
|
)
|
155
147
|
|
156
|
-
expect
|
157
|
-
subject.latest_version(
|
158
|
-
|
148
|
+
expect do
|
149
|
+
subject.latest_version("not_real")
|
150
|
+
end.to raise_error(Berkshelf::CookbookNotFound)
|
159
151
|
end
|
160
152
|
|
161
|
-
it
|
153
|
+
it "raises a CommunitySiteError error on any non 200 or 404 response" do
|
162
154
|
stub_request(:get, "#{api_uri}/cookbooks/not_real").to_return(
|
163
155
|
status: 500,
|
164
|
-
body: nil
|
156
|
+
body: nil
|
165
157
|
)
|
166
158
|
|
167
|
-
expect
|
168
|
-
subject.latest_version(
|
169
|
-
|
159
|
+
expect do
|
160
|
+
subject.latest_version("not_real")
|
161
|
+
end.to raise_error(Berkshelf::CommunitySiteError)
|
170
162
|
end
|
171
163
|
end
|
172
164
|
|
173
|
-
describe
|
174
|
-
it
|
165
|
+
describe "#versions" do
|
166
|
+
it "returns an array containing an item for each version" do
|
175
167
|
stub_request(:get, "#{api_uri}/cookbooks/bacon").to_return(
|
176
168
|
status: 200,
|
177
169
|
body: '{ "versions": ["/bacon/versions/1_0_0", "/bacon/versions/2_0_0"] }',
|
178
|
-
headers: {
|
170
|
+
headers: { "Content-Type" => "application/json" }
|
179
171
|
)
|
180
172
|
|
181
|
-
versions = subject.versions(
|
173
|
+
versions = subject.versions("bacon")
|
182
174
|
expect(versions.size).to eq(2)
|
183
175
|
end
|
184
176
|
|
185
|
-
it
|
177
|
+
it "raises a CookbookNotFound error on a 404 response" do
|
186
178
|
stub_request(:get, "#{api_uri}/cookbooks/not_real").to_return(
|
187
179
|
status: 404,
|
188
|
-
body:
|
180
|
+
body: "Not Found"
|
189
181
|
)
|
190
182
|
|
191
|
-
expect
|
192
|
-
subject.versions(
|
193
|
-
|
183
|
+
expect do
|
184
|
+
subject.versions("not_real")
|
185
|
+
end.to raise_error(Berkshelf::CookbookNotFound)
|
194
186
|
end
|
195
187
|
|
196
|
-
it
|
188
|
+
it "raises a CommunitySiteError error on any non 200 or 404 response" do
|
197
189
|
stub_request(:get, "#{api_uri}/cookbooks/not_real").to_return(
|
198
190
|
status: 500,
|
199
|
-
body: nil
|
191
|
+
body: nil
|
200
192
|
)
|
201
193
|
|
202
|
-
expect
|
203
|
-
subject.versions(
|
204
|
-
|
194
|
+
expect do
|
195
|
+
subject.versions("not_real")
|
196
|
+
end.to raise_error(Berkshelf::CommunitySiteError)
|
205
197
|
end
|
206
198
|
end
|
207
199
|
|
208
|
-
describe
|
209
|
-
it
|
200
|
+
describe "#satisfy" do
|
201
|
+
it "returns the version number of the best solution" do
|
210
202
|
stub_request(:get, "#{api_uri}/cookbooks/bacon").to_return(
|
211
203
|
status: 200,
|
212
204
|
body: '{ "versions": ["/bacon/versions/1_0_0", "/bacon/versions/2_0_0"] }',
|
213
|
-
headers: {
|
205
|
+
headers: { "Content-Type" => "application/json" }
|
214
206
|
)
|
215
207
|
|
216
|
-
result = subject.satisfy(
|
217
|
-
expect(result).to eq(
|
208
|
+
result = subject.satisfy("bacon", "= 1.0.0")
|
209
|
+
expect(result).to eq("1.0.0")
|
218
210
|
end
|
219
211
|
end
|
220
212
|
|
221
|
-
describe
|
213
|
+
describe "#stream" do
|
222
214
|
skip
|
223
215
|
end
|
224
216
|
end
|
@@ -1,51 +1,80 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::Config do
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
4
|
+
describe "::instance" do
|
5
|
+
it "should be a Berkshelf::Config" do
|
6
|
+
expect(Berkshelf::Config.instance).to be_an_instance_of(Berkshelf::Config)
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
context "attributes" do
|
10
|
+
it "should have a default API timeout" do
|
11
|
+
expect(Berkshelf::Config.instance.api.timeout).to eq("30")
|
10
12
|
end
|
11
13
|
end
|
12
|
-
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
context "a Chef config to read defaults from" do
|
16
|
+
let(:chef_config) do
|
17
|
+
double(
|
18
|
+
Berkshelf::ChefConfigCompat,
|
19
|
+
chef_server_url: "https://chef.example.com",
|
20
|
+
validation_client_name: "validator",
|
21
|
+
validation_key: "validator.pem",
|
22
|
+
client_key: "client-key",
|
23
|
+
node_name: "fake-client",
|
24
|
+
trusted_certs_dir: "/tmp/fakecerts",
|
25
|
+
artifactory_api_key: "secret"
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
before do
|
30
|
+
allow(Berkshelf).to receive(:chef_config).and_return(chef_config)
|
31
|
+
end
|
18
32
|
|
19
|
-
|
20
|
-
|
21
|
-
|
33
|
+
{
|
34
|
+
chef_server_url: "https://chef.example.com",
|
35
|
+
validation_client_name: "validator",
|
36
|
+
validation_key_path: "validator.pem",
|
37
|
+
client_key: "client-key",
|
38
|
+
node_name: "fake-client",
|
39
|
+
trusted_certs_dir: "/tmp/fakecerts",
|
40
|
+
artifactory_api_key: "secret",
|
41
|
+
}.each do |attr, default|
|
42
|
+
it "should have a default chef.#{attr}" do
|
43
|
+
expect(Berkshelf::Config.instance.chef.send(attr)).to eq(default)
|
44
|
+
end
|
22
45
|
end
|
23
46
|
end
|
24
47
|
end
|
25
48
|
|
26
|
-
describe
|
27
|
-
it
|
49
|
+
describe "::path" do
|
50
|
+
it "is a string" do
|
28
51
|
expect(Berkshelf::Config.path).to be_a(String)
|
29
52
|
end
|
30
53
|
|
31
|
-
before do
|
32
|
-
allow(File).to receive(:exists?).and_return(false)
|
33
|
-
end
|
34
|
-
|
35
54
|
after do
|
36
55
|
Berkshelf::Config.instance_variable_set(:@path, nil)
|
37
56
|
end
|
38
57
|
|
39
58
|
context "when ENV['BERKSHELF_CONFIG'] is used" do
|
40
59
|
before do
|
41
|
-
allow(ENV).to receive(:[]).with(
|
42
|
-
allow(File).to receive(:
|
60
|
+
allow(ENV).to receive(:[]).with("BERKSHELF_CONFIG").and_return("/tmp/config.json")
|
61
|
+
allow(File).to receive(:exist?).with("/tmp/config.json").and_return(true)
|
43
62
|
end
|
44
63
|
|
45
64
|
it "points to a location within it" do
|
46
65
|
expect(Berkshelf::Config.path).to match(%r{/tmp/config.json})
|
47
66
|
end
|
48
67
|
end
|
68
|
+
|
69
|
+
it "reads json from a path" do
|
70
|
+
Tempfile.open(["berkstest", ".json"]) do |t|
|
71
|
+
t.write JSON.generate({ "ssl" => { "verify" => false } })
|
72
|
+
t.close
|
73
|
+
expect(Berkshelf::Config).to receive(:local_location).at_least(:once).and_return(t.path)
|
74
|
+
Berkshelf::Config.reload
|
75
|
+
expect( Berkshelf::Config.instance[:ssl][:verify] ).to be false
|
76
|
+
end
|
77
|
+
end
|
49
78
|
end
|
50
79
|
|
51
80
|
describe "::set_path" do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::CookbookStore do
|
4
4
|
describe "ClassMethods" do
|
@@ -6,8 +6,8 @@ describe Berkshelf::CookbookStore do
|
|
6
6
|
describe "::import"
|
7
7
|
|
8
8
|
describe "::new" do
|
9
|
-
it
|
10
|
-
storage_path = tmp_path.join(
|
9
|
+
it "creates the storage_path" do
|
10
|
+
storage_path = tmp_path.join("random_storage")
|
11
11
|
Berkshelf::CookbookStore.new(storage_path)
|
12
12
|
|
13
13
|
expect(storage_path).to exist
|
@@ -17,103 +17,103 @@ describe Berkshelf::CookbookStore do
|
|
17
17
|
|
18
18
|
subject { Berkshelf::CookbookStore.new(tmp_path.join("cbstore_rspec")) }
|
19
19
|
|
20
|
-
describe
|
21
|
-
let(:cookbook_name) {
|
22
|
-
let(:cookbook_version) {
|
20
|
+
describe "#cookbook_path" do
|
21
|
+
let(:cookbook_name) { "nginx" }
|
22
|
+
let(:cookbook_version) { "0.101.2" }
|
23
23
|
let(:path) { subject.cookbook_path(cookbook_name, cookbook_version) }
|
24
24
|
|
25
|
-
it
|
25
|
+
it "returns an instance of Pathname" do
|
26
26
|
expect(path).to be_a(Pathname)
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it "returns a the filepath within the storage path" do
|
30
30
|
expect(path.dirname).to eq(subject.storage_path)
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
33
|
+
it "returns a basename containing the cookbook name and version separated by a dash" do
|
34
34
|
expect(path.basename.to_s).to eq("#{cookbook_name}-#{cookbook_version}")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
describe
|
39
|
-
let(:name) {
|
40
|
-
let(:version) {
|
41
|
-
let(:constraint) { Semverse::Constraint.new(
|
42
|
-
let(:cached_one) { double(
|
43
|
-
let(:cached_two) { double(
|
38
|
+
describe "#satisfy" do
|
39
|
+
let(:name) { "nginx" }
|
40
|
+
let(:version) { "0.101.4" }
|
41
|
+
let(:constraint) { Semverse::Constraint.new("~> 0.101.2") }
|
42
|
+
let(:cached_one) { double("cached-one", name: name, version: Semverse::Version.new(version)) }
|
43
|
+
let(:cached_two) { double("cached-two", name: "mysql", version: Semverse::Version.new("1.2.6")) }
|
44
44
|
|
45
45
|
before { allow(subject).to receive(:cookbooks).and_return([cached_one, cached_two]) }
|
46
46
|
|
47
|
-
it
|
47
|
+
it "gets and returns the the CachedCookbook best matching the name and constraint" do
|
48
48
|
expect(subject).to receive(:cookbook).with(name, version).and_return(cached_one)
|
49
49
|
result = subject.satisfy(name, constraint)
|
50
50
|
|
51
51
|
expect(result).to eq(cached_one)
|
52
52
|
end
|
53
53
|
|
54
|
-
context
|
54
|
+
context "when there are no cookbooks in the cookbook store" do
|
55
55
|
before { allow(subject).to receive(:cookbooks).and_return([]) }
|
56
56
|
|
57
|
-
it
|
57
|
+
it "returns nil" do
|
58
58
|
result = subject.satisfy(name, constraint)
|
59
59
|
expect(result).to be_nil
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
context
|
64
|
-
let(:version) { Semverse::Version.new(
|
65
|
-
let(:constraint) { Semverse::Constraint.new(
|
63
|
+
context "when there is no matching cookbook for the given name and constraint" do
|
64
|
+
let(:version) { Semverse::Version.new("1.0.0") }
|
65
|
+
let(:constraint) { Semverse::Constraint.new("= 0.1.0") }
|
66
66
|
|
67
|
-
before { allow(subject).to receive(:cookbooks).and_return([ double(
|
67
|
+
before { allow(subject).to receive(:cookbooks).and_return([ double("badcache", name: "none", version: version) ]) }
|
68
68
|
|
69
|
-
it
|
69
|
+
it "returns nil if there is no matching cookbook for the name and constraint" do
|
70
70
|
result = subject.satisfy(name, constraint)
|
71
71
|
expect(result).to be_nil
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
describe
|
77
|
-
subject { Berkshelf::CookbookStore.new(fixtures_path.join(
|
76
|
+
describe "#cookbook" do
|
77
|
+
subject { Berkshelf::CookbookStore.new(fixtures_path.join("cookbooks")) }
|
78
78
|
|
79
|
-
it
|
80
|
-
expect(subject.cookbook(
|
79
|
+
it "returns a CachedCookbook if the specified cookbook version exists" do
|
80
|
+
expect(subject.cookbook("example_cookbook", "0.5.0")).to be_a(Berkshelf::CachedCookbook)
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
84
|
-
expect(subject.cookbook(
|
83
|
+
it "returns nil if the specified cookbook version does not exist" do
|
84
|
+
expect(subject.cookbook("doesnotexist", "0.1.0")).to be_nil
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
describe
|
88
|
+
describe "#cookbooks" do
|
89
89
|
before do
|
90
|
-
generate_cookbook(subject.storage_path,
|
91
|
-
generate_cookbook(subject.storage_path,
|
90
|
+
generate_cookbook(subject.storage_path, "nginx", "0.101.2")
|
91
|
+
generate_cookbook(subject.storage_path, "mysql", "1.2.6")
|
92
92
|
end
|
93
93
|
|
94
|
-
it
|
94
|
+
it "returns a list of CachedCookbooks" do
|
95
95
|
subject.cookbooks.each do |cookbook|
|
96
96
|
expect(cookbook).to be_a(Berkshelf::CachedCookbook)
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
it
|
100
|
+
it "contains a CachedCookbook for every cookbook in the storage path" do
|
101
101
|
expect(subject.cookbooks.size).to eq(2)
|
102
102
|
end
|
103
103
|
|
104
|
-
context
|
105
|
-
it
|
106
|
-
expect(subject.cookbooks(
|
104
|
+
context "given a value for the filter parameter" do
|
105
|
+
it "returns only the CachedCookbooks whose name match the filter" do
|
106
|
+
expect(subject.cookbooks("mysql").size).to eq(1)
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
context
|
110
|
+
context "when a there is a cookbook without a name attribute" do
|
111
111
|
before do
|
112
|
-
generate_cookbook(subject.storage_path,
|
112
|
+
generate_cookbook(subject.storage_path, "foo", "3.0.1", without_name: true)
|
113
113
|
end
|
114
114
|
|
115
|
-
it
|
116
|
-
expect(subject.cookbooks(
|
115
|
+
it "omits the broken cookbook" do
|
116
|
+
expect(subject.cookbooks("foo")).to be_empty
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|
@@ -1,19 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe FileUtils do
|
4
|
-
describe
|
5
|
-
let(:src) {
|
6
|
-
let(:dest) {
|
4
|
+
describe "#mv" do
|
5
|
+
let(:src) { "src" }
|
6
|
+
let(:dest) { "dest" }
|
7
7
|
let(:options) { {} }
|
8
8
|
|
9
9
|
it "uses mv by default" do
|
10
|
-
expect(FileUtils).to receive(:old_mv).with(src, dest, options)
|
10
|
+
expect(FileUtils).to receive(:old_mv).with(src, dest, **options)
|
11
11
|
FileUtils.mv(src, dest, options)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
expect(FileUtils).to receive(:cp_r).with(src, dest, options)
|
14
|
+
it "replaces mv with cp_r and rm_rf" do
|
15
|
+
expect(FileUtils).to receive(:cp_r).with(src, dest, **options)
|
17
16
|
expect(FileUtils).to receive(:rm_rf).with(src)
|
18
17
|
|
19
18
|
FileUtils.mv(src, dest, options)
|