chef-gen-flavors 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/ARUBA_STEPS.md +74 -0
  3. data/History.md +16 -0
  4. data/Manifest.txt +25 -30
  5. data/README.md +121 -16
  6. data/chef-gen-flavors.gemspec +8 -5
  7. data/lib/chef_gen/flavor_base.rb +42 -34
  8. data/lib/chef_gen/flavors.rb +36 -10
  9. data/lib/chef_gen/snippet/attributes.rb +13 -0
  10. data/lib/chef_gen/snippet/chef_spec.rb +84 -14
  11. data/lib/chef_gen/snippet/cookbook_base.rb +109 -23
  12. data/lib/chef_gen/snippet/example_file.rb +15 -0
  13. data/lib/chef_gen/snippet/example_template.rb +15 -0
  14. data/lib/chef_gen/snippet/git_init.rb +2 -0
  15. data/lib/chef_gen/snippet/recipes.rb +15 -0
  16. data/lib/chef_gen/snippet/resource_provider.rb +18 -0
  17. data/lib/chef_gen/snippet/standard_ignore.rb +56 -80
  18. data/lib/chef_gen/snippet/style_foodcritic.rb +51 -0
  19. data/lib/chef_gen/snippet/style_rubocop.rb +80 -0
  20. data/lib/chef_gen/snippet/style_tailor.rb +48 -0
  21. data/lib/chef_gen/snippet/test_kitchen.rb +70 -15
  22. data/lib/chef_gen/snippets.rb +2 -0
  23. data/shared/snippet/attributes/attributes_default_rb.erb +8 -0
  24. data/{.rspec → shared/snippet/chef_spec/_rspec.erb} +0 -0
  25. data/shared/snippet/chef_spec/spec_chef_runner_context_rb.erb +36 -0
  26. data/shared/snippet/chef_spec/spec_recipes_default_spec_rb.erb +7 -0
  27. data/shared/snippet/chef_spec/spec_spec_helper_rb.erb +95 -0
  28. data/shared/snippet/cookbookbase/Berksfile.erb +5 -0
  29. data/shared/snippet/cookbookbase/CHANGELOG_md.erb +5 -0
  30. data/shared/snippet/cookbookbase/Gemfile.erb +7 -0
  31. data/shared/snippet/cookbookbase/Guardfile.erb +10 -0
  32. data/shared/snippet/cookbookbase/README_md.erb +92 -0
  33. data/shared/snippet/cookbookbase/Rakefile.erb +20 -0
  34. data/shared/snippet/cookbookbase/metadata_rb.erb +10 -0
  35. data/shared/snippet/examplefile/files_default_example_conf +34 -0
  36. data/shared/snippet/exampletemplate/templates_default_example_conf_erb +22 -0
  37. data/shared/snippet/recipes/recipes_default_rb.erb +9 -0
  38. data/shared/snippet/resourceprovider/providers_default_rb.erb +20 -0
  39. data/shared/snippet/resourceprovider/resources_default_rb.erb +9 -0
  40. data/shared/snippet/stylerubocop/_rubocop_yml.erb +27 -0
  41. data/shared/snippet/testkitchen/_kitchen_yml.erb +30 -0
  42. data/shared/snippet/testkitchen/libraries_kitchen_helper_rb +13 -0
  43. data/shared/snippet/testkitchen/test_integration_default_serverspec_recipes_default_spec_rb.erb +16 -0
  44. data/shared/snippet/testkitchen/test_integration_default_serverspec_spec_helper_rb.erb +7 -0
  45. metadata +42 -32
  46. data/.rubocop.yml +0 -27
  47. data/.travis.yml +0 -6
  48. data/Gemfile +0 -3
  49. data/Guardfile +0 -15
  50. data/Rakefile +0 -98
  51. data/features/generate.feature +0 -17
  52. data/features/support/env.rb +0 -15
  53. data/spec/lib/chef_gen/flavor_base_spec.rb +0 -167
  54. data/spec/lib/chef_gen/flavors_spec.rb +0 -132
  55. data/spec/lib/chef_gen/snippet/attributes_spec.rb +0 -40
  56. data/spec/lib/chef_gen/snippet/chef_spec_spec.rb +0 -40
  57. data/spec/lib/chef_gen/snippet/cookbook_base_spec.rb +0 -32
  58. data/spec/lib/chef_gen/snippet/example_file_spec.rb +0 -40
  59. data/spec/lib/chef_gen/snippet/example_template_spec.rb +0 -40
  60. data/spec/lib/chef_gen/snippet/git_init_spec.rb +0 -30
  61. data/spec/lib/chef_gen/snippet/recipes_spec.rb +0 -40
  62. data/spec/lib/chef_gen/snippet/resource_provider_spec.rb +0 -40
  63. data/spec/lib/chef_gen/snippet/standard_ignore_spec.rb +0 -35
  64. data/spec/lib/chef_gen/snippet/style_rubocop_spec.rb +0 -31
  65. data/spec/lib/chef_gen/snippet/test_kitchen_spec.rb +0 -44
  66. data/spec/spec_helper.rb +0 -64
  67. data/spec/support/fixtures/code_generator/metadata.rb +0 -2
  68. data/spec/support/fixtures/code_generator/recipes/cookbook.rb +0 -1
  69. data/spec/support/fixtures/code_generator_2/metadata.rb +0 -2
  70. data/spec/support/fixtures/code_generator_2/recipes/cookbook.rb +0 -3
  71. data/spec/support/fixtures/code_generator_2/templates/default/README_md.erb +0 -1
  72. data/spec/support/fixtures/lib/chef_gen/flavor/bar.rb +0 -21
  73. data/spec/support/fixtures/lib/chef_gen/flavor/baz.rb +0 -6
  74. data/spec/support/fixtures/lib/chef_gen/flavor/foo.rb +0 -9
