chef-gen-flavor-base 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.md +6 -0
- data/LICENSE +17 -0
- data/Manifest.txt +50 -0
- data/README.md +818 -0
- data/chef-gen-flavor-base.gemspec +84 -0
- data/lib/chef_gen/flavor_base.rb +185 -0
- data/lib/chef_gen/flavor_base/copy_helpers.rb +45 -0
- data/lib/chef_gen/flavor_base/resource_helpers.rb +110 -0
- data/lib/chef_gen/snippet/actions_taken.rb +82 -0
- data/lib/chef_gen/snippet/attributes.rb +35 -0
- data/lib/chef_gen/snippet/chef_spec.rb +121 -0
- data/lib/chef_gen/snippet/cookbook_base.rb +135 -0
- data/lib/chef_gen/snippet/debugging.rb +26 -0
- data/lib/chef_gen/snippet/example_file.rb +36 -0
- data/lib/chef_gen/snippet/example_template.rb +36 -0
- data/lib/chef_gen/snippet/git_init.rb +36 -0
- data/lib/chef_gen/snippet/guard.rb +70 -0
- data/lib/chef_gen/snippet/next_steps.rb +44 -0
- data/lib/chef_gen/snippet/no_clobber.rb +62 -0
- data/lib/chef_gen/snippet/recipes.rb +35 -0
- data/lib/chef_gen/snippet/resource_provider.rb +37 -0
- data/lib/chef_gen/snippet/standard_ignore.rb +85 -0
- data/lib/chef_gen/snippet/style_foodcritic.rb +73 -0
- data/lib/chef_gen/snippet/style_rubocop.rb +115 -0
- data/lib/chef_gen/snippet/style_tailor.rb +64 -0
- data/lib/chef_gen/snippet/test_kitchen.rb +129 -0
- data/lib/chef_gen/snippet_base.rb +46 -0
- data/lib/chef_gen/snippets.rb +24 -0
- data/shared/snippet/attributes/templates/default/attributes_default_rb.erb +8 -0
- data/shared/snippet/chef_spec/templates/default/_rspec.erb +2 -0
- data/shared/snippet/chef_spec/templates/default/spec_chef_runner_context_rb.erb +36 -0
- data/shared/snippet/chef_spec/templates/default/spec_recipes_default_spec_rb.erb +7 -0
- data/shared/snippet/chef_spec/templates/default/spec_spec_helper_rb.erb +95 -0
- data/shared/snippet/cookbook_base/templates/default/Berksfile.erb +12 -0
- data/shared/snippet/cookbook_base/templates/default/CHANGELOG_md.erb +5 -0
- data/shared/snippet/cookbook_base/templates/default/Gemfile.erb +18 -0
- data/shared/snippet/cookbook_base/templates/default/README_md.erb +92 -0
- data/shared/snippet/cookbook_base/templates/default/Rakefile.erb +20 -0
- data/shared/snippet/cookbook_base/templates/default/metadata_rb.erb +13 -0
- data/shared/snippet/example_file/files/default/files_default_example_conf +34 -0
- data/shared/snippet/example_template/files/default/templates_default_example_conf_erb +22 -0
- data/shared/snippet/guard/templates/default/Guardfile.erb +16 -0
- data/shared/snippet/recipes/templates/default/recipes_default_rb.erb +9 -0
- data/shared/snippet/resource_provider/templates/default/providers_default_rb.erb +20 -0
- data/shared/snippet/resource_provider/templates/default/resources_default_rb.erb +9 -0
- data/shared/snippet/style_rubocop/templates/default/_rubocop_yml.erb +31 -0
- data/shared/snippet/test_kitchen/libraries/kitchen_helper.rb +13 -0
- data/shared/snippet/test_kitchen/templates/default/_kitchen_yml.erb +30 -0
- data/shared/snippet/test_kitchen/templates/default/test_integration_default_serverspec_recipes_default_spec_rb.erb +16 -0
- data/shared/snippet/test_kitchen/templates/default/test_integration_default_serverspec_spec_helper_rb.erb +7 -0
- metadata +372 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'chef_gen/snippet_base'
|
2
|
+
|
3
|
+
module ChefGen
|
4
|
+
module Snippet
|
5
|
+
# sets up style testing using Tailor
|
6
|
+
class StyleTailor < ChefGen::SnippetBase
|
7
|
+
# the name of the snippet
|
8
|
+
NAME = 'style_tailor'
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# initializes the snippet in generate mode
|
13
|
+
# @return [void]
|
14
|
+
# @api private
|
15
|
+
def initialize_generate
|
16
|
+
super
|
17
|
+
declare_cookbook_gems
|
18
|
+
declare_rake_tasks
|
19
|
+
end
|
20
|
+
|
21
|
+
# declares cookbook_gems if the flavor supports it
|
22
|
+
# @return [void]
|
23
|
+
# @api private
|
24
|
+
def declare_cookbook_gems
|
25
|
+
@flavor.class.do_declare_resources do
|
26
|
+
break unless snippet?('cookbook_base')
|
27
|
+
cookbook_gems['tailor'] = '~> 1.4'
|
28
|
+
cookbook_gems['guard-rake'] = '~> 0.0'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# declares rake tasks if the flavor supports it
|
33
|
+
# @return [void]
|
34
|
+
# @api private
|
35
|
+
def declare_rake_tasks
|
36
|
+
@flavor.class.do_declare_resources do
|
37
|
+
break unless snippet?('cookbook_base')
|
38
|
+
rake_tasks['tailor'] = <<'END'
|
39
|
+
require 'tailor/rake_task'
|
40
|
+
Tailor::RakeTask.new do |t|
|
41
|
+
{
|
42
|
+
spec: 'spec/recipes/*_spec.rb',
|
43
|
+
spec_helper: 'spec/spec_helper.rb',
|
44
|
+
attributes: 'attributes/*.rb',
|
45
|
+
resources: 'resources/*.rb',
|
46
|
+
providers: 'providers/*.rb',
|
47
|
+
libraries: 'libraries/**/*.rb',
|
48
|
+
recipes: 'recipes/*.rb',
|
49
|
+
metadata: 'metadata.rb'
|
50
|
+
}.each do |name, glob|
|
51
|
+
t.file_set glob, name do |s|
|
52
|
+
s.max_line_length 1000
|
53
|
+
s.max_code_lines_in_method 1000
|
54
|
+
s.max_code_lines_in_class 1000
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
task style: :tailor
|
59
|
+
END
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'chef_gen/snippet_base'
|
2
|
+
|
3
|
+
module ChefGen
|
4
|
+
module Snippet
|
5
|
+
# creates a framework for Test Kitchen integration testing
|
6
|
+
class TestKitchen < ChefGen::SnippetBase
|
7
|
+
# the name of the snippet
|
8
|
+
NAME = 'test_kitchen'
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# initializes the snippet in setup mode
|
13
|
+
# @return [void]
|
14
|
+
# @api private
|
15
|
+
def initialize_setup
|
16
|
+
super
|
17
|
+
snippet_content_path = File.expand_path(File.join(static_content_path(__FILE__))) + '/.'
|
18
|
+
@flavor.class.do_add_content do
|
19
|
+
tocopy << [snippet_content_path]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# initializes the snippet in generate mode
|
24
|
+
# @return [void]
|
25
|
+
def initialize_generate
|
26
|
+
super
|
27
|
+
declare_directories
|
28
|
+
declare_files_templates
|
29
|
+
declare_chefignore_patterns
|
30
|
+
declare_gitignore_patterns
|
31
|
+
declare_cookbook_gems
|
32
|
+
declare_rake_tasks
|
33
|
+
end
|
34
|
+
|
35
|
+
# declares directories
|
36
|
+
# @return [void]
|
37
|
+
# @api private
|
38
|
+
def declare_directories
|
39
|
+
@flavor.class.do_declare_resources do
|
40
|
+
directories << 'test'
|
41
|
+
directories << File.join('test', 'integration')
|
42
|
+
directories << File.join('test', 'integration', 'default')
|
43
|
+
directories << File.join(
|
44
|
+
'test', 'integration', 'default', 'serverspec'
|
45
|
+
)
|
46
|
+
directories << File.join(
|
47
|
+
'test', 'integration', 'default', 'serverspec', 'recipes'
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# declares files and templates
|
53
|
+
# @return [void]
|
54
|
+
# @api private
|
55
|
+
def declare_files_templates
|
56
|
+
@flavor.class.do_declare_resources do
|
57
|
+
templates_if_missing << '.kitchen.yml'
|
58
|
+
templates_if_missing << File.join(
|
59
|
+
'test', 'integration', 'default', 'serverspec', 'spec_helper.rb'
|
60
|
+
)
|
61
|
+
templates_if_missing << File.join(
|
62
|
+
'test', 'integration', 'default', 'serverspec',
|
63
|
+
'recipes', 'default_spec.rb'
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# declares chefignore patterns if the flavor supports it
|
69
|
+
# @return [void]
|
70
|
+
# @api private
|
71
|
+
def declare_chefignore_patterns
|
72
|
+
@flavor.class.do_declare_resources do
|
73
|
+
break unless snippet?('standard_ignore')
|
74
|
+
%w(
|
75
|
+
.vagrant .kitchen/* .kitchen.local.yml
|
76
|
+
).each do |e|
|
77
|
+
chefignore_patterns << e
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# declares .gitignore patterns if the flavor supports it
|
83
|
+
# @return [void]
|
84
|
+
# @api private
|
85
|
+
def declare_gitignore_patterns
|
86
|
+
@flavor.class.do_declare_resources do
|
87
|
+
break unless snippet?('standard_ignore')
|
88
|
+
%w(
|
89
|
+
.vagrant .kitchen/* .kitchen.local.yml
|
90
|
+
).each do |e|
|
91
|
+
gitignore_patterns << e
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# declares cookbook_gems if the flavor supports it
|
97
|
+
# @return [void]
|
98
|
+
# @api private
|
99
|
+
def declare_cookbook_gems
|
100
|
+
@flavor.class.do_declare_resources do
|
101
|
+
break unless snippet?('cookbook_base')
|
102
|
+
cookbook_gems['test-kitchen'] = '~> 1.4'
|
103
|
+
cookbook_gems['kitchen-vagrant'] = '~> 0.16'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# declares rake tasks if the flavor supports it
|
108
|
+
# @return [void]
|
109
|
+
# @api private
|
110
|
+
def declare_rake_tasks
|
111
|
+
@flavor.class.do_declare_resources do
|
112
|
+
break unless snippet?('cookbook_base')
|
113
|
+
rake_tasks['testkitchen'] = <<'END'
|
114
|
+
begin
|
115
|
+
require 'kitchen/rake_tasks'
|
116
|
+
Kitchen::RakeTasks.new
|
117
|
+
rescue
|
118
|
+
desc 'placeholder Test Kitchen task when plugins are missing'
|
119
|
+
task 'kitchen:all' do
|
120
|
+
puts 'test-kitchen plugins not installed; this is a placeholder task'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
task integration: 'kitchen:all'
|
124
|
+
END
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ChefGen
|
2
|
+
# a base for ChefDK Template Flavor Snippets
|
3
|
+
class SnippetBase
|
4
|
+
# @overload initialize(flavor)
|
5
|
+
# initializes the snippet in setup mode
|
6
|
+
# @param [ChefGen::FlavorBase] flavor the flavor object
|
7
|
+
# @return [self]
|
8
|
+
# @overload initialize(flavor, recipe)
|
9
|
+
# initializes the snippet in generate mode
|
10
|
+
# @param [ChefGen::FlavorBase] flavor the flavor object
|
11
|
+
# @param [Chef::Recipe] recipe the recipe object
|
12
|
+
# @return [self]
|
13
|
+
def initialize(flavor: nil, recipe: nil)
|
14
|
+
@recipe = recipe
|
15
|
+
@flavor = flavor
|
16
|
+
initialize_setup if flavor.setup_mode?
|
17
|
+
initialize_generate if flavor.generate_mode?
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# @abstract declare {#initialize_setup} to add setup behaviour
|
23
|
+
# @return [void]
|
24
|
+
# @api private
|
25
|
+
def initialize_setup
|
26
|
+
end
|
27
|
+
|
28
|
+
# @abstract declare {#initialize_generate} to add setup behaviour
|
29
|
+
# @return [void]
|
30
|
+
# @api private
|
31
|
+
def initialize_generate
|
32
|
+
end
|
33
|
+
|
34
|
+
# returns the path to static content distributed with a snippet
|
35
|
+
# @param file [String] the file to generate the path from
|
36
|
+
# @return [String] the path the static content relative to the file
|
37
|
+
# @api private
|
38
|
+
def static_content_path(file)
|
39
|
+
File.expand_path(
|
40
|
+
File.join(
|
41
|
+
File.dirname(file), '..', '..', '..', 'shared', 'snippet', self.class::NAME
|
42
|
+
)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Chef Cookbook Generation tools
|
2
|
+
module ChefGen
|
3
|
+
# template snippets that flavors can compose to do common things
|
4
|
+
module Snippet
|
5
|
+
autoload :Attributes, 'chef_gen/snippet/attributes'
|
6
|
+
autoload :ActionsTaken, 'chef_gen/snippet/actions_taken'
|
7
|
+
autoload :ChefSpec, 'chef_gen/snippet/chef_spec'
|
8
|
+
autoload :CookbookBase, 'chef_gen/snippet/cookbook_base'
|
9
|
+
autoload :Debugging, 'chef_gen/snippet/debugging'
|
10
|
+
autoload :ExampleFile, 'chef_gen/snippet/example_file'
|
11
|
+
autoload :ExampleTemplate, 'chef_gen/snippet/example_template'
|
12
|
+
autoload :GitInit, 'chef_gen/snippet/git_init'
|
13
|
+
autoload :Guard, 'chef_gen/snippet/guard'
|
14
|
+
autoload :NextSteps, 'chef_gen/snippet/next_steps'
|
15
|
+
autoload :NoClobber, 'chef_gen/snippet/no_clobber'
|
16
|
+
autoload :Recipes, 'chef_gen/snippet/recipes'
|
17
|
+
autoload :ResourceProvider, 'chef_gen/snippet/resource_provider'
|
18
|
+
autoload :StandardIgnore, 'chef_gen/snippet/standard_ignore'
|
19
|
+
autoload :StyleFoodcritic, 'chef_gen/snippet/style_foodcritic'
|
20
|
+
autoload :StyleRubocop, 'chef_gen/snippet/style_rubocop'
|
21
|
+
autoload :StyleTailor, 'chef_gen/snippet/style_tailor'
|
22
|
+
autoload :TestKitchen, 'chef_gen/snippet/test_kitchen'
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rspec/core/shared_context'
|
2
|
+
|
3
|
+
# this is a 'standard' chef run, with no overrides
|
4
|
+
module ChefRun
|
5
|
+
extend RSpec::Core::SharedContext
|
6
|
+
|
7
|
+
let(:chef_run) do
|
8
|
+
ChefSpec::ServerRunner.new.converge(described_recipe)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# the following are commented out to save memory
|
13
|
+
# they show how you can set up alternate Chef Runners that
|
14
|
+
# override the node's chef environment or other attributes
|
15
|
+
# module ChefRunTestEnv
|
16
|
+
# extend RSpec::Core::SharedContext
|
17
|
+
#
|
18
|
+
# let(:chef_run) do
|
19
|
+
# ChefSpec::ServerRunner.new do |node, server|
|
20
|
+
# server.create_environment('<%= cookbook_name %>-test')
|
21
|
+
# node.chef_environment = '<%= cookbook_name %>-test'
|
22
|
+
# server.create_node(node)
|
23
|
+
# end.converge(described_recipe)
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# # a chef run where node attributes are overriden
|
28
|
+
# module ChefRunOverrideAttrs
|
29
|
+
# extend RSpec::Core::SharedContext
|
30
|
+
#
|
31
|
+
# let(:chef_run) do
|
32
|
+
# ChefSpec::ServerRunner.new do |node|
|
33
|
+
# node.set['<%= cookbook_name %>']['foobar'] = true
|
34
|
+
# end.converge(described_recipe)
|
35
|
+
# end
|
36
|
+
# end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'chefspec'
|
2
|
+
require 'chefspec/berkshelf'
|
3
|
+
require 'chef_runner_context'
|
4
|
+
|
5
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
6
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
7
|
+
# The generated `.rspec` file contains `--require spec_helper` which will
|
8
|
+
# cause this file to always be loaded, without a need to explicitly require
|
9
|
+
# it in any files.
|
10
|
+
#
|
11
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
12
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
13
|
+
# will add to the boot time of your test suite on EVERY test run, even for
|
14
|
+
# an individual file that may not need all of that loaded. Instead, consider
|
15
|
+
# making a separate helper file that requires the additional dependencies
|
16
|
+
# and performs the additional setup, and require it from the spec files that
|
17
|
+
# actually need it.
|
18
|
+
#
|
19
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
20
|
+
# users commonly want.
|
21
|
+
#
|
22
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
23
|
+
RSpec.configure do |config|
|
24
|
+
# rspec-expectations config goes here. You can use an alternate
|
25
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
26
|
+
# assertions if you prefer.
|
27
|
+
config.expect_with :rspec do |expectations|
|
28
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
29
|
+
# and `failure_message` of custom matchers include text for helper methods
|
30
|
+
# defined using `chain`, e.g.:
|
31
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
32
|
+
# # => "be bigger than 2 and smaller than 4"
|
33
|
+
# ...rather than:
|
34
|
+
# # => "be bigger than 2"
|
35
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
36
|
+
end
|
37
|
+
|
38
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
39
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
40
|
+
config.mock_with :rspec do |mocks|
|
41
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
42
|
+
# a real object. This is generally recommended, and will default to
|
43
|
+
# `true` in RSpec 4.
|
44
|
+
mocks.verify_partial_doubles = true
|
45
|
+
end
|
46
|
+
|
47
|
+
# The settings below are suggested to provide a good initial experience
|
48
|
+
# with RSpec, but feel free to customize to your heart's content.
|
49
|
+
# These two settings work together to allow you to limit a spec run
|
50
|
+
# to individual examples or groups you care about by tagging them with
|
51
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
52
|
+
# get run.
|
53
|
+
config.filter_run :focus
|
54
|
+
config.run_all_when_everything_filtered = true
|
55
|
+
|
56
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
57
|
+
# recommended. For more details, see:
|
58
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
59
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
60
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
61
|
+
config.disable_monkey_patching!
|
62
|
+
|
63
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
64
|
+
# be too noisy due to issues in dependencies.
|
65
|
+
config.warnings = false
|
66
|
+
|
67
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
68
|
+
# file, and it's useful to allow more verbose output when running an
|
69
|
+
# individual spec file.
|
70
|
+
if config.files_to_run.one?
|
71
|
+
# Use the documentation formatter for detailed output,
|
72
|
+
# unless a formatter has already been configured
|
73
|
+
# (e.g. via a command-line flag).
|
74
|
+
config.default_formatter = 'doc'
|
75
|
+
end
|
76
|
+
|
77
|
+
# Print the 10 slowest examples and example groups at the
|
78
|
+
# end of the spec run, to help surface which specs are running
|
79
|
+
# particularly slow.
|
80
|
+
config.profile_examples = 10
|
81
|
+
|
82
|
+
# Run specs in random order to surface order dependencies. If you find an
|
83
|
+
# order dependency and want to debug it, you can fix the order by providing
|
84
|
+
# the seed, which is printed after each run.
|
85
|
+
# --seed 1234
|
86
|
+
config.order = :random
|
87
|
+
|
88
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
89
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
90
|
+
# test failures related to randomization by passing the same `--seed` value
|
91
|
+
# as the one that triggered the failure.
|
92
|
+
Kernel.srand config.seed
|
93
|
+
end
|
94
|
+
|
95
|
+
ChefSpec::Coverage.start! if ENV['COVERAGE']
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<% @sources.each do |source| -%>
|
2
|
+
source '<%= source %>'
|
3
|
+
<% end -%>
|
4
|
+
|
5
|
+
metadata
|
6
|
+
|
7
|
+
# load local overrides
|
8
|
+
berksfile_dir = File.absolute_path(File.join('.', 'lib', 'berksfile'))
|
9
|
+
Dir.glob(File.join(berksfile_dir, '*.berks')).each do |snippet|
|
10
|
+
# rubocop:disable Lint/Eval
|
11
|
+
eval File.read(snippet), nil, snippet
|
12
|
+
end
|