From 7c3b8c4be613c4d19b071f1615f04a2f26b5eb43 Mon Sep 17 00:00:00 2001 From: silviabotros Date: Fri, 27 Jun 2014 12:42:29 -0600 Subject: [PATCH] added minitests. New minor version --- .kitchen.yml | 3 +- Berksfile | 1 + CHANGELOG.md | 6 +++ Gemfile | 1 + files/default/tests/minitests/default_test.rb | 37 +++++++++++++++++++ metadata.rb | 2 +- spec/recipes/_database_setup_spec.rb | 12 ++---- 7 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 files/default/tests/minitests/default_test.rb diff --git a/.kitchen.yml b/.kitchen.yml index 8d12154..b5c47d8 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -7,7 +7,7 @@ driver: - ['forwarded_port', {guest: 3000, host: 3000, auto_correct: true}] provisioner: - name: chef_solo + name: chef_zero platforms: - name: ubuntu-12.04 @@ -17,4 +17,5 @@ suites: - name: default run_list: - recipe[orchestrator::default] + - recipe[minitest-handler] attributes: diff --git a/Berksfile b/Berksfile index 2e1a070..c785886 100644 --- a/Berksfile +++ b/Berksfile @@ -1,3 +1,4 @@ source "https://api.berkshelf.com" metadata +cookbook 'minitest-handler', :git => 'https://github.com/btm/minitest-handler-cookbook.git' diff --git a/CHANGELOG.md b/CHANGELOG.md index 04b08b8..19cd9c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.2.0 +Added minitests + +# 1.1.1 +Chefspec passes and 100% coverage + # 1.1.0 Added Chefspec tests diff --git a/Gemfile b/Gemfile index 61afc9f..195d4f9 100644 --- a/Gemfile +++ b/Gemfile @@ -18,3 +18,4 @@ gem 'thor-foodcritic' gem 'test-kitchen' gem 'kitchen-vagrant' gem "chefspec" +gem 'minitest-chef-handler' diff --git a/files/default/tests/minitests/default_test.rb b/files/default/tests/minitests/default_test.rb new file mode 100644 index 0000000..55e8ce7 --- /dev/null +++ b/files/default/tests/minitests/default_test.rb @@ -0,0 +1,37 @@ +require 'minitest/spec' +require 'chef/mixin/shell_out' +# +# Cookbook Name:: orchestrator +# Spec:: default +# + +describe_recipe 'orchestrator::default' do + include Chef::Mixin::ShellOut + include Minitest::Chef::Assertions + include Minitest::Chef::Context + include Minitest::Chef::Resources + + describe "runs orchestrator" do + it 'is running mysql' do + service("mysql").must_be_running + end + it 'has an orchestrator db' do + assert_sh('mysql -e "show databases" | grep orchestrator') + end + it 'has an orchestrator user' do + assert_sh('mysql -e "select user from mysql.user" | grep orchestrator') + end + it 'installs orchestrator' do + package('orchestrator').must_be_installed + end + it 'creates the cfg file' do + file('/etc/orchestrator.conf.json').must_exist + end + it 'removes the packaged cfg file' do + file('/usr/local/orchestrator/conf/orchestrator.conf.json').wont_exist + end + it 'has a process named orchestrator running' do + assert_sh('ps aux | grep orchestrator | grep -v grep') + end + end +end diff --git a/metadata.rb b/metadata.rb index feb642c..4794487 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'All rights reserved' description 'Installs/Configures chef-orchestrator' long_description 'Installs/Configures chef-orchestrator' -version '1.1.0' +version '1.2.0' depends 'yum' depends 'database' diff --git a/spec/recipes/_database_setup_spec.rb b/spec/recipes/_database_setup_spec.rb index 7bc7cc5..3e77118 100644 --- a/spec/recipes/_database_setup_spec.rb +++ b/spec/recipes/_database_setup_spec.rb @@ -17,17 +17,13 @@ expect(chef_run).to enable_service('mysql') expect(chef_run).to start_service('mysql') end - it 'doesnt make orchestrator db if it finds it' do - stub_command("mysql -e 'show databases' | grep orchestrator").and_return(true) - expect(chef_run).to_not create_database('orchestrator') - end - it 'makes orchestrator if it is not found' do + it 'makes the orchestrator db when needed' do stub_command("mysql -e 'show databases' | grep orchestrator").and_return(false) - expect(chef_run).to run_execute('create database orchestrator') + expect(chef_run).to create_mysql_database('orchestrator') end - it 'created orchestrator user' do + it 'creates orchestrator user' do stub_command("mysql -e 'select user from mysql.users' | grep orchestrator").and_return(false) - expect(chef_run).to grant_database_user('orchestrator') + expect(chef_run).to grant_mysql_database_user('orchestrator') end it 'sets the root pass' do stub_command("mysql -u root -pfakepass")