@@ -10,6 +10,8 @@ module ChefGen
10
10
  autoload :ResourceProvider, 'chef_gen/snippet/resource_provider'
11
11
  autoload :StandardIgnore, 'chef_gen/snippet/standard_ignore'
12
12
  autoload :StyleRubocop, 'chef_gen/snippet/style_rubocop'
13
+ autoload :StyleTailor, 'chef_gen/snippet/style_tailor'
14
+ autoload :StyleFoodcritic, 'chef_gen/snippet/style_foodcritic'
13
15
  autoload :TestKitchen, 'chef_gen/snippet/test_kitchen'
14
16
  autoload :GitInit, 'chef_gen/snippet/git_init'
15
17
  end
@@ -0,0 +1,8 @@
1
+ #
2
+ # Cookbook <%= cookbook_name %>
3
+ # Copyright (c) <%= year %> <%= copyright_holder %>
4
+ #
5
+
6
+ # replace these with something real
7
+ default['<%= cookbook_name %>']['attribute_1'] = 'foo'
8
+ default['<%= cookbook_name %>']['attribute_2'] = 'bar'
File without changes
@@ -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,7 @@
1
+ RSpec.describe '<%= cookbook_name %>::default' do
2
+ include ChefRun
3
+
4
+ it 'converges successfully' do
5
+ expect(chef_run).to include_recipe(described_recipe)
6
+ end
7
+ 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,5 @@
1
+ <% @sources.each do |source| -%>
2
+ source '<%= source %>'
3
+ <% end -%>
4
+
5
+ metadata
@@ -0,0 +1,5 @@
1
+ # Revision History for <%= cookbook_name %>
2
+
3
+ ## 0.1.0
4
+
5
+ * initial version
@@ -0,0 +1,7 @@
1
+ <% @sources.each do |source| -%>
2
+ source '<%= source %>'
3
+ <% end -%>
4
+
5
+ <% @gems.each do |gem, constraint| -%>
6
+ gem '<%= gem %>', '<%= constraint %>'
7
+ <% end -%>
@@ -0,0 +1,10 @@
1
+ notification :terminal_title
2
+
3
+ # prevent dropping into pry when nothing is happening
4
+ interactor :off
5
+
6
+ <% @guards.each do |name, guard| -%>
7
+ # <%= name %>
8
+ <%= guard %>
9
+
10
+ <% end -%>
@@ -0,0 +1,92 @@
1
+ # <%= cookbook_name %>
2
+
3
+ ## Description
4
+
5
+ ...
6
+
7
+ ## Usage
8
+
9
+ Add 'recipe[<%= cookbook_name %>::default]' to your node's run-list.
10
+
11
+ ## Recipes
12
+
13
+ ### default
14
+
15
+ The default recipe ...
16
+
17
+ ## Attributes
18
+
19
+ The attributes defined by this recipe are organized under the
20
+ `node['<%= cookbook_name %>']` namespace.
21
+
22
+ Attribute | Description | Type | Default
23
+ ----------|-------------|--------|--------
24
+ ... | ... | String | ...
25
+
26
+ ## Development
27
+
28
+ The first time you check out this cookbook, run
29
+
30
+ bundle --binstubs
31
+
32
+ to download and install the development tools.
33
+
34
+ ## Testing
35
+
36
+ Three forms of cookbook testing are available:
37
+
38
+ ### Style Checks
39
+
40
+ bin/rake style
41
+
42
+ Will run foodcritic (cookbook style) and tailor (ruby style/syntax)
43
+ checks. These tests must pass before the cookbook can progress
44
+ through the CI pipeline.
45
+
46
+ ### Unit Tests
47
+
48
+ bin/rake spec
49
+
50
+ Will run ChefSpec tests. It is a good idea to ensure that these
51
+ tests pass before committing changes to git.
52
+
53
+ #### Unit Test Coverage
54
+
55
+ bin/rake coverage
56
+
57
+ Will run the ChefSpec tests and report on test coverage. It is a
58
+ good idea to make sure that every Chef resource you declare is covered
59
+ by a unit test.
60
+
61
+ #### Automated Testing with Guard
62
+
63
+ bin/guard
64
+
65
+ Will run foodcritic, tailor, rubocop (if enabled) and chefspec tests
66
+ automatically when the associated files change. If a chefspec test
67
+ fails, it will drop you into a pry session in the context of the
68
+ failure to explore the state of the run.
69
+
70
+ To disable the pry-rescue behavior, define the environment variable
71
+ DISABLE_PRY_RESCUE before running guard:
72
+
73
+ DISABLE_PRY_RESCUE=1 bin/guard
74
+
75
+ ### Integration Tests
76
+
77
+ bin/rake kitchen:all
78
+
79
+ Will run the test kitchen integration tests. These tests use Vagrant
80
+ and Virtualbox, which must be installed for the tests to execute.
81
+
82
+ After converging in a virtual machine, ServerSpec tests are executed.
83
+ This skeleton comes with a very basic ServerSpec test; refer to
84
+ http://serverspec.org for detail on how to create tests.
85
+
86
+ ## Author
87
+
88
+ <%= copyright_holder %>
89
+
90
+ ## License
91
+
92
+ <%= license_description %>
@@ -0,0 +1,20 @@
1
+ desc 'runs style tests'
2
+ task style: []
3
+
4
+ desc 'runs unit tests'
5
+ task spec: []
6
+
7
+ desc 'runs integration tests'
8
+ task integration: []
9
+
10
+ desc 'runs style and unit tests'
11
+ task test: [:style, :spec]
12
+
13
+ desc 'runs all tests'
14
+ task default: :test
15
+
16
+ <% @tasks.each do |name, task| -%>
17
+ # <%= name %>
18
+ <%= task %>
19
+
20
+ <% end -%>
@@ -0,0 +1,10 @@
1
+ #
2
+ # Copyright (c) <%= year %> <%= copyright_holder %>
3
+ #
4
+
5
+ name '<%= cookbook_name %>'
6
+ maintainer '<%= copyright_holder %>'
7
+ maintainer_email '<%= email %>'
8
+ license '<%= license %>'
9
+ description 'Installs/Configures <%= cookbook_name %>'
10
+ version '0.1.0'
@@ -0,0 +1,34 @@
1
+ # this is an example of a Chef cookbook file. It is
2
+ # copied intact when referenced by the cookbook_file
3
+ # resource.
4
+
5
+ [today_2014_09_17]
6
+ variable = value
7
+
8
+ [section_two]
9
+ variable_1=value_1
10
+ variable_2=value_2
11
+ variable_3=value_3
12
+ variable_4=value_4
13
+ variable_5=value_5
14
+
15
+ [section_three]
16
+ variable_1=value_1
17
+ variable_2=value_2
18
+ variable_3=value_3
19
+ variable_4=value_4
20
+ variable_5=value_5
21
+
22
+ [section_four]
23
+ variable_1=value_1
24
+ variable_2=value_2
25
+ variable_3=value_3
26
+ variable_4=value_4
27
+ variable_5=value_5
28
+
29
+ [section_five]
30
+ variable_1=value_1
31
+ variable_2=value_2
32
+ variable_3=value_3
33
+ variable_4=value_4
34
+ variable_5=value_5
@@ -0,0 +1,22 @@
1
+ # this is an example of a Chef template. It is a simple
2
+ # INI-style file. The first section name is dynamically
3
+ # generated to be the current date in YYYY_MM_DD format
4
+ # and the second through fifth sections are generated in
5
+ # an 'each' loop.
6
+ #
7
+ # note that ending an ERB tag with -% instead of just %,
8
+ # that line doesn't produce an empty line in the output.
9
+ # Use this syntax on lines that are pure logic (like the
10
+ # require line and start and end of the loop) and contain
11
+ # no actual output
12
+
13
+ <% require 'date' -%>
14
+ [today_<%= DateTime.now.strftime('%Y_%M_%D') %>]
15
+ variable = value
16
+
17
+ <% %w(two three four five).each do |section_name| -%>
18
+ [<%= section_name %>]
19
+ <% 5.times do |i| -%>
20
+ variable_<%= i %>=value_<%= i %>
21
+ <% end -%>
22
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ #
2
+ # Recipe: <%= cookbook_name %>::default
3
+ # Copyright (c) <%= year %> <%= copyright_holder %>
4
+ #
5
+
6
+ # a common pattern is to seperate the cookbook into distinct
7
+ # recipes and pull them all in via the default recipe
8
+ # include_recipe '<%= cookbook_name %>::recipe_a'
9
+ # include_recipe '<%= cookbook_name %>::recipe_b'
@@ -0,0 +1,20 @@
1
+ #
2
+ # Resource: <%= cookbook_name %>
3
+ # Copyright (c) <%= year %> <%= copyright_holder %>
4
+ #
5
+
6
+ use_inline_resources
7
+
8
+ def whyrun_supported?
9
+ true
10
+ end
11
+
12
+ action :create do
13
+ converge_by 'create a <%= cookbook_name %>' do
14
+ end
15
+ end
16
+
17
+ action :delete do
18
+ converge_by 'delete a <%= cookbook_name %>' do
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ #
2
+ # Provider: <%= cookbook_name %>
3
+ # Copyright (c) <%= year %> <%= copyright_holder %>
4
+ #
5
+
6
+ actions :create, :delete
7
+ default_action :create
8
+
9
+ attribute :name, kind_of: String, name_attribute: true
@@ -0,0 +1,27 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'vendor/**/*'
4
+
5
+ Style/SingleSpaceBeforeFirstArg:
6
+ Exclude:
7
+ - '**/Berksfile'
8
+ - '**/metadata.rb'
9
+
10
+ Style/FileName:
11
+ Exclude:
12
+ - '**/Gemfile'
13
+ - '**/Berksfile'
14
+
15
+ Style/RegexpLiteral:
16
+ Exclude:
17
+ - '**/Guardfile'
18
+
19
+ Style/EmptyLines:
20
+ Exclude:
21
+ - '**/Guardfile'
22
+ - '**/Rakefile'
23
+
24
+ Style/TrailingBlankLines:
25
+ Exclude:
26
+ - '**/Guardfile'
27
+ - '**/Rakefile'