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,164 +1,246 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Berkshelf
|
4
4
|
describe Uploader do
|
5
5
|
let(:berksfile) do
|
6
6
|
double(Berksfile,
|
7
7
|
lockfile: lockfile,
|
8
|
-
dependencies: []
|
9
|
-
)
|
8
|
+
dependencies: [])
|
10
9
|
end
|
11
10
|
|
12
11
|
let(:lockfile) do
|
13
12
|
double(Lockfile,
|
14
|
-
graph: graph
|
15
|
-
)
|
13
|
+
graph: graph)
|
16
14
|
end
|
17
15
|
|
18
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) }
|
19
21
|
|
20
22
|
subject { Uploader.new(berksfile) }
|
21
23
|
|
22
|
-
describe
|
23
|
-
it
|
24
|
+
describe "#initialize" do
|
25
|
+
it "saves the berksfile" do
|
24
26
|
instance = Uploader.new(berksfile)
|
25
27
|
expect(instance.berksfile).to be(berksfile)
|
26
28
|
end
|
27
29
|
|
28
|
-
it
|
30
|
+
it "saves the lockfile" do
|
29
31
|
instance = Uploader.new(berksfile)
|
30
32
|
expect(instance.lockfile).to be(lockfile)
|
31
33
|
end
|
32
34
|
|
33
|
-
it
|
35
|
+
it "saves the options" do
|
34
36
|
instance = Uploader.new(berksfile, force: true, validate: false)
|
35
37
|
options = instance.options
|
36
38
|
expect(options[:force]).to be(true)
|
37
39
|
expect(options[:validate]).to be(false)
|
38
40
|
end
|
39
41
|
|
40
|
-
it
|
41
|
-
instance = Uploader.new(berksfile,
|
42
|
-
expect(instance.names).to eq(
|
42
|
+
it "saves the names" do
|
43
|
+
instance = Uploader.new(berksfile, "cookbook_1", "cookbook_2")
|
44
|
+
expect(instance.names).to eq(%w{cookbook_1 cookbook_2})
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
|
-
describe
|
47
|
-
let(:options) {
|
48
|
+
describe "#run" do
|
49
|
+
let(:options) { {} }
|
48
50
|
|
49
51
|
let(:chef_config) do
|
50
|
-
double(
|
51
|
-
node_name:
|
52
|
-
client_key:
|
53
|
-
chef_server_url:
|
54
|
-
validation_client_name:
|
55
|
-
validation_key:
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
}
|
62
|
-
)
|
52
|
+
double(Berkshelf::ChefConfigCompat,
|
53
|
+
node_name: "fake-client",
|
54
|
+
client_key: "client-key",
|
55
|
+
chef_server_url: "http://configured-chef-server/",
|
56
|
+
validation_client_name: "validator",
|
57
|
+
validation_key: "validator.pem",
|
58
|
+
artifactory_api_key: "secret",
|
59
|
+
cookbook_copyright: "user",
|
60
|
+
cookbook_email: "user@example.com",
|
61
|
+
cookbook_license: "apachev2",
|
62
|
+
trusted_certs_dir: self_signed_crt_path)
|
63
63
|
end
|
64
64
|
|
65
65
|
let(:berkshelf_config) do
|
66
66
|
double(Config,
|
67
67
|
ssl: double(verify: true),
|
68
|
-
chef: chef_config
|
69
|
-
)
|
68
|
+
chef: chef_config)
|
70
69
|
end
|
71
70
|
|
72
71
|
let(:default_ridley_options) do
|
73
72
|
{
|
74
|
-
client_name:
|
75
|
-
client_key:
|
73
|
+
client_name: "fake-client",
|
74
|
+
client_key: "client-key",
|
76
75
|
ssl: {
|
77
|
-
verify: true
|
78
|
-
}
|
76
|
+
verify: true,
|
77
|
+
},
|
79
78
|
}
|
80
79
|
end
|
81
80
|
|
82
81
|
before do
|
83
82
|
allow(Berkshelf).to receive(:config).and_return(berkshelf_config)
|
83
|
+
allow(Berkshelf).to receive(:ssl_policy).and_return(ssl_policy)
|
84
84
|
end
|
85
85
|
|
86
|
-
context
|
86
|
+
context "when there is no value for :chef_server_url" do
|
87
87
|
before { allow(chef_config).to receive_messages(chef_server_url: nil) }
|
88
|
-
let(:message) {
|
88
|
+
let(:message) { "Missing required attribute in your Berkshelf configuration: chef.server_url" }
|
89
89
|
|
90
|
-
it
|
90
|
+
it "raises an error" do
|
91
91
|
expect { subject.run }.to raise_error(Berkshelf::ChefConnectionError, message)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
context
|
95
|
+
context "when there is no value for :client_name" do
|
96
96
|
before { allow(chef_config).to receive_messages(node_name: nil) }
|
97
|
-
let(:message) {
|
97
|
+
let(:message) { "Missing required attribute in your Berkshelf configuration: chef.node_name" }
|
98
98
|
|
99
|
-
it
|
99
|
+
it "raises an error" do
|
100
100
|
expect { subject.run }.to raise_error(Berkshelf::ChefConnectionError, message)
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
context
|
104
|
+
context "when there is no value for :client_key" do
|
105
105
|
before { allow(chef_config).to receive_messages(client_key: nil) }
|
106
|
-
let(:message) {
|
106
|
+
let(:message) { "Missing required attribute in your Berkshelf configuration: chef.client_key" }
|
107
107
|
|
108
|
-
it
|
109
|
-
expect
|
108
|
+
it "raises an error" do
|
109
|
+
expect do
|
110
110
|
subject.run
|
111
|
-
|
111
|
+
end.to raise_error(Berkshelf::ChefConnectionError, message)
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
context
|
115
|
+
context "when no options are given" do
|
116
116
|
let(:ridley_options) do
|
117
|
-
{ server_url:
|
117
|
+
{ server_url: "http://configured-chef-server/" }.merge(default_ridley_options)
|
118
118
|
end
|
119
119
|
|
120
|
-
it
|
121
|
-
expect(
|
120
|
+
it "uses the Berkshelf::Config options" do
|
121
|
+
expect(Berkshelf::RidleyCompat).to receive(:new_client).with(
|
122
122
|
server_url: chef_config.chef_server_url,
|
123
123
|
client_name: chef_config.node_name,
|
124
124
|
client_key: chef_config.client_key,
|
125
125
|
ssl: {
|
126
|
-
verify: berkshelf_config.ssl.verify
|
126
|
+
verify: berkshelf_config.ssl.verify,
|
127
|
+
cert_store: cert_store,
|
127
128
|
}
|
128
129
|
)
|
129
130
|
subject.run
|
130
131
|
end
|
131
132
|
end
|
132
133
|
|
133
|
-
context
|
134
|
-
subject { Uploader.new(berksfile,
|
134
|
+
context "when ssl_verify: false is passed as an option" do
|
135
|
+
subject { Uploader.new(berksfile, ssl_verify: false) }
|
135
136
|
|
136
|
-
it
|
137
|
-
expect(
|
138
|
-
|
137
|
+
it "uses the passed option" do
|
138
|
+
expect(Berkshelf::RidleyCompat).to receive(:new_client).with(
|
139
|
+
server_url: chef_config.chef_server_url,
|
140
|
+
client_name: chef_config.node_name,
|
141
|
+
client_key: chef_config.client_key,
|
142
|
+
ssl: {
|
143
|
+
verify: false,
|
144
|
+
cert_store: cert_store,
|
145
|
+
}
|
146
|
+
)
|
139
147
|
subject.run
|
140
148
|
end
|
141
149
|
end
|
142
150
|
|
143
|
-
context
|
144
|
-
subject { Uploader.new(berksfile,
|
151
|
+
context "when a Chef Server url is passed as an option" do
|
152
|
+
subject { Uploader.new(berksfile, server_url: "http://custom") }
|
145
153
|
|
146
|
-
it
|
147
|
-
expect(
|
148
|
-
.with(include(
|
154
|
+
it "uses the passed in :server_url" do
|
155
|
+
expect(Berkshelf::RidleyCompat).to receive(:new_client)
|
156
|
+
.with(include(server_url: "http://custom"))
|
149
157
|
subject.run
|
150
158
|
end
|
151
159
|
end
|
152
160
|
|
153
|
-
context
|
154
|
-
subject { Uploader.new(berksfile,
|
161
|
+
context "when a client name is passed as an option" do
|
162
|
+
subject { Uploader.new(berksfile, client_name: "custom") }
|
155
163
|
|
156
|
-
it
|
157
|
-
expect(
|
158
|
-
.with(include(
|
164
|
+
it "uses the passed in :client_name" do
|
165
|
+
expect(Berkshelf::RidleyCompat).to receive(:new_client)
|
166
|
+
.with(include(client_name: "custom"))
|
159
167
|
subject.run
|
160
168
|
end
|
161
169
|
end
|
170
|
+
|
171
|
+
context "when a client key is passed as an option" do
|
172
|
+
subject { Uploader.new(berksfile, client_key: "custom") }
|
173
|
+
|
174
|
+
it "uses the passed in :client_key" do
|
175
|
+
expect(Berkshelf::RidleyCompat).to receive(:new_client)
|
176
|
+
.with(include(client_key: "custom"))
|
177
|
+
subject.run
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "#lookup_dependencies" do
|
183
|
+
before do
|
184
|
+
allow_any_instance_of(Berkshelf::Berksfile).to receive(:lockfile).and_return(lockfile)
|
185
|
+
end
|
186
|
+
|
187
|
+
let(:berksfile) { Berkshelf::Berksfile.from_file(fixtures_path.join("berksfiles/default")) }
|
188
|
+
let(:lockfile) { Berkshelf::Lockfile.from_file(fixtures_path.join("lockfiles/default.lock")) }
|
189
|
+
|
190
|
+
context "when given a cookbook that has no dependencies" do
|
191
|
+
subject { described_class.new(berksfile).send(:lookup_dependencies, "yum") }
|
192
|
+
|
193
|
+
it "returns empty array" do
|
194
|
+
expect(subject).to eq []
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "when given a cookbook that has dependencies" do
|
199
|
+
subject { described_class.new(berksfile).send(:lookup_dependencies, "yum-epel") }
|
200
|
+
|
201
|
+
it "returns array of cookbook's dependencies" do
|
202
|
+
expect(subject).to eq ["yum"]
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context "when given a cookbook that has dependencies which have dependencies" do
|
207
|
+
subject { described_class.new(berksfile).send(:lookup_dependencies, "runit") }
|
208
|
+
|
209
|
+
it "returns array of cookbook's dependencies and their dependencies" do
|
210
|
+
expect(subject).to eq %w{build-essential yum yum-epel}
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "#filtered_cookbooks" do
|
216
|
+
context "when iterating over a list of of cookbooks that have dependencies" do
|
217
|
+
before do
|
218
|
+
allow_any_instance_of(Berkshelf::Dependency).to receive(:berksfile).and_return(berksfile)
|
219
|
+
allow_any_instance_of(Berkshelf::Berksfile).to receive(:lockfile).and_return(lockfile)
|
220
|
+
allow(Berkshelf::CookbookStore).to receive(:instance).and_return(cookbook_store)
|
221
|
+
end
|
222
|
+
|
223
|
+
let(:berksfile) { Berkshelf::Berksfile.from_file(fixtures_path.join("berksfiles/default")) }
|
224
|
+
let(:lockfile) { Berkshelf::Lockfile.from_file(fixtures_path.join("lockfiles/default.lock")) }
|
225
|
+
let(:cookbook_store) { Berkshelf::CookbookStore.new(fixtures_path.join("cookbook-path-uploader")) }
|
226
|
+
|
227
|
+
subject { described_class.new(berksfile).send(:filtered_cookbooks) }
|
228
|
+
|
229
|
+
it "returns filtered list in correct order" do
|
230
|
+
upload_order = subject.map(&:name)
|
231
|
+
# assert that dependent cookbooks are uploaded before the cookbooks that depend on them
|
232
|
+
expect(upload_order.index("apt")).to be < upload_order.index("jenkins")
|
233
|
+
expect(upload_order.index("runit")).to be < upload_order.index("jenkins")
|
234
|
+
expect(upload_order.index("yum")).to be < upload_order.index("jenkins")
|
235
|
+
expect(upload_order.index("jenkins")).to be < upload_order.index("jenkins-config")
|
236
|
+
expect(upload_order.index("yum")).to be < upload_order.index("jenkins-config")
|
237
|
+
expect(upload_order.index("build-essential")).to be < upload_order.index("runit")
|
238
|
+
expect(upload_order.index("yum")).to be < upload_order.index("runit")
|
239
|
+
expect(upload_order.index("yum-epel")).to be < upload_order.index("runit")
|
240
|
+
expect(upload_order.index("yum")).to be < upload_order.index("yum-epel")
|
241
|
+
expect(upload_order.uniq.length).to eql(upload_order.length)
|
242
|
+
end
|
243
|
+
end
|
162
244
|
end
|
163
245
|
end
|
164
246
|
end
|
@@ -1,30 +1,37 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::Validator do
|
4
|
-
describe
|
5
|
-
let(:cookbook) { double(
|
4
|
+
describe "#validate_files" do
|
5
|
+
let(:cookbook) { double("cookbook", cookbook_name: "cookbook", path: "path") }
|
6
6
|
|
7
|
-
it
|
8
|
-
allow(Dir).to receive(:glob).and_return([
|
9
|
-
|
7
|
+
it "raises an error when the cookbook has spaces in the files" do
|
8
|
+
allow(Dir).to receive(:glob).and_return(["/there are/spaces/in this/recipes/default.rb"])
|
9
|
+
allow(cookbook).to receive(:dependencies).and_return({"cookbook" => "1.0.0"})
|
10
|
+
expect do
|
10
11
|
subject.validate_files(cookbook)
|
11
|
-
|
12
|
+
end.to raise_error(Berkshelf::InvalidCookbookFiles)
|
12
13
|
end
|
13
14
|
|
14
|
-
it
|
15
|
-
allow(Dir).to receive(:glob).and_return([
|
16
|
-
|
15
|
+
it "does not raise an error when the cookbook is valid" do
|
16
|
+
allow(Dir).to receive(:glob).and_return(["/there-are/no-spaces/in-this/recipes/default.rb"])
|
17
|
+
allow(cookbook).to receive(:dependencies).and_return({"cookbook" => "1.0.0"})
|
18
|
+
expect do
|
17
19
|
subject.validate_files(cookbook)
|
18
|
-
|
20
|
+
end.to_not raise_error
|
19
21
|
end
|
20
22
|
|
21
|
-
it
|
22
|
-
allow(
|
23
|
-
|
23
|
+
it "raises an error when the cookbook version is not valid" do
|
24
|
+
allow(cookbook).to receive(:dependencies).and_return({"cookbook" => "1"})
|
25
|
+
expect do
|
26
|
+
subject.validate_files(cookbook)
|
27
|
+
end.to raise_error
|
28
|
+
end
|
24
29
|
|
25
|
-
|
30
|
+
it "does not raise an error when the cookbook version is valid" do
|
31
|
+
allow(cookbook).to receive(:dependencies).and_return({"cookbook" => "1.0"})
|
32
|
+
expect do
|
26
33
|
subject.validate_files(cookbook)
|
27
|
-
|
34
|
+
end.to_not raise_error
|
28
35
|
end
|
29
36
|
end
|
30
37
|
end
|
@@ -1,43 +1,52 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rspec"
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
4
|
module Berkshelf
|
5
5
|
describe Visualizer, :not_supported_on_windows do
|
6
|
-
describe
|
7
|
-
context
|
6
|
+
describe "#to_png" do
|
7
|
+
context "when graphviz is not installed" do
|
8
8
|
before do
|
9
9
|
allow(Berkshelf).to receive(:which)
|
10
|
-
.with(
|
10
|
+
.with("dot")
|
11
11
|
.and_return(nil)
|
12
12
|
allow(Berkshelf).to receive(:which)
|
13
|
-
.with(
|
13
|
+
.with("dot.exe")
|
14
14
|
.and_return(nil)
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it "raises a GraphvizNotInstalled exception" do
|
18
18
|
expect { subject.to_png }.to raise_error(GraphvizNotInstalled)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
context
|
22
|
+
context "when the graphviz command fails", :graphviz do
|
23
23
|
before do
|
24
|
-
response = double(
|
24
|
+
response = double(error?: true, stderr: "Something happened!")
|
25
25
|
allow(subject).to receive(:shell_out).and_return(response)
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it "raises a GraphvizCommandFailed exception" do
|
29
29
|
expect { subject.to_png }.to raise_error(GraphvizCommandFailed)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
context
|
34
|
-
it
|
35
|
-
outfile = tmp_path.join(
|
36
|
-
lockfile = Lockfile.from_file(fixtures_path.join(
|
33
|
+
context "when the graphviz command succeeds", :graphviz do
|
34
|
+
it "builds a dot from a Lockfile" do
|
35
|
+
outfile = tmp_path.join("test-graph.dot").to_s
|
36
|
+
lockfile = Lockfile.from_file(fixtures_path.join("lockfiles/default.lock").to_s)
|
37
|
+
|
38
|
+
Visualizer.from_lockfile(lockfile).to_dot_file(outfile)
|
39
|
+
|
40
|
+
expect(File.exist?(outfile)).to be true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "builds a png from a Lockfile" do
|
44
|
+
outfile = tmp_path.join("test-graph.png").to_s
|
45
|
+
lockfile = Lockfile.from_file(fixtures_path.join("lockfiles/default.lock").to_s)
|
37
46
|
|
38
47
|
Visualizer.from_lockfile(lockfile).to_png(outfile)
|
39
48
|
|
40
|
-
expect(File.
|
49
|
+
expect(File.exist?(outfile)).to be true
|
41
50
|
end
|
42
51
|
end
|
43
52
|
end
|
data/spec/unit/berkshelf_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Berkshelf
|
4
|
-
describe
|
5
|
-
context
|
4
|
+
describe ".formatter" do
|
5
|
+
context "with default formatter" do
|
6
6
|
before { Berkshelf.instance_variable_set(:@formatter, nil) }
|
7
7
|
|
8
|
-
it
|
8
|
+
it "is human readable" do
|
9
9
|
expect(Berkshelf.formatter).to be_an_instance_of(HumanFormatter)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
context
|
13
|
+
context "with a custom formatter" do
|
14
14
|
before(:all) do
|
15
15
|
Berkshelf.instance_eval { @formatter = nil }
|
16
16
|
end
|
@@ -21,41 +21,41 @@ module Berkshelf
|
|
21
21
|
Berkshelf.set_format :custom
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it "is custom class" do
|
25
25
|
expect(Berkshelf.formatter).to be_an_instance_of(CustomFormatter)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe
|
30
|
+
describe ".berkshelf_path" do
|
31
31
|
before { Berkshelf.instance_variable_set(:@berkshelf_path, nil) }
|
32
32
|
|
33
|
-
context
|
33
|
+
context "with default path" do
|
34
34
|
before do
|
35
|
-
@berkshelf_path = ENV[
|
36
|
-
ENV[
|
35
|
+
@berkshelf_path = ENV["BERKSHELF_PATH"]
|
36
|
+
ENV["BERKSHELF_PATH"] = nil
|
37
37
|
end
|
38
38
|
|
39
39
|
after do
|
40
|
-
ENV[
|
40
|
+
ENV["BERKSHELF_PATH"] = @berkshelf_path
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
expect(Berkshelf.berkshelf_path).to eq File.expand_path(
|
45
|
-
expect(Berkshelf.instance_variable_get(:@berkshelf_path)).to eq File.expand_path(
|
43
|
+
it "is ~/.berkshelf" do
|
44
|
+
expect(Berkshelf.berkshelf_path).to eq File.expand_path("~/.berkshelf")
|
45
|
+
expect(Berkshelf.instance_variable_get(:@berkshelf_path)).to eq File.expand_path("~/.berkshelf")
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
context 'with ENV["BERKSHELF_PATH"]' do
|
50
50
|
it 'is ENV["BERKSHELF_PATH"]' do
|
51
|
-
expect(Berkshelf.berkshelf_path).to eq File.expand_path(ENV[
|
52
|
-
expect(Berkshelf.instance_variable_get(:@berkshelf_path)).to eq File.expand_path(ENV[
|
51
|
+
expect(Berkshelf.berkshelf_path).to eq File.expand_path(ENV["BERKSHELF_PATH"])
|
52
|
+
expect(Berkshelf.instance_variable_get(:@berkshelf_path)).to eq File.expand_path(ENV["BERKSHELF_PATH"])
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
describe
|
58
|
-
it
|
57
|
+
describe "::log" do
|
58
|
+
it "returns Berkshelf::Logger" do
|
59
59
|
expect(Berkshelf.log).to be_a(Berkshelf::Logger)
|
60
60
|
end
|
61
61
|
end
|