kitchen-config 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ab2d713ae72df3a263f9e2f1ebef54ca3c4a254
4
+ data.tar.gz: 8bdbec32e26e2f48eefaf493a6eb5116abb13c65
5
+ SHA512:
6
+ metadata.gz: 04995f258e0237a58654ab89b6cf01e3772a1781b0d555e1c5887f38ca909de5a1fcedafaa818a759855bca2c139d861e7b13107f69d7117b7f4385b522930f4
7
+ data.tar.gz: 9f81f09933df60e06aa9889502188287ac6caee7d9bbb6039f807511db6b6b8e2749860ab0b9424ba828f36fa6c106f870f731c456dc763750f00f236349f266
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ screenlog*
18
+ *.swp*
19
+ .kitchen/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ # LineLength can be greater than 80 characters
2
+ Metrics/LineLength:
3
+ Enabled: false
4
+
5
+ AllCops:
6
+ Exclude:
7
+ - 'chef_repo/**/*'
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ - 2.1.0
5
+ addons:
6
+ code_climate:
7
+ repo_token: 51b75c40638d400d9a0a96c199f6675c3149cecf164b7922a8fa835e7c6
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chef-config.gemspec
4
+ #
5
+ gemspec
6
+
7
+ group :test, :development do
8
+ gem 'simplecov', require: false
9
+ gem 'simplecov-rcov', require: false
10
+ gem 'rubocop', require: false
11
+ gem 'guard', require: false
12
+ gem 'rspec', require: false
13
+ gem 'rspec-core', require: false
14
+ gem 'codeclimate-test-reporter', require: false
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,100 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kitchen-config (0.1.1)
5
+ term-ansicolor
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.2.0)
11
+ codeclimate-test-reporter (0.5.0)
12
+ simplecov (>= 0.7.1, < 1.0.0)
13
+ coderay (1.1.1)
14
+ diff-lcs (1.2.5)
15
+ docile (1.1.5)
16
+ ffi (1.9.10)
17
+ formatador (0.2.5)
18
+ guard (2.13.0)
19
+ formatador (>= 0.2.4)
20
+ listen (>= 2.7, <= 4.0)
21
+ lumberjack (~> 1.0)
22
+ nenv (~> 0.1)
23
+ notiffany (~> 0.0)
24
+ pry (>= 0.9.12)
25
+ shellany (~> 0.0)
26
+ thor (>= 0.18.1)
27
+ json (1.8.3)
28
+ listen (3.0.6)
29
+ rb-fsevent (>= 0.9.3)
30
+ rb-inotify (>= 0.9.7)
31
+ lumberjack (1.0.10)
32
+ method_source (0.8.2)
33
+ nenv (0.3.0)
34
+ notiffany (0.0.8)
35
+ nenv (~> 0.1)
36
+ shellany (~> 0.0)
37
+ parser (2.3.0.6)
38
+ ast (~> 2.2)
39
+ powerpack (0.1.1)
40
+ pry (0.10.3)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.8.1)
43
+ slop (~> 3.4)
44
+ rainbow (2.1.0)
45
+ rake (11.1.0)
46
+ rb-fsevent (0.9.7)
47
+ rb-inotify (0.9.7)
48
+ ffi (>= 0.5.0)
49
+ rspec (3.4.0)
50
+ rspec-core (~> 3.4.0)
51
+ rspec-expectations (~> 3.4.0)
52
+ rspec-mocks (~> 3.4.0)
53
+ rspec-core (3.4.4)
54
+ rspec-support (~> 3.4.0)
55
+ rspec-expectations (3.4.0)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.4.0)
58
+ rspec-mocks (3.4.1)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.4.0)
61
+ rspec-support (3.4.1)
62
+ rubocop (0.38.0)
63
+ parser (>= 2.3.0.6, < 3.0)
64
+ powerpack (~> 0.1)
65
+ rainbow (>= 1.99.1, < 3.0)
66
+ ruby-progressbar (~> 1.7)
67
+ unicode-display_width (~> 1.0, >= 1.0.1)
68
+ ruby-progressbar (1.7.5)
69
+ shellany (0.0.1)
70
+ simplecov (0.11.2)
71
+ docile (~> 1.1.0)
72
+ json (~> 1.8)
73
+ simplecov-html (~> 0.10.0)
74
+ simplecov-html (0.10.0)
75
+ simplecov-rcov (0.2.3)
76
+ simplecov (>= 0.4.1)
77
+ slop (3.6.0)
78
+ term-ansicolor (1.3.2)
79
+ tins (~> 1.0)
80
+ thor (0.19.1)
81
+ tins (1.9.0)
82
+ unicode-display_width (1.0.2)
83
+
84
+ PLATFORMS
85
+ ruby
86
+
87
+ DEPENDENCIES
88
+ bundler (~> 1.5)
89
+ codeclimate-test-reporter
90
+ guard
91
+ kitchen-config!
92
+ rake
93
+ rspec
94
+ rspec-core
95
+ rubocop
96
+ simplecov
97
+ simplecov-rcov
98
+
99
+ BUNDLED WITH
100
+ 1.11.2
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
15
+ watch('spec/spec_helper.rb') { 'spec' }
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 craig
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+ [![Build Status](https://travis-ci.org/callmeradical/kitchen-config.svg?branch=master)](https://travis-ci.org/callmeradical/kitchen-config)
2
+ [![Code Climate](https://codeclimate.com/github/callmeradical/kitchen-config/badges/gpa.svg)](https://codeclimate.com/github/callmeradical/kitchen-config)
3
+ [![Test Coverage](https://codeclimate.com/github/callmeradical/kitchen-config/badges/coverage.svg)](https://codeclimate.com/github/callmeradical/kitchen-config/coverage)
4
+ # Kitchen::Config
5
+
6
+ Kitchen::Config handles initializing a new cookbook, and some deps.
7
+
8
+ ## Usage
9
+
10
+ This installs initialize_cookbook, which sets up your dev env for cookbooks.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ task default: :test
4
+ desc 'run rspec on this project'
5
+ task :test do
6
+ sh 'bundle exec rspec'
7
+ end
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+ require 'term/ansicolor'
3
+ include Term::ANSIColor
4
+
5
+ require 'kitchen/config'
6
+
7
+ @no_errs = true
8
+ ##
9
+ ## wrap some stuff around printing in colors
10
+ ##
11
+ def gputs(*stuff)
12
+ print green, bold, line_join(stuff), reset
13
+ end
14
+
15
+ def rputs(*stuff)
16
+ print red, bold, line_join(stuff), reset
17
+ end
18
+
19
+ def yputs(*stuff)
20
+ print yellow, ' - ' + line_join(stuff), reset
21
+ end
22
+
23
+ def line_join(*stuff)
24
+ stuff.join("\n") + "\n"
25
+ end
26
+
27
+ def run_cmd(cmd)
28
+ yputs cmd
29
+ @no_errs = system(cmd) && @no_errs
30
+ end
31
+
32
+ def usage
33
+ "Usage: initialize_cookbook <cookbook_name>
34
+ used to initialize a base cookbook with all the necessary development tools
35
+ all ready to go. <cookbook_name> is required.
36
+ "
37
+ end
38
+
39
+ def exit_usage
40
+ puts(usage)
41
+ exit
42
+ end
43
+
44
+ def exit_version
45
+ puts 'Kitchen::Config / initialize_cookbook v' + Kitchen::Config::VERSION
46
+ exit
47
+ end
48
+
49
+ ##
50
+ ## BEGIN
51
+ ##
52
+ name = ARGV.shift
53
+ copy_path = File.expand_path(File.dirname(__FILE__)).gsub('/bin', '/templates')
54
+ int_path = 'test/integration/default/serverspec'
55
+ files = {
56
+ 'Gemfile' => 'Gemfile',
57
+ 'Guardfile' => 'Guardfile',
58
+ '.kitchen.yml' => '.kitchen.yml',
59
+ '.rspec' => '.rspec',
60
+ 'spec_helper.rb' => 'spec/spec_helper.rb',
61
+ 'integration_spec_helper.rb' => "#{int_path}/spec_helper.rb",
62
+ 'default_spec.rb' => 'spec/recipes/default_spec.rb',
63
+ 'integration_default_spec.rb' => "#{int_path}/localhost/default_spec.rb",
64
+ '.gitignore' => '.gitignore',
65
+ 'Berksfile' => 'Berksfile',
66
+ 'metadata.rb' => 'metadata.rb',
67
+ 'Rakefile' => 'Rakefile',
68
+ 'Gemfile.serverspec' => "#{int_path}/Gemfile"
69
+ }
70
+
71
+ dirs = %w(
72
+ test
73
+ test/integration
74
+ test/integration/default
75
+ test/integration/default/serverspec
76
+ test/integration/default/serverspec/localhost
77
+ spec
78
+ spec/attributes
79
+ spec/libraries
80
+ spec/providers
81
+ spec/recipes
82
+ spec/resources
83
+ spec/templates
84
+ )
85
+
86
+ ##
87
+ ## start our run
88
+ ##
89
+
90
+ puts exit_usage if name.nil? || name == '' || name == '--help' || name == '-h'
91
+ puts exit_version if name == '--version' || name == '-v'
92
+ puts exit_usage unless name =~ /^[a-z_0-9]*$/
93
+
94
+ gputs "Initializing cookbook #{name}"
95
+ cmd = "berks cookbook #{name} --skip-vagrant"
96
+ run_cmd cmd
97
+
98
+ gputs "creating directory structure under #{name}"
99
+ dirs.each do |dir|
100
+ new_dir = "#{name}/#{dir}"
101
+ cmd = "mkdir #{new_dir}"
102
+ yputs cmd
103
+ if File.directory? new_dir.to_s
104
+ yputs "Directory #{new_dir} already exists... skipping."
105
+ else
106
+ Dir.mkdir new_dir.to_s
107
+ end
108
+ end
109
+
110
+ gputs "creating base files in #{name}"
111
+ files.each do |k, v|
112
+ yputs "creating #{copy_path}/#{k} #{name}/#{v}"
113
+ content = File.read("#{copy_path}/#{k}").gsub('COOKBOOK_NAME', name)
114
+ @no_errs = File.open("#{name}/#{v}", 'w') { |f| f.write(content) } && @no_errs
115
+ end
116
+
117
+ gputs 'Running bundler'
118
+ cmd = "cd #{name} && bundle install"
119
+ run_cmd cmd
120
+
121
+ ## finish up
122
+ if @no_errs
123
+ gputs 'Build Successful'
124
+ else
125
+ rputs 'There were build problems. Please read scroll.'
126
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kitchen/config/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kitchen-config'
8
+ spec.version = Kitchen::Config::VERSION
9
+ spec.authors = ['craig monson', 'lars cromley']
10
+ spec.email = ['craig@malachiarts.com', 'lars@callmeradical.com']
11
+ spec.summary = 'Basic gem for cookbook config and init.'
12
+ spec.description = 'This gem provides some configs and cookbook initialization'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.5'
21
+ spec.add_development_dependency 'rake'
22
+
23
+ spec.add_runtime_dependency 'term-ansicolor'
24
+ end
@@ -0,0 +1,5 @@
1
+ module Kitchen
2
+ module Config
3
+ VERSION = '0.1.1'
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ #
2
+ # the chef client cookbook utilizes a windows only lib called WIN32OLE. This is
3
+ # all fine and dandy and all, but breaks when we fauxhai our chefspec run as
4
+ # a windows machine... you know... since WIN32OLE is ONLY available to windows
5
+ # versions of ruby. So, to get around that, we're going to stub out this
6
+ # nastiness:
7
+
8
+ # btw... this is a stunning show of hacknery.
9
+ module WIN32OLE
10
+ #This just accepts everything.
11
+ module Stuby
12
+ def self.ExecQuery(_args)
13
+ WIN32OLE::Eachy
14
+ end
15
+ end
16
+
17
+ # Iterative.
18
+ module Eachy
19
+ def self.each
20
+ []
21
+ end
22
+ end
23
+
24
+ def self.connect(_args)
25
+ WIN32OLE::Stuby
26
+ end
27
+ end
28
+
29
+ module Win32
30
+ include WIN32OLE
31
+ end
@@ -0,0 +1,23 @@
1
+ #
2
+ # the windows cookbooks that we write utilize a windows only lib called Registry.
3
+ # WHen running chefspec on a windows box this does not present a problem, however
4
+ # since we develop on linux, we had to monkey patch the lib because chef does not
5
+ # load the lib on non-windows systems.
6
+ module Win32
7
+ module Registry
8
+ module Regmock
9
+ def self.open(_a = nil, _b = nil)
10
+ true
11
+ end
12
+ end
13
+
14
+ HKEY_LOCAL_MACHINE = Regmock
15
+ HKEY_USERS = Regmock
16
+ HKEY_CURRENT_USER = Regmock
17
+ KEY_ALL_ACCESS = 0x000000
18
+
19
+ def self.get_value(_a = nil, _b = nil)
20
+ 'super_string'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,44 @@
1
+ # Primary module for this gem, uses method missing to read shared config file.
2
+ require 'kitchen/config/version'
3
+
4
+ module Kitchen
5
+ module Config
6
+ require 'yaml'
7
+
8
+ @config = nil
9
+
10
+ def self.method_missing(method_sym, *_arguments, &_block)
11
+ if @config.nil?
12
+ self.load_config(ENV['KITCHEN_CONFIG'])
13
+ end
14
+
15
+ if @config.keys.include?(method_sym)
16
+ @config[method_sym]
17
+ else
18
+ raise 'Undefined method or variable, '\
19
+ "received #{method_sym}, availabile #{@config.keys}"
20
+ end
21
+ end
22
+
23
+ def self.load_config(file)
24
+ begin
25
+ @config_path = File.expand_path(File.dirname(file))
26
+ rescue ArguementError => e
27
+ puts "You provided #{ENV['KITCHEN_CONFIG']}"
28
+ raise 'Please define valid KITCHEN_CONFIG in your shell.'
29
+ end
30
+ @config = YAML.load_file("#{@config_path}/config.yml")
31
+ end
32
+
33
+ def self.respond_to?(method_sym, include_private = false)
34
+ @config.keys.include?(method_sym) ? true : super
35
+ end
36
+
37
+ def self.tags(cb_name, user)
38
+ " tags:\n" \
39
+ " Name: \"Chef Tester\"\n" \
40
+ " Apps: \"#{cb_name} cookbook test\"\n" \
41
+ " App Owner: \"#{user}\""
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe WIN32OLE::Stuby do
4
+ let(:subj) { WIN32OLE::Stuby }
5
+ let(:args) { nil }
6
+ subject { subj }
7
+
8
+ before :each do
9
+ allow(WIN32OLE::Stuby).to receive(:ExecQuery).with(args)
10
+ end
11
+ describe '#ExecQuery' do
12
+ it { expect(subj).to respond_to(:ExecQuery).with(args) }
13
+ it { expect(subj).to respond_to(:ExecQuery) }
14
+ end
15
+ end
16
+
17
+ RSpec.describe WIN32OLE::Eachy do
18
+ let(:subj) { WIN32OLE::Eachy }
19
+ subject { subj }
20
+
21
+ describe '#each' do
22
+ it { expect(subj).to respond_to :each }
23
+ end
24
+ end
25
+
26
+ RSpec.describe Win32 do
27
+ let(:subj) { Win32 }
28
+ subject { subj }
29
+
30
+ describe 'includes WIN32OLE module' do
31
+ it { expect(subj).to include WIN32OLE }
32
+ end
33
+ end
34
+
35
+ RSpec.describe WIN32OLE do
36
+ let(:subj) { WIN32OLE }
37
+ let(:args) { nil }
38
+ subject { subj }
39
+
40
+ describe '#connect' do
41
+ it { expect(subj).to respond_to(:connect).with(args) }
42
+ end
43
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Win32::Registry::Regmock do
4
+ # create a copy of class
5
+ let(:subj) { Win32::Registry::Regmock }
6
+ # this is required to ref unit tests directly (is_expected)
7
+
8
+ describe '#open' do
9
+ it { expect(subj).to respond_to(:open) }
10
+ it { expect(subj.open).to eq(true) }
11
+ end
12
+ end
13
+
14
+ RSpec.describe Win32::Registry do
15
+ let(:subj) { Win32::Registry }
16
+ let(:kaa) { Win32::Registry::KEY_ALL_ACCESS }
17
+ regmocks = {
18
+ 'HKEY_LOCAL_MACHINE' => Win32::Registry::HKEY_LOCAL_MACHINE,
19
+ 'HKEY_USERS' => Win32::Registry::HKEY_USERS,
20
+ 'HKEY_CURRENT_USER' => Win32::Registry::HKEY_CURRENT_USER
21
+ }
22
+
23
+ regmocks.each do |k, v|
24
+ describe "has #{k}" do
25
+ it { expect(v).to eq Win32::Registry::Regmock }
26
+ it { expect(v).to respond_to(:open) }
27
+ it { expect(v.open).to eq(true) }
28
+ end
29
+ end
30
+
31
+ describe 'has KEY_ALL_ACCESS' do
32
+ it { expect(kaa).to eq 0x000000 }
33
+ end
34
+
35
+ describe '#get_value' do
36
+ it { expect(subj).to respond_to(:get_value) }
37
+ it { expect(subj.get_value).to match /super/ }
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ ---
2
+ :key_id: 'your_key_here'
3
+ :tester_ami: 'your_ami_here'
4
+ :tester_flavor_id: 't2.large'
5
+ :busser_version: '0.7.1'
6
+ :chef_version: '12.5.1'
7
+ :region: 'us-east-1'
8
+ :availability_zone: 'us-east-1b'
9
+ :username: 'ec2-user'
10
+ :threads: '10'
11
+ :windows_username: 'chef'
12
+ :password: 'chef'
13
+ :data_bag_path: 'chef_repo/test/data_bags'
14
+ :data_bag_secret_path: 'chef_repo/test/secret'
15
+ :iam_profile_name: 'chef-kitchen-tests'
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Kitchen::Config do
4
+ context 'A Valid Kitchen Config' do
5
+ mimic_config = {
6
+ key_id: 'super_secret_key',
7
+ tester_ami: 'ami-666',
8
+ bare_ami: 'ami-999',
9
+ security_group_ids: ['sg-123456']
10
+ }
11
+
12
+ cb_name = 'FartBook'
13
+ user = 'Derp'
14
+ os = 'DerpOS'
15
+
16
+ let(:subj) { Kitchen::Config }
17
+ subject { subj }
18
+ before :each do
19
+ config = File.expand_path(__FILE__)
20
+ ENV['KITCHEN_CONFIG'] = "#{config}/config.yml"
21
+ subj.instance_variable_set('@config', mimic_config)
22
+ end
23
+
24
+ describe '#tags' do
25
+ let(:method) { subj.tags(cb_name, user) }
26
+ it { expect(subj).to respond_to(:tags) }
27
+ it { expect(method).to match /Name: \"Chef Tester\"/ }
28
+ it { expect(method).to match /Apps: \"#{cb_name} cookbook test\"/ }
29
+ end
30
+
31
+ describe '#load_config' do
32
+ let(:method) { subj.load_config(ENV['KITCHEN_CONFIG']) }
33
+ it { expect(subj).to respond_to(:load_config) }
34
+ end
35
+
36
+ describe 'values returned for config' do
37
+ it { expect(subj.tester_ami).to eq('ami-666') }
38
+ it { expect(subj.bare_ami).to eq('ami-999') }
39
+ it { expect(subj.key_id).to eq('super_secret_key') }
40
+ end
41
+
42
+ describe 'if key is not present in config' do
43
+ it 'raises an exception' do
44
+ expect { subj.foo }.to raise_error /Undefined method/
45
+ end
46
+ it 'presents the user with available keys' do
47
+ expect { subj.bar }.to raise_error /:key_id, :tester_ami, :bare_ami/
48
+ end
49
+ end
50
+ end
51
+
52
+ context 'An INVALID Kitchen Config' do
53
+ let(:subj) { Kitchen::Config }
54
+ describe 'if KITCHEN_CONFIG is not valid' do
55
+ it 'it raises an exception' do
56
+ expect { subj.load_config(nil) }.to raise_error /ArguementError/
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,11 @@
1
+ require 'rspec'
2
+ require 'yaml'
3
+ require "codeclimate-test-reporter"
4
+ CodeClimate::TestReporter.start
5
+
6
+ Dir['./lib/**/*.rb'].reverse_each { |file| require file }
7
+ RSpec.configure do |config|
8
+ config.run_all_when_everything_filtered = true
9
+ RSpec::Mocks.configuration.verify_partial_doubles = true
10
+ config.order = 'random'
11
+ end
@@ -0,0 +1,20 @@
1
+ *~
2
+ *#
3
+ .#*
4
+ \#*#
5
+ .*.sw[a-z]
6
+ *.un~
7
+ pkg/
8
+
9
+ # Berkshelf
10
+ /cookbooks
11
+ Berksfile.lock
12
+
13
+ # Bundler
14
+ bin/*
15
+ .bundle/*
16
+
17
+ .kitchen/
18
+ nodes
19
+ tmp
20
+ .swp*
@@ -0,0 +1,69 @@
1
+ <% require 'kitchen/config' %>
2
+ <% config = Kitchen::Config %>
3
+ <% aws_access_key = ENV['AWS_ACCESS_KEY'] %>
4
+ <% aws_secret_key = ENV['AWS_SECRET_KEY'] %>
5
+ <% user = "#{`git config --get user.name`.chomp} <#{`git config --get user.email`.chomp}>" %>
6
+ ---
7
+ settings:
8
+ parallel: true
9
+
10
+ driver:
11
+ name: ec2
12
+ require_chef_omnibus: <%= config.chef_version %>
13
+ aws_access_key_id: <%= aws_access_key %>
14
+ aws_secret_access_key: <%= aws_secret_key %>
15
+ aws_ssh_key_id: <%= config.key_id %>
16
+ ssh_key: <%= ENV['HOME'] %>/.ssh/<%= config.key_id %>.pem
17
+ flavor_id: '<%= config.tester_flavor_id %>'
18
+ region: '<%= config.region %>'
19
+ availability_zone: '<%= config.availability_zone %>'
20
+ security_group_ids: <%= config.security_group_ids %>
21
+ username: '<%= config.username %>'
22
+ subnet_id: '<%= config.subnet_id %>'
23
+ iam_profile_name: '<%= config.iam_profile_name%>'
24
+ <%= config.tags("COOKBOOK_NAME", user) %>
25
+
26
+ driver_config:
27
+ name: ec2
28
+ associate_public_ip: false
29
+
30
+ provisioner:
31
+ name: chef_zero
32
+ attributes:
33
+ chef_client:
34
+ config:
35
+ ssl_verify_mode: ":verify_peer"
36
+
37
+ platforms:
38
+ - name: rhel6
39
+ driver:
40
+ name: ec2
41
+ image_id: <%= config.bare_ami %>
42
+ - name: rhel7
43
+ driver:
44
+ name: ec2
45
+ image_id: <%= config.rhel7_ami %>
46
+ - name: amazon
47
+ driver:
48
+ name: ec2
49
+ image_id: <%= config.amazon_ami %>
50
+
51
+ suites:
52
+ - name: default
53
+ # use these if you require encrypted data bags: Setup a submodule:
54
+ # %> git submodule add ssh://git@server/devops_cookbooks/chef_repo.git
55
+ # then uncoment the below lines:
56
+ # data_bags_path: "chef_repo/test/data_bags"
57
+ # encrypted_data_bag_secret_key_path: "chef_repo/test/secret"
58
+ # to remove the submodule:
59
+ # %> git submodule deinit -f chef_repo
60
+ # %> git rm chef_repo
61
+ # %> rm -rf .git/modules/chef_repo
62
+ run_list:
63
+ # use this if you are building an application cookbook, and comment out
64
+ # the recipe. Make sure you add roles/COOKBOOK_NAME.json, and the
65
+ # attribute: default['application'] = 'COOKBOOK_NAME' to
66
+ # attributes/default.rb too.
67
+ # - role[COOKBOOK_NAME]
68
+ - recipe[COOKBOOK_NAME::default]
69
+ attributes:
data/templates/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,7 @@
1
+ # LineLength can be greater than 80 characters
2
+ Metrics/LineLength:
3
+ Enabled: false
4
+
5
+ AllCops:
6
+ Exclude:
7
+ - 'chef_repo/**/*'
@@ -0,0 +1,6 @@
1
+ source 'https://api.berkshelf.com'
2
+
3
+ metadata
4
+
5
+ group :test do
6
+ end
data/templates/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://radmine' do
2
+ gem 'kitchen-config'
3
+ end
4
+
5
+ source 'https://rubygems.org'
6
+
7
+ gem 'test-kitchen', git: 'https://github.com/callmeradical/test-kitchen.git', branch: 'wallofdeath_fix'
8
+ gem 'kitchen-ec2', git: 'https://github.com/afiune/kitchen-ec2.git', branch: 'Transport'
9
+ gem 'chefspec'
10
+ gem 'chef'
11
+ gem 'berkshelf'
12
+ gem 'mixlib-shellout'
13
+ gem 'winrm-transport'
@@ -0,0 +1,8 @@
1
+ #source 'https://radmine'
2
+ source 'https://rubygems.org'
3
+
4
+ group :test, :development do
5
+ gem 'serverspec', '2.25.0'
6
+ # specinfra 2.36.18 is bugged on the 'match' matcher.
7
+ gem 'specinfra', '2.36.14'
8
+ end
@@ -0,0 +1,33 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+ guard 'foodcritic', cookbook_paths: '.', notification: false, cli: '-X spec/' do
4
+ watch(%r{attributes/.+\.rb$})
5
+ watch(%r{providers/.+\.rb$})
6
+ watch(%r{recipes/.+\.rb$})
7
+ watch(%r{resources/.+\.rb$})
8
+ watch(%r{libraries/.+\.rb$})
9
+ end
10
+
11
+ seed = ENV['SEED'].nil? ? '' : " --seed #{ENV['SEED']}"
12
+ guard :rspec, cmd: "chef exec rspec#{seed}", all_on_start: false, notification: false do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch('spec/spec_helper.rb') { 'spec' }
15
+ watch(%r{^attributes/(.+)\.rb$}) { |m| "spec/attributes/#{m[1]}_spec.rb" }
16
+ watch(%r{^libraries/(.+)\.rb$}) { |m| "spec/libraries/#{m[1]}_spec.rb" }
17
+ watch(%r{^providers/(.+)\.rb$}) { |m| "spec/providers/#{m[1]}_spec.rb" }
18
+ watch(%r{^recipes/(.+)\.rb$}) { |m| "spec/recipes/#{m[1]}_spec.rb" }
19
+ watch(%r{^resources/(.+)\.rb$}) { |m| "spec/resources/#{m[1]}_spec.rb" }
20
+ watch(%r{^templates/(.+)\.rb$}) { |m| "spec/templates/#{m[1]}_spec.rb" }
21
+
22
+ ignore(%r{^spec/integration/(.+)\.rb$})
23
+ end
24
+
25
+ # #guard 'kitchen' do
26
+ ## watch(%r{^test/integration/default/serverspec/localhost/(.+)_spec.rb})
27
+ ## watch(%r{^recipes/(.+)\.rb$})
28
+ ## watch(%r{^attributes/(.+)\.rb$})
29
+ ## watch(%r{^files/(.+)})
30
+ ## watch(%r{^templates/(.+)})
31
+ ## watch(%r{^providers/(.+)\.rb})
32
+ ## watch(%r{^resources/(.+)\.rb})
33
+ ## end
@@ -0,0 +1,7 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+ require 'ci/reporter/rake/rspec'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ ## see https://github.com/sethvargo/chefspec
3
+
4
+ # using chef client or another WIN32OLE dependent cookbook?
5
+ # require 'kitchen/config/win32ole_chefspec_linux.rb'
6
+
7
+ describe 'COOKBOOK_NAME::default' do
8
+ cached(:chef_run) { default_chef_run }
9
+ subject { chef_run }
10
+
11
+ before :each do
12
+ stub_command(/.*/).and_return true
13
+ # need to stub out a data bag? see .kitchen.yml too.
14
+ # allow(Chef::EncryptedDataBagItem).to receive(:load).and_return 'stuff'
15
+ end
16
+
17
+ describe 'included recipies' do
18
+ it { is_expected.to include_recipe 'my_cookbook::recipe' }
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ ## see http://serverspec.org/
4
+
5
+ describe command 'ls' do
6
+ it {expect(false) to be true}
7
+ end
@@ -0,0 +1,3 @@
1
+ require 'serverspec'
2
+
3
+ set :backend, :exec
@@ -0,0 +1,13 @@
1
+ name 'COOKBOOK_NAME'
2
+ maintainer 'YOUR_NAME'
3
+ maintainer_email 'YOUR_EMAIL'
4
+ license 'All rights reserved'
5
+ description 'Installs/Configures COOKBOOK_NAME'
6
+ long_description 'Installs/Configures COOKBOOK_NAME'
7
+ version '0.0.1'
8
+
9
+ supports 'redhat'
10
+ supports 'amazon'
11
+
12
+ ## depends on another cookbook, or series of cookbooks?
13
+ ## depends 'some_cookbook'
@@ -0,0 +1,40 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ ## chef spec
9
+ require 'chefspec'
10
+ require 'chefspec/berkshelf'
11
+ require 'chefspec/cacher'
12
+
13
+ Dir['../libraries/*.rb'].each { |f| require f }
14
+ Dir['./spec/support/**/*.rb'].each { |f| require f }
15
+
16
+ RSpec.configure do |config|
17
+ config.run_all_when_everything_filtered = true
18
+ config.filter_run :focus
19
+ config.log_level = :error
20
+
21
+ # Run specs in random order to surface order dependencies. If you find an
22
+ # order dependency and want to debug it, you can fix the order by providing
23
+ # the seed, which is printed after each run.
24
+ # --seed 1234
25
+ config.order = 'random'
26
+
27
+ ## setup fauxhai to be redhat 6.5
28
+ config.platform = 'redhat'
29
+ config.version = '6.5'
30
+ end
31
+
32
+ ## setup default chef run for chefspec
33
+ def default_chef_run(&block)
34
+ ChefSpec::ServerRunner.new do |node|
35
+ ## allow the runner to be configured like it would normally by calling any
36
+ ## passed in block.
37
+ yield node unless block.nil?
38
+ end.converge described_recipe
39
+ end
40
+ at_exit { ChefSpec::Coverage.report! }
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - craig monson
8
+ - lars cromley
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-03-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.5'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: term-ansicolor
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: This gem provides some configs and cookbook initialization
57
+ email:
58
+ - craig@malachiarts.com
59
+ - lars@callmeradical.com
60
+ executables:
61
+ - initialize_cookbook
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - ".rubocop.yml"
68
+ - ".travis.yml"
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - Guardfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - bin/initialize_cookbook
76
+ - kitchen-config.gemspec
77
+ - lib/kitchen/config.rb
78
+ - lib/kitchen/config/version.rb
79
+ - lib/kitchen/config/win32ole_chefspec_linux.rb
80
+ - lib/kitchen/config/win32registry_chefspec_linux.rb
81
+ - spec/lib/kitchen/config.yml
82
+ - spec/lib/kitchen/config/win32ole_chefspec_linux_spec.rb
83
+ - spec/lib/kitchen/config/win32registry_chefspec_linux_spec.rb
84
+ - spec/lib/kitchen/config_spec.rb
85
+ - spec/spec_helper.rb
86
+ - templates/.gitignore
87
+ - templates/.kitchen.yml
88
+ - templates/.rspec
89
+ - templates/.rubocop.yml
90
+ - templates/Berksfile
91
+ - templates/Gemfile
92
+ - templates/Gemfile.serverspec
93
+ - templates/Guardfile
94
+ - templates/Rakefile
95
+ - templates/default_spec.rb
96
+ - templates/integration_default_spec.rb
97
+ - templates/integration_spec_helper.rb
98
+ - templates/metadata.rb
99
+ - templates/spec_helper.rb
100
+ homepage:
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.5
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Basic gem for cookbook config and init.
124
+ test_files:
125
+ - spec/lib/kitchen/config.yml
126
+ - spec/lib/kitchen/config/win32ole_chefspec_linux_spec.rb
127
+ - spec/lib/kitchen/config/win32registry_chefspec_linux_spec.rb
128
+ - spec/lib/kitchen/config_spec.rb
129
+ - spec/spec_helper.rb