chef-dk 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/chef-dk/authenticated_http.rb +40 -0
- data/lib/chef-dk/chef_runner.rb +5 -0
- data/lib/chef-dk/command/exec.rb +4 -1
- data/lib/chef-dk/command/generate.rb +11 -0
- data/lib/chef-dk/command/generator_commands.rb +20 -365
- data/lib/chef-dk/command/generator_commands/app.rb +99 -0
- data/lib/chef-dk/command/generator_commands/attribute.rb +37 -0
- data/lib/chef-dk/command/generator_commands/base.rb +76 -0
- data/lib/chef-dk/command/generator_commands/cookbook.rb +100 -0
- data/lib/chef-dk/command/generator_commands/cookbook_code_file.rb +99 -0
- data/lib/chef-dk/command/generator_commands/cookbook_file.rb +45 -0
- data/lib/chef-dk/command/generator_commands/lwrp.rb +36 -0
- data/lib/chef-dk/command/generator_commands/recipe.rb +36 -0
- data/lib/chef-dk/command/generator_commands/repo.rb +96 -0
- data/lib/chef-dk/command/generator_commands/template.rb +45 -0
- data/lib/chef-dk/command/verify.rb +28 -0
- data/lib/chef-dk/component_test.rb +16 -3
- data/lib/chef-dk/cookbook_omnifetch.rb +2 -0
- data/lib/chef-dk/cookbook_profiler/identifiers.rb +3 -15
- data/lib/chef-dk/exceptions.rb +15 -0
- data/lib/chef-dk/generator.rb +102 -25
- data/lib/chef-dk/policyfile/community_cookbook_source.rb +0 -7
- data/lib/chef-dk/policyfile/{cookbook_spec.rb → cookbook_location_specification.rb} +35 -6
- data/lib/chef-dk/policyfile/cookbook_locks.rb +305 -0
- data/lib/chef-dk/policyfile/dsl.rb +26 -12
- data/lib/chef-dk/policyfile/read_cookbook_for_compat_mode_upload.rb +70 -0
- data/lib/chef-dk/policyfile/solution_dependencies.rb +204 -0
- data/lib/chef-dk/policyfile/storage_config.rb +77 -0
- data/lib/chef-dk/policyfile/uploader.rb +110 -0
- data/lib/chef-dk/policyfile_compiler.rb +59 -29
- data/lib/chef-dk/policyfile_lock.rb +104 -160
- data/lib/chef-dk/skeletons/code_generator/files/default/Berksfile +1 -1
- data/lib/chef-dk/skeletons/code_generator/files/default/chefignore +0 -1
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/README.md +66 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/Rakefile +65 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/certificates/README.md +19 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/README-policy.md +9 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/README.md +54 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/data_bags/README.md +63 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/environments/README.md +5 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/roles/README.md +16 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +7 -1
- data/lib/chef-dk/skeletons/code_generator/recipes/repo.rb +62 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.all_rights.erb +3 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.apache2.erb +201 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.gplv2.erb +339 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.gplv3.erb +674 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.mit.erb +21 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/default_recipe.rb.erb +1 -4
- data/lib/chef-dk/skeletons/code_generator/templates/default/metadata.rb.erb +3 -3
- data/lib/chef-dk/skeletons/code_generator/templates/default/repo/config/rake.rb.erb +38 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/repo/gitignore.erb +11 -0
- data/lib/chef-dk/version.rb +1 -1
- data/spec/shared/a_file_generator.rb +121 -0
- data/spec/shared/a_generated_file.rb +12 -0
- data/spec/shared/fixture_cookbook_checksums.rb +47 -0
- data/spec/spec_helper.rb +4 -2
- data/spec/unit/chef_runner_spec.rb +12 -5
- data/spec/unit/cli_spec.rb +4 -4
- data/spec/unit/command/base_spec.rb +1 -1
- data/spec/unit/command/exec_spec.rb +37 -27
- data/spec/unit/command/generate_spec.rb +3 -3
- data/spec/unit/command/generator_commands/app_spec.rb +131 -0
- data/spec/unit/command/generator_commands/attribute_spec.rb +32 -0
- data/spec/unit/command/generator_commands/cookbook_file_spec.rb +32 -0
- data/spec/unit/command/generator_commands/cookbook_spec.rb +205 -0
- data/spec/unit/command/generator_commands/lwrp_spec.rb +32 -0
- data/spec/unit/command/generator_commands/recipe_spec.rb +32 -0
- data/spec/unit/command/generator_commands/repo_spec.rb +287 -0
- data/spec/unit/command/generator_commands/template_spec.rb +32 -0
- data/spec/unit/command/shell_init_spec.rb +4 -4
- data/spec/unit/command/verify_spec.rb +9 -9
- data/spec/unit/commands_map_spec.rb +1 -1
- data/spec/unit/component_test_spec.rb +3 -3
- data/spec/unit/cookbook_profiler/git_spec.rb +7 -7
- data/spec/unit/cookbook_profiler/identifiers_spec.rb +12 -8
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/Berksfile +1 -1
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/Berksfile +1 -1
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/Berksfile +1 -1
- data/spec/unit/fixtures/example_cookbook/Berksfile +1 -1
- data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/README.md +4 -0
- data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/chefignore +96 -0
- data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/metadata.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/recipes/default.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/Berksfile +1 -1
- data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/.kitchen.yml +16 -0
- data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/README.md +4 -0
- data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb +8 -0
- data/spec/unit/generator_spec.rb +120 -0
- data/spec/unit/policyfile/{cookbook_spec_spec.rb → cookbook_location_specification_spec.rb} +83 -38
- data/spec/unit/policyfile/cookbook_locks_spec.rb +354 -0
- data/spec/unit/policyfile/read_cookbook_for_compat_mode_upload_spec.rb +85 -0
- data/spec/unit/policyfile/solution_dependencies_spec.rb +145 -0
- data/spec/unit/policyfile/storage_config_spec.rb +98 -0
- data/spec/unit/policyfile/uploader_spec.rb +292 -0
- data/spec/unit/policyfile_demands_spec.rb +177 -24
- data/spec/unit/policyfile_evaluation_spec.rb +40 -12
- data/spec/unit/{policyfile_builder_spec.rb → policyfile_lock_build_spec.rb} +179 -64
- data/spec/unit/policyfile_lock_install_spec.rb +138 -0
- data/spec/unit/policyfile_lock_validation_spec.rb +610 -0
- metadata +103 -59
- data/spec/unit/command/generator_commands_spec.rb +0 -504
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) <%= year %> <%= copyright_holder %>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
name '<%= cookbook_name %>'
|
2
|
-
maintainer '<%=
|
3
|
-
maintainer_email '<%=
|
4
|
-
license '<%=
|
2
|
+
maintainer '<%= copyright_holder %>'
|
3
|
+
maintainer_email '<%= email %>'
|
4
|
+
license '<%= license %>'
|
5
5
|
description 'Installs/Configures <%= cookbook_name %>'
|
6
6
|
long_description 'Installs/Configures <%= cookbook_name %>'
|
7
7
|
version '0.1.0'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Configure the Rakefile's tasks.
|
2
|
+
|
3
|
+
###
|
4
|
+
# Company and SSL Details
|
5
|
+
# Used with the ssl_cert task.
|
6
|
+
###
|
7
|
+
|
8
|
+
# The company name - used for SSL certificates, and in srvious other places
|
9
|
+
COMPANY_NAME = "<%= copyright_holder %>"
|
10
|
+
|
11
|
+
# The Country Name to use for SSL Certificates
|
12
|
+
SSL_COUNTRY_NAME = "US"
|
13
|
+
|
14
|
+
# The State Name to use for SSL Certificates
|
15
|
+
SSL_STATE_NAME = "Several"
|
16
|
+
|
17
|
+
# The Locality Name for SSL - typically, the city
|
18
|
+
SSL_LOCALITY_NAME = "Locality"
|
19
|
+
|
20
|
+
# What department?
|
21
|
+
SSL_ORGANIZATIONAL_UNIT_NAME = "Operations"
|
22
|
+
|
23
|
+
# The SSL contact email address
|
24
|
+
SSL_EMAIL_ADDRESS = "ops@example.com"
|
25
|
+
|
26
|
+
# License for new Cookbooks
|
27
|
+
# Can be :apachev2 or :none
|
28
|
+
NEW_COOKBOOK_LICENSE = :<%= license %>
|
29
|
+
|
30
|
+
###
|
31
|
+
# Useful Extras (which you probably don't need to change)
|
32
|
+
###
|
33
|
+
|
34
|
+
# The top of the repository checkout
|
35
|
+
TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
36
|
+
|
37
|
+
# Where to store certificates generated with ssl_cert
|
38
|
+
CADIR = File.expand_path(File.join(TOPDIR, "certificates"))
|
data/lib/chef-dk/version.rb
CHANGED
@@ -0,0 +1,121 @@
|
|
1
|
+
shared_examples_for "a file generator" do
|
2
|
+
|
3
|
+
let(:stdout_io) { StringIO.new }
|
4
|
+
let(:stderr_io) { StringIO.new }
|
5
|
+
|
6
|
+
def stdout
|
7
|
+
stdout_io.string
|
8
|
+
end
|
9
|
+
|
10
|
+
def stderr
|
11
|
+
stderr_io.string
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:expected_cookbook_root) { tempdir }
|
15
|
+
let(:cookbook_name) { "example_cookbook" }
|
16
|
+
|
17
|
+
let(:cookbook_path) { File.join(tempdir, cookbook_name) }
|
18
|
+
|
19
|
+
subject(:recipe_generator) do
|
20
|
+
generator = described_class.new(argv)
|
21
|
+
allow(generator).to receive(:stdout).and_return(stdout_io)
|
22
|
+
allow(generator).to receive(:stderr).and_return(stderr_io)
|
23
|
+
generator
|
24
|
+
end
|
25
|
+
|
26
|
+
def generator_context
|
27
|
+
ChefDK::Generator.context
|
28
|
+
end
|
29
|
+
|
30
|
+
before do
|
31
|
+
ChefDK::Generator.reset
|
32
|
+
reset_tempdir
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when argv is empty" do
|
36
|
+
let(:argv) { [] }
|
37
|
+
|
38
|
+
it "emits an error message and exits" do
|
39
|
+
expected_stdout = "Usage: chef generate #{generator_name} [path/to/cookbook] NAME [options]"
|
40
|
+
|
41
|
+
expect(recipe_generator.run).to eq(1)
|
42
|
+
expect(stdout).to include(expected_stdout)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when CWD is a cookbook" do
|
47
|
+
|
48
|
+
let(:argv) { [ new_file_name ] }
|
49
|
+
|
50
|
+
before do
|
51
|
+
FileUtils.cp_r(File.join(fixtures_path, "example_cookbook"), tempdir)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "configures the generator context" do
|
55
|
+
Dir.chdir(cookbook_path) do
|
56
|
+
recipe_generator.read_and_validate_params
|
57
|
+
recipe_generator.setup_context
|
58
|
+
|
59
|
+
expect(generator_context.cookbook_root).to eq(expected_cookbook_root)
|
60
|
+
expect(generator_context.cookbook_name).to eq(cookbook_name)
|
61
|
+
expect(generator_context.new_file_basename).to eq(new_file_name)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "creates a new recipe" do
|
66
|
+
Dir.chdir(cookbook_path) do
|
67
|
+
allow(recipe_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
|
68
|
+
recipe_generator.run
|
69
|
+
end
|
70
|
+
|
71
|
+
generated_files.each do |expected_file|
|
72
|
+
expect(File).to exist(File.join(cookbook_path, expected_file))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when CWD is not a cookbook" do
|
79
|
+
context "and path to the cookbook is not given in the agv" do
|
80
|
+
let(:argv) { [ new_file_name ] }
|
81
|
+
|
82
|
+
it "emits an error message and exits" do
|
83
|
+
expected_stdout = "Usage: chef generate #{generator_name} [path/to/cookbook] NAME [options]"
|
84
|
+
expected_stderr = "Error: Directory #{Dir.pwd} is not a cookbook\n"
|
85
|
+
|
86
|
+
expect(recipe_generator.run).to eq(1)
|
87
|
+
expect(stdout).to include(expected_stdout)
|
88
|
+
expect(stderr).to eq(expected_stderr)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "and path to the cookbook is given in the argv" do
|
93
|
+
let(:argv) { [cookbook_path, new_file_name ] }
|
94
|
+
|
95
|
+
before do
|
96
|
+
FileUtils.cp_r(File.join(fixtures_path, "example_cookbook"), tempdir)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "configures the generator context" do
|
100
|
+
recipe_generator.read_and_validate_params
|
101
|
+
recipe_generator.setup_context
|
102
|
+
|
103
|
+
expect(generator_context.cookbook_root).to eq(File.dirname(cookbook_path))
|
104
|
+
expect(generator_context.cookbook_name).to eq(cookbook_name)
|
105
|
+
expect(generator_context.new_file_basename).to eq(new_file_name)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "creates a new recipe" do
|
109
|
+
allow(recipe_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
|
110
|
+
recipe_generator.run
|
111
|
+
|
112
|
+
generated_files.each do |expected_file|
|
113
|
+
expect(File).to exist(File.join(cookbook_path, expected_file))
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
shared_examples_for "a generated file" do |context_var|
|
2
|
+
before do
|
3
|
+
Dir.chdir(tempdir) do
|
4
|
+
allow(generator.chef_runner).to receive(:stdout).and_return(stdout_io)
|
5
|
+
generator.run
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should contain #{context_var} from the generator context" do
|
10
|
+
expect(File.read(file)).to match line
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'chef-dk/helpers'
|
19
|
+
|
20
|
+
RSpec.shared_context "fixture cookbooks checksums" do
|
21
|
+
|
22
|
+
def id_to_dotted(sha1_id)
|
23
|
+
major = sha1_id[0...14]
|
24
|
+
minor = sha1_id[14...28]
|
25
|
+
patch = sha1_id[28..40]
|
26
|
+
decimal_integers =[major, minor, patch].map {|hex| hex.to_i(16) }
|
27
|
+
decimal_integers.join(".")
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:cookbook_foo_cksum) { "467dc855408ce8b74f991c5dc2fd72a6aa369b60" }
|
31
|
+
|
32
|
+
let(:cookbook_foo_cksum_dotted) { id_to_dotted(cookbook_foo_cksum) }
|
33
|
+
|
34
|
+
let(:cookbook_bar_cksum) { "4c538def500b75e744a3af05df66afd04dc3b3c5" }
|
35
|
+
|
36
|
+
let(:cookbook_bar_cksum_dotted) { id_to_dotted(cookbook_bar_cksum) }
|
37
|
+
|
38
|
+
let(:cookbook_baz_cksum) { "5c9063efbc5b5d8acc37024d7383f7dd010ae728" }
|
39
|
+
|
40
|
+
let(:cookbook_baz_cksum_dotted) { id_to_dotted(cookbook_baz_cksum) }
|
41
|
+
|
42
|
+
let(:cookbook_dep_of_bar_cksum) { "a4a6a5e4c6d95a580d291f6415d55b010669feac" }
|
43
|
+
|
44
|
+
let(:cookbook_dep_of_bar_cksum_dotted) { id_to_dotted(cookbook_dep_of_bar_cksum) }
|
45
|
+
|
46
|
+
end
|
47
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -17,7 +17,6 @@
|
|
17
17
|
|
18
18
|
require 'rubygems'
|
19
19
|
require 'rspec/mocks'
|
20
|
-
require 'pry-debugger'
|
21
20
|
require 'test_helpers'
|
22
21
|
|
23
22
|
RSpec.configure do |c|
|
@@ -28,5 +27,8 @@ RSpec.configure do |c|
|
|
28
27
|
|
29
28
|
c.filter_run :focus => true
|
30
29
|
c.run_all_when_everything_filtered = true
|
31
|
-
|
30
|
+
|
31
|
+
c.mock_with(:rspec) do |mocks|
|
32
|
+
mocks.verify_partial_doubles = true
|
33
|
+
end
|
32
34
|
end
|
@@ -33,17 +33,24 @@ describe ChefDK::ChefRunner do
|
|
33
33
|
|
34
34
|
subject(:chef_runner) do
|
35
35
|
r = ChefDK::ChefRunner.new(default_cookbook_path, run_list)
|
36
|
-
r.
|
37
|
-
r.
|
36
|
+
allow(r).to receive(:stdout).and_return(stdout_io)
|
37
|
+
allow(r).to receive(:stderr).and_return(stderr_io)
|
38
38
|
r
|
39
39
|
end
|
40
40
|
|
41
41
|
it "sets up Chef::Config" do
|
42
42
|
chef_runner.configure
|
43
|
-
expect(Chef::Config.solo).to
|
43
|
+
expect(Chef::Config.solo).to be true
|
44
44
|
expect(Chef::Config.cookbook_path).to eq(default_cookbook_path)
|
45
|
-
expect(Chef::Config.color).to
|
46
|
-
expect(Chef::Config.diff_disabled).to
|
45
|
+
expect(Chef::Config.color).to be true
|
46
|
+
expect(Chef::Config.diff_disabled).to be true
|
47
|
+
expect(Chef::Config.file_staging_uses_destdir).to be true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "disables atomic file updates on Windows" do
|
51
|
+
allow(Chef::Platform).to receive(:windows?) { true }
|
52
|
+
chef_runner.configure
|
53
|
+
expect(Chef::Config.file_atomic_update).to be false
|
47
54
|
end
|
48
55
|
|
49
56
|
it "configures a formatter for the chef run" do
|
data/spec/unit/cli_spec.rb
CHANGED
@@ -58,15 +58,15 @@ E
|
|
58
58
|
let(:version_message) { "Chef Development Kit Version: #{ChefDK::VERSION}\n" }
|
59
59
|
|
60
60
|
def run_cli(expected_exit_code)
|
61
|
-
cli.
|
61
|
+
expect(cli).to receive(:exit).with(expected_exit_code)
|
62
62
|
cli.run
|
63
63
|
end
|
64
64
|
|
65
65
|
subject(:cli) do
|
66
66
|
ChefDK::CLI.new(argv).tap do |c|
|
67
|
-
c.
|
68
|
-
c.
|
69
|
-
c.
|
67
|
+
allow(c).to receive(:commands_map).and_return(commands_map)
|
68
|
+
allow(c).to receive(:stdout).and_return(stdout_io)
|
69
|
+
allow(c).to receive(:stderr).and_return(stderr_io)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -33,22 +33,22 @@ describe ChefDK::Command::Exec do
|
|
33
33
|
|
34
34
|
describe "when locating omnibus directory" do
|
35
35
|
it "should find omnibus bin directory from ruby path" do
|
36
|
-
Gem.
|
36
|
+
allow(Gem).to receive(:ruby).and_return(File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby"))
|
37
37
|
expect(command_instance.omnibus_bin_dir).to include("eg_omnibus_dir/valid/bin")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should find omnibus embedded bin directory from ruby path" do
|
41
|
-
Gem.
|
41
|
+
allow(Gem).to receive(:ruby).and_return(File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby"))
|
42
42
|
expect(command_instance.omnibus_embedded_bin_dir).to include("eg_omnibus_dir/valid/embedded/bin")
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should raise OmnibusInstallNotFound if directory is not looking like omnibus" do
|
46
|
-
Gem.
|
46
|
+
allow(Gem).to receive(:ruby).and_return(File.join(fixtures_path,".rbenv/versions/2.1.1/bin/ruby"))
|
47
47
|
expect{command_instance.omnibus_bin_dir}.to raise_error(ChefDK::OmnibusInstallNotFound)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should raise OmnibusInstallNotFound if directory is not looking like omnibus" do
|
51
|
-
Gem.
|
51
|
+
allow(Gem).to receive(:ruby).and_return(File.join(fixtures_path,".rbenv/versions/2.1.1/bin/ruby"))
|
52
52
|
expect{command_instance.omnibus_embedded_bin_dir}.to raise_error(ChefDK::OmnibusInstallNotFound)
|
53
53
|
end
|
54
54
|
end
|
@@ -57,7 +57,7 @@ describe ChefDK::Command::Exec do
|
|
57
57
|
let(:ruby_path) { File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby") }
|
58
58
|
|
59
59
|
before do
|
60
|
-
Gem.
|
60
|
+
allow(Gem).to receive(:ruby).and_return(ruby_path)
|
61
61
|
end
|
62
62
|
|
63
63
|
context "when running exec env" do
|
@@ -69,24 +69,29 @@ describe ChefDK::Command::Exec do
|
|
69
69
|
|
70
70
|
let(:omnibus_bin_dir) { "/foo/bin" }
|
71
71
|
|
72
|
-
let(:
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
72
|
+
let(:expected_PATH) { "#{omnibus_bin_dir}:#{user_bin_dir}:#{omnibus_embedded_bin_dir}:#{ENV['PATH']}" }
|
73
|
+
|
74
|
+
let(:expected_GEM_ROOT) { Gem.default_dir.inspect }
|
75
|
+
|
76
|
+
let(:expected_GEM_HOME) { ENV['GEM_HOME'] }
|
77
|
+
|
78
|
+
let(:expected_GEM_PATH) { Gem.path.join(':') }
|
80
79
|
|
81
80
|
before do
|
82
|
-
command_instance.
|
83
|
-
command_instance.
|
81
|
+
allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
|
82
|
+
allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir)
|
84
83
|
end
|
85
84
|
|
86
85
|
it "should call exec to fire off the command with the correct environment" do
|
87
|
-
expect(
|
86
|
+
expect(ENV).to receive(:[]=).with("PATH", expected_PATH)
|
87
|
+
expect(ENV).to receive(:[]=).with("GEM_ROOT", expected_GEM_ROOT)
|
88
|
+
expect(ENV).to receive(:[]=).with("GEM_HOME", expected_GEM_HOME)
|
89
|
+
expect(ENV).to receive(:[]=).with("GEM_PATH", expected_GEM_PATH)
|
90
|
+
|
91
|
+
expect(command_instance).to receive(:exec).with(*command_options)
|
88
92
|
expect{ run_command }.to raise_error # XXX: this isn't a test we just need to swallow the exception
|
89
93
|
end
|
94
|
+
|
90
95
|
end
|
91
96
|
|
92
97
|
context "when running command that does not exist" do
|
@@ -98,23 +103,28 @@ describe ChefDK::Command::Exec do
|
|
98
103
|
|
99
104
|
let(:omnibus_embedded_bin_dir) { "/foo/embedded/bin" }
|
100
105
|
|
101
|
-
let(:
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
let(:expected_PATH) { "#{omnibus_bin_dir}:#{user_bin_dir}:#{omnibus_embedded_bin_dir}:#{ENV['PATH']}" }
|
107
|
+
|
108
|
+
let(:expected_GEM_ROOT) { Gem.default_dir.inspect }
|
109
|
+
|
110
|
+
let(:expected_GEM_HOME) { ENV['GEM_HOME'] }
|
111
|
+
|
112
|
+
let(:expected_GEM_PATH) { Gem.path.join(':') }
|
113
|
+
|
109
114
|
|
110
115
|
before do
|
111
|
-
command_instance.
|
112
|
-
command_instance.
|
116
|
+
allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
|
117
|
+
allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir)
|
113
118
|
end
|
114
119
|
|
115
120
|
it "should raise Errno::ENOENT" do
|
121
|
+
expect(ENV).to receive(:[]=).with("PATH", expected_PATH)
|
122
|
+
expect(ENV).to receive(:[]=).with("GEM_ROOT", expected_GEM_ROOT)
|
123
|
+
expect(ENV).to receive(:[]=).with("GEM_HOME", expected_GEM_HOME)
|
124
|
+
expect(ENV).to receive(:[]=).with("GEM_PATH", expected_GEM_PATH)
|
125
|
+
|
116
126
|
# XXX: this doesn't really test much, but really calling exec will never return to rspec
|
117
|
-
expect(command_instance).to receive(:exec).with(
|
127
|
+
expect(command_instance).to receive(:exec).with(*command_options).and_raise(Errno::ENOENT)
|
118
128
|
expect{ run_command }.to raise_error(Errno::ENOENT)
|
119
129
|
end
|
120
130
|
end
|