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
@@ -44,8 +44,8 @@ describe ChefDK::Command::Generate do
|
|
44
44
|
|
45
45
|
subject(:generate) do
|
46
46
|
g = generator_class.new
|
47
|
-
g.
|
48
|
-
g.
|
47
|
+
allow(g).to receive(:stdout).and_return(stdout_io)
|
48
|
+
allow(g).to receive(:stderr).and_return(stderr_io)
|
49
49
|
g
|
50
50
|
end
|
51
51
|
|
@@ -68,7 +68,7 @@ E
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "includes the generator in the list" do
|
71
|
-
expect(generator_class).to
|
71
|
+
expect(generator_class.generators.size).to eq(1)
|
72
72
|
generator_spec = generator_class.generators.first
|
73
73
|
expect(generator_spec.name).to eq(:example)
|
74
74
|
expect(generator_spec.class_name).to eq(:Example)
|
@@ -0,0 +1,131 @@
|
|
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 'spec_helper'
|
19
|
+
require 'chef-dk/command/generator_commands/app'
|
20
|
+
|
21
|
+
describe ChefDK::Command::GeneratorCommands::App do
|
22
|
+
|
23
|
+
let(:argv) { %w[new_app] }
|
24
|
+
|
25
|
+
let(:stdout_io) { StringIO.new }
|
26
|
+
let(:stderr_io) { StringIO.new }
|
27
|
+
|
28
|
+
let(:expected_cookbook_file_relpaths) do
|
29
|
+
%w[
|
30
|
+
.gitignore
|
31
|
+
.kitchen.yml
|
32
|
+
README.md
|
33
|
+
cookbooks/new_app/Berksfile
|
34
|
+
cookbooks/new_app/chefignore
|
35
|
+
cookbooks/new_app/metadata.rb
|
36
|
+
cookbooks/new_app/recipes
|
37
|
+
cookbooks/new_app/recipes/default.rb
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:expected_cookbook_files) do
|
42
|
+
expected_cookbook_file_relpaths.map do |relpath|
|
43
|
+
File.join(tempdir, "new_app", relpath)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
subject(:cookbook_generator) { described_class.new(argv) }
|
48
|
+
|
49
|
+
def generator_context
|
50
|
+
ChefDK::Generator.context
|
51
|
+
end
|
52
|
+
|
53
|
+
before do
|
54
|
+
ChefDK::Generator.reset
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when given the name of the cookbook to generate" do
|
58
|
+
|
59
|
+
before do
|
60
|
+
reset_tempdir
|
61
|
+
end
|
62
|
+
|
63
|
+
it "configures the generator context" do
|
64
|
+
cookbook_generator.read_and_validate_params
|
65
|
+
cookbook_generator.setup_context
|
66
|
+
expect(generator_context.app_root).to eq(Dir.pwd)
|
67
|
+
expect(generator_context.app_name).to eq("new_app")
|
68
|
+
expect(generator_context.cookbook_root).to eq(File.join(Dir.pwd, "new_app", "cookbooks"))
|
69
|
+
expect(generator_context.cookbook_name).to eq("new_app")
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "generated files" do
|
73
|
+
it "creates a new cookbook" do
|
74
|
+
Dir.chdir(tempdir) do
|
75
|
+
allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
|
76
|
+
cookbook_generator.run
|
77
|
+
end
|
78
|
+
generated_files = Dir.glob(File.join(tempdir, "new_app", "**", "*"), File::FNM_DOTMATCH)
|
79
|
+
expected_cookbook_files.each do |expected_file|
|
80
|
+
expect(generated_files).to include(expected_file)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
shared_examples_for "a generated file" do |context_var|
|
85
|
+
before do
|
86
|
+
Dir.chdir(tempdir) do
|
87
|
+
allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
|
88
|
+
cookbook_generator.run
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should contain #{context_var} from the generator context" do
|
93
|
+
expect(File.read(file)).to match line
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "README.md" do
|
98
|
+
let(:file) { File.join(tempdir, "new_app", "README.md") }
|
99
|
+
|
100
|
+
include_examples "a generated file", :cookbook_name do
|
101
|
+
let(:line) { "# new_app" }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe ".kitchen.yml" do
|
106
|
+
let(:file) { File.join(tempdir, "new_app", ".kitchen.yml") }
|
107
|
+
|
108
|
+
include_examples "a generated file", :cookbook_name do
|
109
|
+
let(:line) { /\s*- recipe\[new_app::default\]/ }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "cookbooks/new_app/metadata.rb" do
|
114
|
+
let(:file) { File.join(tempdir, "new_app", "cookbooks", "new_app", "metadata.rb") }
|
115
|
+
|
116
|
+
include_examples "a generated file", :cookbook_name do
|
117
|
+
let(:line) { /name\s+'new_app'/ }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "cookbooks/new_app/recipes/default.rb" do
|
122
|
+
let(:file) { File.join(tempdir, "new_app", "cookbooks", "new_app", "recipes", "default.rb") }
|
123
|
+
|
124
|
+
include_examples "a generated file", :cookbook_name do
|
125
|
+
let(:line) { "# Cookbook Name:: new_app" }
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
@@ -0,0 +1,32 @@
|
|
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 'spec_helper'
|
19
|
+
require 'shared/a_file_generator'
|
20
|
+
require 'chef-dk/command/generator_commands/attribute'
|
21
|
+
|
22
|
+
describe ChefDK::Command::GeneratorCommands::Attribute do
|
23
|
+
|
24
|
+
include_examples "a file generator" do
|
25
|
+
|
26
|
+
let(:generator_name) { "attribute" }
|
27
|
+
let(:generated_files) { [ "attributes/new_attribute_file.rb" ] }
|
28
|
+
let(:new_file_name) { "new_attribute_file" }
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,32 @@
|
|
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 'spec_helper'
|
19
|
+
require 'shared/a_file_generator'
|
20
|
+
require 'chef-dk/command/generator_commands/cookbook_file'
|
21
|
+
|
22
|
+
describe ChefDK::Command::GeneratorCommands::CookbookFile do
|
23
|
+
|
24
|
+
include_examples "a file generator" do
|
25
|
+
|
26
|
+
let(:generator_name) { "file" }
|
27
|
+
let(:generated_files) { [ "files/default/new_file.txt" ] }
|
28
|
+
let(:new_file_name) { "new_file.txt" }
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,205 @@
|
|
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 'spec_helper'
|
19
|
+
require 'chef-dk/command/generator_commands/cookbook'
|
20
|
+
|
21
|
+
describe ChefDK::Command::GeneratorCommands::Cookbook do
|
22
|
+
|
23
|
+
let(:argv) { %w[new_cookbook] }
|
24
|
+
|
25
|
+
let(:stdout_io) { StringIO.new }
|
26
|
+
let(:stderr_io) { StringIO.new }
|
27
|
+
|
28
|
+
let(:expected_cookbook_file_relpaths) do
|
29
|
+
%w[
|
30
|
+
.gitignore
|
31
|
+
.kitchen.yml
|
32
|
+
Berksfile
|
33
|
+
chefignore
|
34
|
+
metadata.rb
|
35
|
+
README.md
|
36
|
+
recipes
|
37
|
+
recipes/default.rb
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:expected_cookbook_files) do
|
42
|
+
expected_cookbook_file_relpaths.map do |relpath|
|
43
|
+
File.join(tempdir, "new_cookbook", relpath)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
subject(:cookbook_generator) do
|
48
|
+
g = described_class.new(argv)
|
49
|
+
allow(g).to receive(:cookbook_path_in_git_repo?).and_return(false)
|
50
|
+
g
|
51
|
+
end
|
52
|
+
|
53
|
+
def generator_context
|
54
|
+
ChefDK::Generator.context
|
55
|
+
end
|
56
|
+
|
57
|
+
before do
|
58
|
+
ChefDK::Generator.reset
|
59
|
+
end
|
60
|
+
|
61
|
+
it "configures the chef runner" do
|
62
|
+
expect(cookbook_generator.chef_runner).to be_a(ChefDK::ChefRunner)
|
63
|
+
expect(cookbook_generator.chef_runner.cookbook_path).to eq(File.expand_path('lib/chef-dk/skeletons', project_root))
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when given invalid/incomplete arguments" do
|
67
|
+
|
68
|
+
let(:expected_help_message) do
|
69
|
+
"Usage: chef generate cookbook NAME [options]\n"
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def with_argv(argv)
|
74
|
+
generator = described_class.new(argv)
|
75
|
+
allow(generator).to receive(:stdout).and_return(stdout_io)
|
76
|
+
allow(generator).to receive(:stderr).and_return(stderr_io)
|
77
|
+
generator
|
78
|
+
end
|
79
|
+
|
80
|
+
it "prints usage when args are empty" do
|
81
|
+
with_argv([]).run
|
82
|
+
expect(stdout_io.string).to eq(expected_help_message)
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when given the name of the cookbook to generate" do
|
88
|
+
|
89
|
+
let(:argv) { %w[new_cookbook] }
|
90
|
+
|
91
|
+
before do
|
92
|
+
reset_tempdir
|
93
|
+
end
|
94
|
+
|
95
|
+
it "configures the generator context" do
|
96
|
+
cookbook_generator.read_and_validate_params
|
97
|
+
cookbook_generator.setup_context
|
98
|
+
expect(generator_context.cookbook_root).to eq(Dir.pwd)
|
99
|
+
expect(generator_context.cookbook_name).to eq("new_cookbook")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "creates a new cookbook" do
|
103
|
+
Dir.chdir(tempdir) do
|
104
|
+
allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
|
105
|
+
cookbook_generator.run
|
106
|
+
end
|
107
|
+
generated_files = Dir.glob("#{tempdir}/new_cookbook/**/*", File::FNM_DOTMATCH)
|
108
|
+
expected_cookbook_files.each do |expected_file|
|
109
|
+
expect(generated_files).to include(expected_file)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
shared_examples_for "a generated file" do |context_var|
|
114
|
+
before do
|
115
|
+
Dir.chdir(tempdir) do
|
116
|
+
allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
|
117
|
+
cookbook_generator.run
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should contain #{context_var} from the generator context" do
|
122
|
+
expect(File.read(file)).to match line
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "README.md" do
|
127
|
+
let(:file) { File.join(tempdir, "new_cookbook", "README.md") }
|
128
|
+
|
129
|
+
include_examples "a generated file", :cookbook_name do
|
130
|
+
let(:line) { "# new_cookbook" }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe ".kitchen.yml" do
|
135
|
+
let(:file) { File.join(tempdir, "new_cookbook", ".kitchen.yml") }
|
136
|
+
|
137
|
+
include_examples "a generated file", :cookbook_name do
|
138
|
+
let(:line) { /\s*- recipe\[new_cookbook::default\]/ }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "metadata.rb" do
|
143
|
+
let(:file) { File.join(tempdir, "new_cookbook", "metadata.rb") }
|
144
|
+
|
145
|
+
include_examples "a generated file", :cookbook_name do
|
146
|
+
let(:line) { /name\s+'new_cookbook'/ }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "recipes/default.rb" do
|
151
|
+
let(:file) { File.join(tempdir, "new_cookbook", "recipes", "default.rb") }
|
152
|
+
|
153
|
+
include_examples "a generated file", :cookbook_name do
|
154
|
+
let(:line) { "# Cookbook Name:: new_cookbook" }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
context "when given the path to the cookbook to generate" do
|
161
|
+
let(:argv) { [ File.join(tempdir, "a_new_cookbook") ] }
|
162
|
+
|
163
|
+
before do
|
164
|
+
reset_tempdir
|
165
|
+
end
|
166
|
+
|
167
|
+
it "configures the generator context" do
|
168
|
+
cookbook_generator.read_and_validate_params
|
169
|
+
cookbook_generator.setup_context
|
170
|
+
expect(generator_context.cookbook_root).to eq(tempdir)
|
171
|
+
expect(generator_context.cookbook_name).to eq("a_new_cookbook")
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
context "when given a generator-cookbook path" do
|
177
|
+
let(:generator_cookbook_path) { File.join(tempdir, 'a_generator_cookbook') }
|
178
|
+
let(:argv) { ["new_cookbook", "--generator-cookbook", generator_cookbook_path] }
|
179
|
+
|
180
|
+
before do
|
181
|
+
reset_tempdir
|
182
|
+
end
|
183
|
+
|
184
|
+
it "configures the generator context" do
|
185
|
+
cookbook_generator.read_and_validate_params
|
186
|
+
cookbook_generator.setup_context
|
187
|
+
expect(generator_context.cookbook_root).to eq(Dir.pwd)
|
188
|
+
expect(generator_context.cookbook_name).to eq("new_cookbook")
|
189
|
+
expect(cookbook_generator.chef_runner.cookbook_path).to eq(generator_cookbook_path)
|
190
|
+
end
|
191
|
+
|
192
|
+
it "creates a new cookbook" do
|
193
|
+
Dir.chdir(tempdir) do
|
194
|
+
allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
|
195
|
+
cookbook_generator.run
|
196
|
+
end
|
197
|
+
generated_files = Dir.glob("#{tempdir}/new_cookbook/**/*", File::FNM_DOTMATCH)
|
198
|
+
expected_cookbook_files.each do |expected_file|
|
199
|
+
expect(generated_files).to include(expected_file)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
@@ -0,0 +1,32 @@
|
|
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 'spec_helper'
|
19
|
+
require 'shared/a_file_generator'
|
20
|
+
require 'chef-dk/command/generator_commands/lwrp'
|
21
|
+
|
22
|
+
describe ChefDK::Command::GeneratorCommands::LWRP do
|
23
|
+
|
24
|
+
include_examples "a file generator" do
|
25
|
+
|
26
|
+
let(:generator_name) { "lwrp" }
|
27
|
+
let(:generated_files) { [ "resources/new_lwrp.rb", "providers/new_lwrp.rb" ] }
|
28
|
+
let(:new_file_name) { "new_lwrp" }
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|