From ebc3a3ccff6ef7f7a33535163f89450cf0bf5b64 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Fri, 16 Mar 2018 00:40:23 -0700 Subject: [PATCH 01/21] use .foodcritic file to manage ignored rules --- .foodcritic | 2 ++ Rakefile | 12 ++---------- 2 files changed, 4 insertions(+), 10 deletions(-) create mode 100644 .foodcritic diff --git a/.foodcritic b/.foodcritic new file mode 100644 index 0000000..7f2d2f8 --- /dev/null +++ b/.foodcritic @@ -0,0 +1,2 @@ +~FC007 +~FC071 diff --git a/Rakefile b/Rakefile index 8348bb9..6422bd0 100644 --- a/Rakefile +++ b/Rakefile @@ -15,15 +15,7 @@ RuboCop::RakeTask.new(:rubocop) do |task| task.fail_on_error = true end -FoodCritic::Rake::LintTask.new do |t| - t.options = { - fail_tags: ['any'], - tags: [ - '~FC007', # Don't reflect recipe dependencies - '~FC071' # Don't require LICENSE file - ] - } -end +FoodCritic::Rake::LintTask.new desc 'Run Test Kitchen integration tests' namespace :integration do @@ -50,7 +42,7 @@ desc 'Run chefspec unit tests' RSpec::Core::RakeTask.new(:unit) do |t| t.rspec_opts = [].tap do |a| a.push('--color') - a.push('--format progress') + a.push('--format documentation') end.join(' ') t.pattern = 'test/unit/spec/*_spec.rb' end From 0e7711b7b7bc4ad6aee7c59e1f5c2fa760183638 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Fri, 16 Mar 2018 14:42:23 -0700 Subject: [PATCH 02/21] Add 'compat_resource' dependency --- metadata.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/metadata.rb b/metadata.rb index b3bab3f..a0dc26a 100644 --- a/metadata.rb +++ b/metadata.rb @@ -20,6 +20,9 @@ depends 'ark' depends 'apt' +# For compatibility with 12.X versions of Chef +depends 'compat_resource' + # Suggests is not officially valid, that is why these are commented out # suggests 'apache2', '>= 2.0' # suggests 'authbind' From be1426a8b002fcb90e8c29c450eec56bd9be0cb2 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Fri, 16 Mar 2018 14:42:36 -0700 Subject: [PATCH 03/21] # This is a combination of 2 commits. # This is the 1st commit message: update rubocop # This is the commit message #2: update rubocop length allowances --- .rubocop.yml | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2a6481f..84ea53c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,8 +9,11 @@ AllCops: BlockComments: Enabled: false -BlockLength: - Enabled: false + +Style/RescueModifier: + Exclude: + - 'Rakefile' + - 'libraries/helpers.rb' LeadingCommentSpace: Enabled: false @@ -18,6 +21,31 @@ LeadingCommentSpace: LineLength: Enabled: false +# Longer classes are okay. +Metrics/BlockLength: + Max: 41 +Metrics/LineLength: + Max: 172 +Metrics/MethodLength: + Max: 30 +Metrics/ModuleLength: + Max: 150 + +# We're not against complexity. +Metrics/AbcSize: + Max: 55 +Metrics/CyclomaticComplexity: + Max: 20 +Metrics/PerceivedComplexity: + Max: 20 + +# Mixlib::ShellOut is nice to have as an older hash syntax +Style/HashSyntax: + Enabled: false + +Style/ClassAndModuleChildren: + Enabled: false + Style/FileName: Exclude: - 'Berksfile' From ae1e6c2f3fa5b9302e2365b105126ee04079183b Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Fri, 16 Mar 2018 14:42:56 -0700 Subject: [PATCH 04/21] compat_resource dependency --- Berksfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Berksfile b/Berksfile index 453296b..5ce69f9 100644 --- a/Berksfile +++ b/Berksfile @@ -4,6 +4,8 @@ source 'https://supermarket.chef.io/' metadata +cookbook 'compat_resource' + group :vagrant do cookbook 'ark' cookbook 'apt' From 456bdf84fc8783417e1c21b0f6f4f8dd21e06586 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Fri, 16 Mar 2018 14:43:09 -0700 Subject: [PATCH 05/21] correct chef12 version --- .kitchen.yml | 2 +- CHANGELOG.md | 4 ++++ metadata.rb | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index 522d18e..8f1e742 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,7 +1,7 @@ --- driver_plugin: vagrant driver_config: - require_chef_omnibus: 12.4.1 + require_chef_omnibus: 12.7.2 network: - ["forwarded_port", {guest: 8080, host: 8080, auto_correct: true}] diff --git a/CHANGELOG.md b/CHANGELOG.md index 31b4644..2653e41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.3: +* Further test fixes +* Run unit tests on multiple platforms (@mburns) + ## 0.2.2: * Update to fix travis runs for CentOS7 and Ubuntu 16.04. #102 (@drenalin23) * Update `ark` #103 (@drenalin23) diff --git a/metadata.rb b/metadata.rb index a0dc26a..2e90528 100644 --- a/metadata.rb +++ b/metadata.rb @@ -10,7 +10,7 @@ source_url 'https://github.com/realityforge/chef-kibana' issues_url 'https://github.com/realityforge/chef-kibana/issues' -chef_version '>= 12' if respond_to?(:chef_version) +chef_version '>= 12.7.2' if respond_to?(:chef_version) supports 'ubuntu' supports 'debian' From 9775f27a9918bbbd175d1e9dd6c0756ece1235bf Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Fri, 16 Mar 2018 14:43:25 -0700 Subject: [PATCH 06/21] Use cyberflow's unit testing logic from https://github.com/realityforge/chef-kibana/pull/101 --- chefignore | 1 + test/fixtures/environments/chefspec.json | 12 ++ test/fixtures/nodes/node01.json | 27 ++++ test/unit/spec/_service_spec.rb | 116 +++++++++--------- test/unit/spec/apache_spec.rb | 25 +++- test/unit/spec/default_spec.rb | 48 +++++--- test/unit/spec/kibana3_spec.rb | 81 +++++++----- test/unit/spec/kibana4_spec.rb | 61 +++++---- test/unit/spec/nginx_spec.rb | 19 ++- test/unit/spec/spec_helper.rb | 54 ++++---- test/unit/spec/support/platform_properties.rb | 11 ++ test/unit/spec/support/supported_platforms.rb | 8 ++ 12 files changed, 302 insertions(+), 161 deletions(-) create mode 100644 test/fixtures/environments/chefspec.json create mode 100644 test/fixtures/nodes/node01.json create mode 100644 test/unit/spec/support/platform_properties.rb create mode 100644 test/unit/spec/support/supported_platforms.rb diff --git a/chefignore b/chefignore index a6de142..8b15b92 100644 --- a/chefignore +++ b/chefignore @@ -53,6 +53,7 @@ test/* features/* Guardfile Procfile +test # SCM # ####### diff --git a/test/fixtures/environments/chefspec.json b/test/fixtures/environments/chefspec.json new file mode 100644 index 0000000..e55f29e --- /dev/null +++ b/test/fixtures/environments/chefspec.json @@ -0,0 +1,12 @@ +{ + "name": "chefspec", + "description": "Stubbed Environment for Chefspec", + "cookbook_versions": { + }, + "json_class": "Chef::Environment", + "chef_type": "environment", + "default_attributes": { + }, + "override_attributes": { + } +} \ No newline at end of file diff --git a/test/fixtures/nodes/node01.json b/test/fixtures/nodes/node01.json new file mode 100644 index 0000000..67efee5 --- /dev/null +++ b/test/fixtures/nodes/node01.json @@ -0,0 +1,27 @@ +{ + "name": "node01", + "chef_environment": "_default", + "json_class": "Chef::Node", + "automatic": { + "hostname": "vagrant.vm", + "recipes": [ + "kibana::default" + ], + "roles": [ + ], + "ipaddress": "192.168.0.1" + }, + "tags": [ + "app" + ], + "normal": { + }, + "chef_type": "node", + "default": { + }, + "override": { + }, + "run_list": [ + "recipe[kibana::default]" + ] +} \ No newline at end of file diff --git a/test/unit/spec/_service_spec.rb b/test/unit/spec/_service_spec.rb index ea68470..3f44590 100644 --- a/test/unit/spec/_service_spec.rb +++ b/test/unit/spec/_service_spec.rb @@ -1,69 +1,73 @@ # frozen_string_literal: true -require 'chefspec' require_relative 'spec_helper' # for ubuntu 14.04 upstart -describe 'kibana::_service' do - before { stub_resources } - let(:chef_run) { ChefSpec::SoloRunner.new(UBUNTU_OPTS).converge(described_recipe) } - let(:template) { chef_run.template('/etc/init/kibana.conf') } - it 'creates an upstart template at /etc/init/kibana.conf' do - expect(chef_run).to create_template('/etc/init/kibana.conf') - end - it 'enables a kibana service' do - expect(chef_run).to enable_service('kibana') - end - it 'sends a restart notification to the service' do - expect(template).to notify('service[kibana]').to(:restart) - end -end +# describe 'kibana::_service' do +# before { stub_resources } +# let(:chef_run) { ChefSpec::SoloRunner.new(UBUNTU_OPTS).converge(described_recipe) } +# let(:template) { chef_run.template('/etc/init/kibana.conf') } +# it 'creates an upstart template at /etc/init/kibana.conf' do +# expect(chef_run).to create_template('/etc/init/kibana.conf') +# end +# end +# +# # for ubuntu 16.04 systemd +# describe 'kibana::_service' do +# before { stub_resources } +# let(:chef_run) { ChefSpec::SoloRunner.new(UBUNTU_1604_OPTS).converge(described_recipe) } +# let(:template) { chef_run.template('/lib/systemd/system/kibana.service') } +# it 'creates an upstart template at /lib/systemd/system/kibana.service' do +# expect(chef_run).to create_template('/lib/systemd/system/kibana.service') +# end +# end +# +# # for centos 6.x init +# describe 'kibana::_service' do +# before { stub_resources } +# let(:chef_run) { ChefSpec::SoloRunner.new(CENTOS_OPTS).converge(described_recipe) } +# let(:template) { chef_run.template('/usr/lib/systemd/system/kibana.service') } +# +# it 'creates an init.d template at /usr/lib/systemd/system/kibana.service' do +# expect(chef_run).to create_template('/usr/lib/systemd/system/kibana.service') +# end +# end +# +# # for centos 7.x systemd +# describe 'kibana::_service' do +# before { stub_resources } +# let(:chef_run) { ChefSpec::SoloRunner.new(CENTOS7_OPTS).converge(described_recipe) } +# let(:template) { chef_run.template('/usr/lib/systemd/system/kibana.service') } +# it 'creates an init.d template at /usr/lib/systemd/system/kibana.service' do +# expect(chef_run).to create_template('/usr/lib/systemd/system/kibana.service') +# end +# end -# for ubuntu 16.04 systemd describe 'kibana::_service' do before { stub_resources } - let(:chef_run) { ChefSpec::SoloRunner.new(UBUNTU_1604_OPTS).converge(described_recipe) } - let(:template) { chef_run.template('/lib/systemd/system/kibana.service') } - it 'creates an upstart template at /lib/systemd/system/kibana.service' do - expect(chef_run).to create_template('/lib/systemd/system/kibana.service') - end - it 'enables a kibana service' do - expect(chef_run).to enable_service('kibana') - end - it 'sends a restart notification to the service' do - expect(template).to notify('service[kibana]').to(:restart) - end -end + supported_platforms.each do |platform, versions| + versions.each do |version| + context "on #{platform.capitalize} #{version}" do + let(:chef_run) do + ChefSpec::ServerRunner.new(platform: platform, version: version) do |node, server| + node_resources(node) # data for this node + stub_chef_zero(platform, version, server) # stub other nodes in chef-zero + end.converge(described_recipe) + end -# for centos 6.x init -describe 'kibana::_service' do - before { stub_resources } - let(:chef_run) { ChefSpec::SoloRunner.new(CENTOS_OPTS).converge(described_recipe) } - let(:template) { chef_run.template('/usr/lib/systemd/system/kibana.service') } + # any platform specific data you want available to your test can be loaded here + _property = load_platform_properties(platform: platform, platform_version: version) - it 'creates an init.d template at /usr/lib/systemd/system/kibana.service' do - expect(chef_run).to create_template('/usr/lib/systemd/system/kibana.service') - end - it 'enables a kibana service' do - expect(chef_run).to enable_service('kibana') - end - it 'sends a restart notification to the service' do - expect(template).to notify('service[kibana]').to(:restart) - end -end + # tempalte kibana service -# for centos 7.x systemd -describe 'kibana::_service' do - before { stub_resources } - let(:chef_run) { ChefSpec::SoloRunner.new(CENTOS7_OPTS).converge(described_recipe) } - let(:template) { chef_run.template('/usr/lib/systemd/system/kibana.service') } - it 'creates an init.d template at /usr/lib/systemd/system/kibana.service' do - expect(chef_run).to create_template('/usr/lib/systemd/system/kibana.service') - end - it 'enables a kibana service' do - expect(chef_run).to enable_service('kibana') - end - it 'sends a restart notification to the service' do - expect(template).to notify('service[kibana]').to(:restart) + it 'enables a kibana service' do + expect(chef_run).to enable_service('kibana') + end + + # it 'sends a restart notification to the service' do + # expect(template).to notify('service[kibana]').to(:restart) + # end + end + end end end diff --git a/test/unit/spec/apache_spec.rb b/test/unit/spec/apache_spec.rb index 7e41d63..c08b0b5 100644 --- a/test/unit/spec/apache_spec.rb +++ b/test/unit/spec/apache_spec.rb @@ -5,13 +5,26 @@ describe 'kibana::apache' do before { stub_resources } + supported_platforms.each do |platform, versions| + versions.each do |version| + context "on #{platform.capitalize} #{version}" do + let(:chef_run) do + ChefSpec::ServerRunner.new(platform: platform, version: version) do |node, server| + node_resources(node) + stub_chef_zero(platform, version, server) + end.converge(described_recipe) + end - let(:chef_run) { ChefSpec::SoloRunner.new(UBUNTU_OPTS).converge(described_recipe) } + # any platform specific data you want available to your test can be loaded here + _property = load_platform_properties(platform: platform, platform_version: version) - # TODO: creates a template /etc/apache2/htpasswd - # TODO: creates a template /etc/apache2/sites-available/kibana.conf - - it 'converges successfully' do - expect { :chef_run }.to_not raise_error + # TODO: creates a template /etc/apache2/htpasswd + # TODO: creates a template /etc/apache2/sites-available/kibana.conf + + it 'converges successfully' do + expect { :chef_run }.to_not raise_error + end + end + end end end diff --git a/test/unit/spec/default_spec.rb b/test/unit/spec/default_spec.rb index 6b6622d..2d8ee53 100644 --- a/test/unit/spec/default_spec.rb +++ b/test/unit/spec/default_spec.rb @@ -1,27 +1,41 @@ # frozen_string_literal: true -require 'chefspec' require_relative 'spec_helper' describe 'kibana::default' do before { stub_resources } + supported_platforms.each do |platform, versions| + versions.each do |version| + context "on #{platform.capitalize} #{version}" do + let(:chef_run) do + ChefSpec::ServerRunner.new(platform: platform, version: version) do |node, server| + node_resources(node) + stub_chef_zero(platform, version, server) + end.converge(described_recipe) + end - let(:chef_run) { ChefSpec::SoloRunner.new(UBUNTU_OPTS).converge(described_recipe) } + # any platform specific data you want available to your test can be loaded here + _property = load_platform_properties(platform: platform, platform_version: version) - it 'creates kibana group' do - expect(chef_run).to create_group('kibana') - end - it 'creates kibana user' do - expect(chef_run).to create_user('kibana').with( - gid: 'kibana', - home: '/opt/kibana', - shell: '/bin/bash' - ) - end - it 'creates kibana base directory' do - expect(chef_run).to create_directory('/opt/kibana').with( - owner: 'kibana', - group: 'kibana' - ) + it 'creates kibana group' do + expect(chef_run).to create_group('kibana') + end + + it 'creates kibana user' do + expect(chef_run).to create_user('kibana').with( + gid: 'kibana', + home: '/opt/kibana', + shell: '/bin/bash' + ) + end + + it 'creates kibana base directory' do + expect(chef_run).to create_directory('/opt/kibana').with( + owner: 'kibana', + group: 'kibana' + ) + end + end + end end end diff --git a/test/unit/spec/kibana3_spec.rb b/test/unit/spec/kibana3_spec.rb index 150d36c..ac423ed 100644 --- a/test/unit/spec/kibana3_spec.rb +++ b/test/unit/spec/kibana3_spec.rb @@ -1,52 +1,71 @@ # frozen_string_literal: true -require 'chefspec' require_relative 'spec_helper' describe 'kibana::kibana3' do before { stub_resources } + supported_platforms.each do |platform, versions| + versions.each do |version| + context "on #{platform.capitalize} #{version}" do + let(:chef_run) do + ChefSpec::ServerRunner.new(platform: platform, version: version) do |node, server| + node_resources(node) + stub_chef_zero(platform, version, server) + end.converge(described_recipe) + end - let(:chef_run) { ChefSpec::SoloRunner.new(UBUNTU_OPTS).converge(described_recipe) } + _property = load_platform_properties(platform: platform, platform_version: version) - it 'includes kibana recipe' do - expect(chef_run).to include_recipe('kibana::default') - end + it 'includes kibana recipe' do + expect(chef_run).to include_recipe('kibana::default') + end - it 'installs kibana3 with ark' do - expect(chef_run).to install_ark('kibana') - end + it 'installs kibana3 with ark' do + expect(chef_run).to install_ark('kibana') + end - it 'creates a template for kibana' do - expect(chef_run).to create_template('/opt/kibana/current/config.js').with( - owner: 'kibana', - group: 'kibana', - mode: '0644' - ) + it 'creates a template for kibana' do + expect(chef_run).to create_template('/opt/kibana/current/config.js').with( + owner: 'kibana', + group: 'kibana', + mode: '0644' + ) + end + end + end end end # if source install is requested test this path describe 'kibana::kibana3' do before { stub_resources } + supported_platforms.each do |platform, versions| + versions.each do |version| + context "on #{platform.capitalize} #{version}" do + let(:chef_run) do + ChefSpec::ServerRunner.new(platform: platform, version: version) do |node, server| + node_resources(node) + stub_chef_zero(platform, version, server) + end.converge(described_recipe) + end - let(:chef_run) do - ChefSpec::SoloRunner.new(UBUNTU_OPTS) do |node| - node.override['kibana']['install_method'] = 'source' - end.converge(described_recipe) - end + _property = load_platform_properties(platform: platform, platform_version: version) - it 'installs package git' do - expect(chef_run).to install_package('git') - end - it 'checks out /opt/kibana' do - expect(chef_run).to checkout_git('/opt/kibana/current').with(repository: 'https://github.com/elasticsearch/kibana.git') - end + it 'installs package git' do + expect(chef_run).to install_package('git') + end + it 'checks out /opt/kibana' do + expect(chef_run).to checkout_git('/opt/kibana/current').with(repository: 'https://github.com/elasticsearch/kibana.git') + end - it 'creates a template for kibana' do - expect(chef_run).to create_template('/opt/kibana/current/src/config.js').with( - owner: 'kibana', - group: 'kibana', - mode: '0644' - ) + it 'creates a template for kibana' do + expect(chef_run).to create_template('/opt/kibana/current/src/config.js').with( + owner: 'kibana', + group: 'kibana', + mode: '0644' + ) + end + end + end end end diff --git a/test/unit/spec/kibana4_spec.rb b/test/unit/spec/kibana4_spec.rb index 48cfb14..b9d8385 100644 --- a/test/unit/spec/kibana4_spec.rb +++ b/test/unit/spec/kibana4_spec.rb @@ -1,38 +1,47 @@ # frozen_string_literal: true -require 'chefspec' require_relative 'spec_helper' describe 'kibana::kibana4' do before { stub_resources } + supported_platforms.each do |platform, versions| + versions.each do |version| + context "on #{platform.capitalize} #{version}" do + let(:chef_run) do + ChefSpec::ServerRunner.new(platform: platform, version: version) do |node, server| + node_resources(node) + stub_chef_zero(platform, version, server) + node.override['kibana']['version'] = 4 + node.override['kibana']['install_method'] = 'release' + end.converge(described_recipe, 'kibana::_service') + end - let(:chef_run) do - ChefSpec::SoloRunner.new(UBUNTU_OPTS) do |node| - node.override['kibana']['version'] = 4 - node.override['kibana']['install_method'] = 'release' - end.converge(described_recipe, 'kibana::_service') - end - let(:template) { chef_run.template('/opt/kibana/current/config/kibana.yml') } + _property = load_platform_properties(platform: platform, platform_version: version) - it 'includes kibana recipe' do - expect(chef_run).to include_recipe('kibana::default') - end - it 'includes the kibana::_service recipe' do - expect(chef_run).to include_recipe('kibana::_service') - end + let(:template) { chef_run.template('/opt/kibana/current/config/kibana.yml') } - it 'installs kibana4 using ark' do - expect(chef_run).to install_ark('kibana') - end + it 'includes kibana recipe' do + expect(chef_run).to include_recipe('kibana::default') + end + it 'includes the kibana::_service recipe' do + expect(chef_run).to include_recipe('kibana::_service') + end - it 'creates a template for the kibana config' do - expect(chef_run).to create_template('/opt/kibana/current/config/kibana.yml').with( - owner: 'kibana', - group: 'kibana', - mode: '0644' - ) - end - it 'sends a restart notification to the service kibana' do - expect(template).to notify('service[kibana]').to(:restart) + it 'installs kibana4 using ark' do + expect(chef_run).to install_ark('kibana') + end + + it 'creates a template for the kibana config' do + expect(chef_run).to create_template('/opt/kibana/current/config/kibana.yml').with( + owner: 'kibana', + group: 'kibana', + mode: '0644' + ) + end + it 'sends a restart notification to the service kibana' do + expect(template).to notify('service[kibana]').to(:restart) + end + end + end end end diff --git a/test/unit/spec/nginx_spec.rb b/test/unit/spec/nginx_spec.rb index 79b9194..e6c6159 100644 --- a/test/unit/spec/nginx_spec.rb +++ b/test/unit/spec/nginx_spec.rb @@ -5,10 +5,23 @@ describe 'kibana::nginx' do before { stub_resources } + supported_platforms.each do |platform, versions| + versions.each do |version| + context "on #{platform.capitalize} #{version}" do + let(:chef_run) do + ChefSpec::ServerRunner.new(platform: platform, version: version) do |node, server| + node_resources(node) + stub_chef_zero(platform, version, server) + end.converge(described_recipe) + end - let(:chef_run) { ChefSpec::SoloRunner.new(UBUNTU_OPTS).converge(described_recipe) } + # any platform specific data you want available to your test can be loaded here + _property = load_platform_properties(platform: platform, platform_version: version) - it 'converges successfully' do - expect { :chef_run }.to_not raise_error + it 'converges successfully' do + expect { :chef_run }.to_not raise_error + end + end + end end end diff --git a/test/unit/spec/spec_helper.rb b/test/unit/spec/spec_helper.rb index 4379f96..7d0f3e4 100644 --- a/test/unit/spec/spec_helper.rb +++ b/test/unit/spec/spec_helper.rb @@ -1,33 +1,43 @@ # frozen_string_literal: true -# -*- mode: ruby -*- -# vi: set ft=ruby : - require 'rspec/expectations' require 'chefspec' require 'chefspec/berkshelf' require 'chef/application' +require 'json' + +Dir['./test/unit/spec/support/**/*.rb'].sort.each { |f| require f } + +# use node.default or node.set to put stub data for every node in every test +# could also use this method to stub other node-related things like environment +def node_resources(node) + # Stub the node and any calls to Environment.Load to return this environment + env = Chef::Environment.new + env.name 'chefspec' # matches ./test/integration/ + allow(node).to receive(:chef_environment).and_return(env.name) + allow(Chef::Environment).to receive(:load).and_return(env) +end -require 'support/matchers' +# use to stub commands or files or other ruby calls +# e.g. stub_command('/usr/sbin/httpd -t').and_return(0) +def stub_resources + stub_command('/usr/sbin/foo').and_return(0) +end -::LOG_LEVEL = :fatal -::UBUNTU_OPTS = { - platform: 'ubuntu', - version: '14.04' -}.freeze -::UBUNTU_1604_OPTS = { - platform: 'ubuntu', - version: '16.04' -}.freeze -::CENTOS_OPTS = { - platform: 'centos', - version: '6.9' -}.freeze -::CENTOS7_OPTS = { - platform: 'centos', - version: '7.4.1708' -}.freeze +def stub_chef_zero(platform, version, server) + Dir['./test/fixtures/nodes/*.json'].sort.each do |f| + node_data = JSON.parse(IO.read(f), symbolize_names: false) + node_name = node_data['name'] + server.create_node(node_name, node_data) + platform.to_s # pacify rubocop + version.to_s # pacify rubocop + end -def stub_resources; end + Dir['./test/fixtures/environments/*.json'].sort.each do |f| + env_data = JSON.parse(IO.read(f), symbolize_names: false) + env_name = env_data['name'] + server.create_environment(env_name, env_data) + end +end at_exit { ChefSpec::Coverage.report! } diff --git a/test/unit/spec/support/platform_properties.rb b/test/unit/spec/support/platform_properties.rb new file mode 100644 index 0000000..7a5b778 --- /dev/null +++ b/test/unit/spec/support/platform_properties.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'json' + +def load_platform_properties(args) + platform_file_str = "../../../fixtures/platform/#{args[:platform]}/#{args[:platform_version]}.json" + platform_file_name = File.join(File.dirname(__FILE__), platform_file_str) + platform_str = '{}' + platform_str = IO.read(platform_file_name) if File.exist?(platform_file_name) + JSON.parse(platform_str, symbolize_names: false) +end diff --git a/test/unit/spec/support/supported_platforms.rb b/test/unit/spec/support/supported_platforms.rb new file mode 100644 index 0000000..491350b --- /dev/null +++ b/test/unit/spec/support/supported_platforms.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +def supported_platforms + { + 'centos' => ['6.9', '7.4.1708'], + 'ubuntu' => ['14.04', '16.04'] + } +end From e9b432c70c1c679b0218ebb3899580107f430665 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sat, 17 Mar 2018 16:09:05 -0700 Subject: [PATCH 07/21] fix github URL now that Elastic is renamed --- attributes/default.rb | 2 +- test/unit/spec/kibana3_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 1aa54e6..4552081 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -31,7 +31,7 @@ #<> Kibana repository Public Signing Key default['kibana']['repository_key'] = 'https://packages.elastic.co/GPG-KEY-elasticsearch' #<> The URL to Kibana repository. -default['kibana']['git']['url'] = 'https://github.com/elasticsearch/kibana.git' +default['kibana']['git']['url'] = 'https://github.com/elastic/kibana.git' #<> The git reference in the Kibana repository. default['kibana']['git']['reference'] = "v#{node['kibana']['kibana5_version']}" diff --git a/test/unit/spec/kibana3_spec.rb b/test/unit/spec/kibana3_spec.rb index ac423ed..9fb704b 100644 --- a/test/unit/spec/kibana3_spec.rb +++ b/test/unit/spec/kibana3_spec.rb @@ -55,7 +55,7 @@ expect(chef_run).to install_package('git') end it 'checks out /opt/kibana' do - expect(chef_run).to checkout_git('/opt/kibana/current').with(repository: 'https://github.com/elasticsearch/kibana.git') + expect(chef_run).to checkout_git('/opt/kibana/current').with(repository: 'https://github.com/elastic/kibana.git') end it 'creates a template for kibana' do From 4fed5d5ceeb29edcb22da0c879eb1bff4893972a Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sat, 17 Mar 2018 16:35:28 -0700 Subject: [PATCH 08/21] fix test-kitchen run_lists --- .kitchen.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index 8f1e742..6cda189 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -38,7 +38,7 @@ suites: - name: kibana3_nginx run_list: - 'recipe[netstat]' - - 'recipe[chef_nginx]' + - 'recipe[nginx]' - 'recipe[kibana]' - 'recipe[kibana::nginx]' attributes: {} @@ -73,7 +73,7 @@ suites: - name: kibana4_nginx run_list: - 'recipe[netstat]' - - 'recipe[chef_nginx]' + - 'recipe[nginx]' - 'recipe[java]' - 'recipe[elasticsearch]' - 'recipe[kibana]' @@ -106,7 +106,7 @@ suites: - name: kibana4_nginx_package run_list: - 'recipe[netstat]' - - 'recipe[chef_nginx]' + - 'recipe[nginx]' - 'recipe[java]' - 'recipe[elasticsearch]' - 'recipe[kibana]' From f1804816170433d0d46148cabbbc6bfd27b8730b Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sat, 17 Mar 2018 18:09:34 -0700 Subject: [PATCH 09/21] correctly set attr for source install testing enforce version 3 on kibana3 unit tests --- test/unit/spec/kibana3_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unit/spec/kibana3_spec.rb b/test/unit/spec/kibana3_spec.rb index 9fb704b..07a3926 100644 --- a/test/unit/spec/kibana3_spec.rb +++ b/test/unit/spec/kibana3_spec.rb @@ -11,6 +11,7 @@ ChefSpec::ServerRunner.new(platform: platform, version: version) do |node, server| node_resources(node) stub_chef_zero(platform, version, server) + node.override['kibana']['version'] = 3 end.converge(described_recipe) end @@ -46,6 +47,8 @@ ChefSpec::ServerRunner.new(platform: platform, version: version) do |node, server| node_resources(node) stub_chef_zero(platform, version, server) + node.override['kibana']['version'] = 3 + node.override['kibana']['install_method'] = 'source' end.converge(described_recipe) end From fae47ae06033b7410418ba1650814df6e5c967f5 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sat, 17 Mar 2018 19:14:36 -0700 Subject: [PATCH 10/21] make version an int, as required --- .kitchen.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index 6cda189..2474e2d 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -64,7 +64,7 @@ suites: listen: - '*:8080' kibana: - version: '4' + version: 4 apache: port: 8080 interface: '0.0.0.0' @@ -80,7 +80,7 @@ suites: - 'recipe[kibana::nginx]' attributes: kibana: - version: '4' + version: 4 interface: '0.0.0.0' nginx: listen_http: 8080 @@ -97,7 +97,7 @@ suites: - '*:8080' kibana: install_method: 'package' - version: '4' + version: 4 apache: port: 8080 interface: '0.0.0.0' @@ -114,7 +114,7 @@ suites: attributes: kibana: install_method: 'package' - version: '4' + version: 4 interface: '0.0.0.0' nginx: listen_http: 8080 From bbc33db41283bb7cda1cd953cae651c1e4f5cc1a Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sat, 17 Mar 2018 20:26:49 -0700 Subject: [PATCH 11/21] require chef-sugar --- Berksfile | 1 + Gemfile | 1 + 2 files changed, 2 insertions(+) diff --git a/Berksfile b/Berksfile index 5ce69f9..0f10264 100644 --- a/Berksfile +++ b/Berksfile @@ -5,6 +5,7 @@ source 'https://supermarket.chef.io/' metadata cookbook 'compat_resource' +cookbook 'chef-sugar' group :vagrant do cookbook 'ark' diff --git a/Gemfile b/Gemfile index 02830fd..1715a8e 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ gem 'stove' group :test do gem 'buff-extensions' + gem 'chef-sugar' gem 'chefspec' gem 'foodcritic' gem 'rake' From e56a39476d1505b2b8b73ef73c9e217bac2a7017 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sat, 17 Mar 2018 20:35:57 -0700 Subject: [PATCH 12/21] use sysvinit for centos <7 --- attributes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/attributes/default.rb b/attributes/default.rb index 4552081..a55b999 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -141,7 +141,7 @@ # kibana service configurations - defaults to settings for Ubuntu 14.04 case node['platform'] when 'centos', 'amazon' - if node['platform_version'] < '6.9' + if node['platform_version'] < '7.0' default['kibana']['service']['provider'] = Chef::Provider::Service::Init::Redhat default['kibana']['service']['source'] = 'initd.kibana.erb' default['kibana']['service']['template_file'] = '/etc/init.d/kibana' From 0aa1c8abbc08790622c623685dbc90cb39471b08 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sat, 17 Mar 2018 20:38:33 -0700 Subject: [PATCH 13/21] use centos 7.4.1708 & 6.9 --- .kitchen.docker.yml | 4 ++-- .kitchen.yml | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.kitchen.docker.yml b/.kitchen.docker.yml index 636b65f..f49c29d 100644 --- a/.kitchen.docker.yml +++ b/.kitchen.docker.yml @@ -8,8 +8,8 @@ platforms: - name: ubuntu-16.04 driver_config: run_command: /sbin/init - - name: centos-6.4 - - name: centos-7.2 + - name: centos-6.9 + - name: centos-7.4.1708 driver_config: image: centos:7 provision_command: yum -y install initscripts diff --git a/.kitchen.yml b/.kitchen.yml index 2474e2d..c041bd7 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -15,17 +15,14 @@ platforms: - name: ubuntu-16.04 run_list: - recipe[apt] -- name: centos-6.4 - driver_config: - box: opscode-centos-6.4 - box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box +- name: centos-6.9 attributes: yum: epel: mirrorlist: http://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch gpgkey: http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6 sslverify: false -- name: centos-7.2 +- name: centos-7.4.1708 suites: - name: kibana3_apache From bd28b1a356493dc698fcd3a5def59e8641437170 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sat, 17 Mar 2018 20:54:44 -0700 Subject: [PATCH 14/21] try apt_update if debian platform --- recipes/nginx.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/recipes/nginx.rb b/recipes/nginx.rb index 90bef12..33758b9 100644 --- a/recipes/nginx.rb +++ b/recipes/nginx.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +apt_update 'update apt' if node['platform_family'] == 'debian' + include_recipe 'nginx' template File.join(node['nginx']['dir'], 'sites-available', 'kibana') do From b585dbc978a7abb84e1131b1bf4235ac6693c73b Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sat, 17 Mar 2018 21:06:03 -0700 Subject: [PATCH 15/21] fix versions --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index fafb7e7..22472cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,12 +18,12 @@ env: - TESTS="integration:docker[kibana4-apache-ubuntu-1604]" - TESTS="integration:docker[kibana4-nginx-ubuntu-1604]" - TESTS="integration:docker[kibana4-apache-package-ubuntu-1604]" - - TESTS="integration:docker[kibana3-apache-centos-64]" - - TESTS="integration:docker[kibana3-nginx-centos-64]" - - TESTS="integration:docker[kibana4-apache-centos-64]" - - TESTS="integration:docker[kibana4-nginx-centos-64]" - - TESTS="integration:docker[kibana4-apache-centos-72]" - - TESTS="integration:docker[kibana4-nginx-centos-72]" + - TESTS="integration:docker[kibana3-apache-centos-69]" + - TESTS="integration:docker[kibana3-nginx-centos-69]" + - TESTS="integration:docker[kibana4-apache-centos-69]" + - TESTS="integration:docker[kibana4-nginx-centos-69]" + - TESTS="integration:docker[kibana4-apache-centos-741708]" + - TESTS="integration:docker[kibana4-nginx-centos-741708]" before_install: curl -L https://www.getchef.com/chef/install.sh | sudo bash -s -- -P chefdk install: chef exec bundle install --jobs=3 --retry=3 --without='vagrant' From 523240389caf894cb62e969cf089c8a6a4abbe97 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sat, 17 Mar 2018 22:48:27 -0700 Subject: [PATCH 16/21] lint --- test/unit/spec/apache_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/spec/apache_spec.rb b/test/unit/spec/apache_spec.rb index c08b0b5..a7f6fe8 100644 --- a/test/unit/spec/apache_spec.rb +++ b/test/unit/spec/apache_spec.rb @@ -20,7 +20,7 @@ # TODO: creates a template /etc/apache2/htpasswd # TODO: creates a template /etc/apache2/sites-available/kibana.conf - + it 'converges successfully' do expect { :chef_run }.to_not raise_error end From b8dadba894d51cbecae22cca19412d4e661ac6ed Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sat, 17 Mar 2018 23:21:43 -0700 Subject: [PATCH 17/21] remove deprecated require_chef_omnibus --- .kitchen.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.kitchen.yml b/.kitchen.yml index c041bd7..a3aa995 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,7 +1,8 @@ --- driver_plugin: vagrant driver_config: - require_chef_omnibus: 12.7.2 + product_name: chefdk + product_version: 12.7.2 network: - ["forwarded_port", {guest: 8080, host: 8080, auto_correct: true}] From 3f33663dcde5cab7e5bcaebe72219dab65408d9e Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sun, 18 Mar 2018 00:05:22 -0700 Subject: [PATCH 18/21] try specifying chefdk version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 22472cb..41cd61d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ env: - TESTS="integration:docker[kibana4-apache-centos-741708]" - TESTS="integration:docker[kibana4-nginx-centos-741708]" -before_install: curl -L https://www.getchef.com/chef/install.sh | sudo bash -s -- -P chefdk +before_install: curl -L https://www.getchef.com/chef/install.sh -v 1.3.43 | sudo bash -s -- -P chefdk install: chef exec bundle install --jobs=3 --retry=3 --without='vagrant' # https://github.com/zuazo/kitchen-in-travis-native/issues/1#issuecomment-142455888 From 9b75e649acaa26584bea36280f1d9d702f1b3941 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sun, 18 Mar 2018 00:09:08 -0700 Subject: [PATCH 19/21] try specifying chefdk version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 41cd61d..20317ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ env: - TESTS="integration:docker[kibana4-apache-centos-741708]" - TESTS="integration:docker[kibana4-nginx-centos-741708]" -before_install: curl -L https://www.getchef.com/chef/install.sh -v 1.3.43 | sudo bash -s -- -P chefdk +before_install: curl -L https://www.getchef.com/chef/install.sh | sudo bash -s -- -P chefdk -v 1.3.43 install: chef exec bundle install --jobs=3 --retry=3 --without='vagrant' # https://github.com/zuazo/kitchen-in-travis-native/issues/1#issuecomment-142455888 From a450dcd53b07b65e728927f6646f6243dbe06283 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sun, 18 Mar 2018 00:24:21 -0700 Subject: [PATCH 20/21] try specifying chefdk version --- .kitchen.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.kitchen.yml b/.kitchen.yml index a3aa995..5356e01 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -2,7 +2,7 @@ driver_plugin: vagrant driver_config: product_name: chefdk - product_version: 12.7.2 + product_version: 1.3.43 network: - ["forwarded_port", {guest: 8080, host: 8080, auto_correct: true}] From 3fe3c436fe35dd944e721a7214b3b5af63a7e983 Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sun, 18 Mar 2018 01:10:12 -0700 Subject: [PATCH 21/21] use newer elasticsearch cookbook --- Berksfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Berksfile b/Berksfile index 0f10264..94df506 100644 --- a/Berksfile +++ b/Berksfile @@ -12,7 +12,7 @@ group :vagrant do cookbook 'apt' cookbook 'apache2' cookbook 'build-essential' - cookbook 'elasticsearch', '~ 2.4.0' + cookbook 'elasticsearch', '~> 3.4' cookbook 'java' cookbook 'netstat' cookbook 'ohai'