Skip to content

Commit 2017084

Browse files
shortdudey123gmiranda23
authored andcommitted
PR 76: Testing suite overhauled
Signed-off-by: gmiranda23 <[email protected]>
1 parent 103c84e commit 2017084

16 files changed

+141
-70
lines changed

.kitchen.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ driver_config:
55
memory: 1024
66

77
platforms:
8+
- name: ubuntu-14.04
9+
run_list:
10+
- recipe[apt]
811
- name: ubuntu-12.04
912
run_list:
1013
- recipe[apt]

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--color

.rubocop.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
AllCops:
2-
Excludes:
2+
Exclude:
33
- vendor/**
44

5-
AlignParameters:
6-
Enabled: false
7-
Encoding:
5+
Style/SingleSpaceBeforeFirstArg:
86
Enabled: false
7+
98
HashSyntax:
109
Enabled: false
10+
1111
LineLength:
1212
Enabled: false
13+
1314
MethodLength:
1415
Max: 30
16+
17+
Lint/UnusedBlockArgument:
18+
Enabled: false
19+
20+
Style/BlockComments:
21+
Enabled: false

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ language: ruby
22
rvm:
33
- 1.9.3
44
- 2.0.0
5+
- 2.1.5
6+
bundler_args: --without integration
57
before_script:
68
- bundle exec berks install
79
script:
8-
- bundle exec rubocop
9-
- bundle exec foodcritic -f any --tags ~FC023 .
10-
- bundle exec rspec --color --format progress
10+
- bundle exec rake

Gemfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
source 'https://rubygems.org'
22

33
gem 'berkshelf', '~> 2.0'
4-
gem 'chefspec', '~> 2.0'
5-
gem 'foodcritic', '~> 3.0'
6-
gem 'rubocop', '~> 0.23'
4+
gem 'chefspec', '~> 4.0'
5+
gem 'foodcritic', '~> 4.0'
6+
gem 'rubocop', '~> 0.27.1'
77

88
group :integration do
9-
gem 'test-kitchen', '~> 1.2'
9+
gem 'test-kitchen', '~> 1.2.1'
1010
gem 'kitchen-vagrant', '~> 0.15'
1111
end

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
NTP Cookbook
22
============
3-
[![Build Status](https://secure.travis-ci.org/opscode-cookbooks/ntp.png?branch=master)](http://travis-ci.org/opscode-cookbooks/ntp)
3+
[![Build Status](https://secure.travis-ci.org/gmiranda23/ntp.png?branch=master)](http://travis-ci.org/gmiranda23/ntp)
44

55
Installs and configures ntp. On Windows systems it uses the Meinberg port of the standard NTPd client to Windows.
66

@@ -157,7 +157,7 @@ If for some reason you need to stop and remove the ntp daemon, you can apply thi
157157

158158
### windows_client recipe
159159

160-
Windows only. Apply on a Windows host to install the Meinberg NTPd client.
160+
Windows only. Apply on a Windows host to install the Meinberg NTPd client.
161161

162162

163163
Development
@@ -179,10 +179,8 @@ This section details "quick development" steps. For a detailed explanation, see
179179
4. **Write tests**
180180
5. Make your changes/patches/fixes, committing appropriately
181181
6. Run the tests:
182-
- `bundle exec foodcritic -f any .`
183-
- `bundle exec rspec`
184-
- `bundle exec rubocop`
185-
- `bundle exec kitchen test`
182+
- `bundle exec rake`
183+
- `bundle exec rake kitchen`
186184

187185
In detail:
188186
- Foodcritic will catch any Chef-specific style errors

Rakefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env rake
2+
3+
require 'foodcritic'
4+
require 'rspec/core/rake_task'
5+
require 'rubocop/rake_task'
6+
7+
task :default => [
8+
:style,
9+
:spec
10+
]
11+
task :kitchen => [
12+
'kitchen:all'
13+
]
14+
15+
# Style tests. Rubocop and Foodcritic
16+
namespace :style do
17+
desc 'Run Ruby style checks'
18+
RuboCop::RakeTask.new(:ruby)
19+
20+
desc 'Run Chef style checks'
21+
FoodCritic::Rake::LintTask.new(:chef)
22+
end
23+
24+
desc 'Run all style checks'
25+
task style: ['style:chef', 'style:ruby']
26+
27+
# Rspec and ChefSpec
28+
desc 'Run ChefSpec examples'
29+
RSpec::Core::RakeTask.new(:spec)
30+
31+
begin
32+
require 'kitchen/rake_tasks'
33+
Kitchen::RakeTasks.new
34+
rescue LoadError
35+
puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI']
36+
end

TESTING.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ Development
4242
5. Write tests to support those changes. It is highly recommended you write both unit and integration tests.
4343
6. Run the tests:
4444

45-
- `bundle exec rspec`
46-
- `bundle exec foodcritic .`
47-
- `bundle exec rubocop`
48-
- `bundle exec kitchen test`
45+
- `bundle exec rake`
46+
- `bundle exec rake kitchen`
4947

5048
7. Assuming the tests pass, open a Pull Request on GitHub
5149
8. Open a JIRA ticket for this component, linking the JIRA ticket to the Pull Request and visa versa.

metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
recipe 'ntp', 'Installs and configures ntp either as a server or client'
1010

11-
%w{ amazon centos debian fedora freebsd gentoo redhat scientific solaris2 oracle ubuntu windows xcp }.each do |os|
11+
%w( amazon centos debian fedora freebsd gentoo redhat scientific solaris2 oracle ubuntu windows xcp ).each do |os|
1212
supports os
1313
end
1414

recipes/default.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,10 @@
9999
end
100100
end
101101

102-
if node['ntp']['sync_hw_clock'] && !platform_family?('windows')
103-
execute 'Force sync hardware clock with system clock' do
104-
command 'hwclock --systohc'
105-
action :run
106-
end
102+
execute 'Force sync hardware clock with system clock' do
103+
command 'hwclock --systohc'
104+
action :run
105+
only_if { node['ntp']['sync_hw_clock'] && !platform_family?('windows') }
107106
end
108107

109108
service node['ntp']['service'] do

recipes/windows_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
only_if { node['kernel']['release'].to_f < 6 }
4242
end
4343

44-
unless File.exists?('C:/NTP/bin/ntpd.exe')
44+
unless File.exist?('C:/NTP/bin/ntpd.exe')
4545
remote_file "#{Chef::Config[:file_cache_path]}/ntpd.exe" do
4646
source node['ntp']['package_url']
4747
end

spec/unit/attributes_spec.rb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
require 'spec_helper'
2525

2626
describe 'ntp attributes' do
27-
let(:chef_run) { ChefSpec::ChefRunner.new.converge('ntp::default') }
27+
let(:chef_run) { ChefSpec::SoloRunner.new.converge('ntp::default') }
2828
let(:ntp) { chef_run.node['ntp'] }
2929

3030
describe 'on an unknown platform' do
@@ -88,23 +88,23 @@
8888
end
8989

9090
describe 'on Debian-family platforms' do
91-
let(:chef_run) { ChefSpec::ChefRunner.new(platform: 'ubuntu', version: '12.04').converge('ntp::default') }
91+
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '12.04').converge('ntp::default') }
9292

9393
it 'sets the service name to ntp' do
9494
expect(ntp['service']).to eq('ntp')
9595
end
9696
end
9797

9898
describe 'on Ubuntu' do
99-
let(:chef_run) { ChefSpec::ChefRunner.new(platform: 'ubuntu', version: '12.04').converge('ntp::default') }
99+
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '12.04').converge('ntp::default') }
100100

101101
it 'sets the apparmor_enabled attribute to true' do
102102
expect(ntp['apparmor_enabled']).to eq(true)
103103
end
104104
end
105105

106106
describe 'on the CentOS 5 platform' do
107-
let(:chef_run) { ChefSpec::ChefRunner.new(platform: 'centos', version: '5.8').converge('ntp::default') }
107+
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'centos', version: '5.8').converge('ntp::default') }
108108

109109
it 'sets the package list to only ntp' do
110110
expect(ntp['packages']).to include('ntp')
@@ -113,8 +113,26 @@
113113
end
114114

115115
describe 'on the Windows platform' do
116-
let(:chef_run) { ChefSpec::ChefRunner.new(platform: 'windows', version: '2008R2').converge('ntp::default') }
116+
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'windows', version: '2008R2').converge('ntp::default') }
117117

118+
# chefspec can not check windows reliably so skip these tests for now
119+
it 'sets the service name to NTP'
120+
121+
it 'sets the drift file to /var/db/ntpd.drift'
122+
123+
it 'sets the conf file to /etc/ntp.conf'
124+
125+
it 'sets the conf_owner to root'
126+
127+
it 'sets the conf_group to root'
128+
129+
it 'sets the package_url correctly'
130+
131+
it 'sets the vs_runtime_url correctly'
132+
133+
it 'sets the vs_runtime_productname correctly'
134+
135+
=begin
118136
it 'sets the service name to NTP' do
119137
pending('ChefSpec does not yet understand the inherits attribute in cookbook_file resources')
120138
expect(ntp['service']).to eq('NTP')
@@ -154,10 +172,12 @@
154172
pending('ChefSpec does not yet understand the inherits attribute in cookbook_file resources')
155173
expect(ntp['vs_runtime_productname']).to eq('Microsoft Visual C++ 2008 Redistributable - x86 9.0.21022')
156174
end
175+
=end
176+
157177
end
158178

159179
describe 'on the FreeBSD platform' do
160-
let(:chef_run) { ChefSpec::ChefRunner.new(platform: 'freebsd', version: '9.1').converge('ntp::default') }
180+
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'freebsd', version: '9.1').converge('ntp::default') }
161181

162182
it 'sets the package list to only ntp' do
163183
expect(ntp['packages']).to include('ntp')

spec/unit/recipes/apparmor_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
require 'spec_helper'
22

33
describe 'ntp::apparmor' do
4-
let(:chef_run) { ChefSpec::ChefRunner.new.converge('recipe[ntp::apparmor]') }
4+
let(:chef_run) { ChefSpec::SoloRunner.new.converge('recipe[ntp::apparmor]') }
55

66
it 'creates the apparmor file' do
77
expect(chef_run).to create_cookbook_file '/etc/apparmor.d/usr.sbin.ntpd'
88
file = chef_run.cookbook_file('/etc/apparmor.d/usr.sbin.ntpd')
9-
expect(file).to be_owned_by('root', 'root')
9+
expect(file.owner).to eq('root')
10+
expect(file.group).to eq('root')
1011
end
1112

1213
it 'restarts the apparmor service' do
13-
chef_run.cookbook_file('/etc/apparmor.d/usr.sbin.ntpd').should notify('service[apparmor]', :restart)
14+
expect(chef_run.cookbook_file('/etc/apparmor.d/usr.sbin.ntpd')).to notify('service[apparmor]').to(:restart)
1415
end
1516

1617
end

0 commit comments

Comments
 (0)