serverspec 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Guardfile +4 -0
- data/lib/serverspec/commands/base.rb +5 -1
- data/lib/serverspec/commands/solaris.rb +5 -1
- data/lib/serverspec/helper/type.rb +15 -8
- data/lib/serverspec/matchers.rb +0 -1
- data/lib/serverspec/matchers/have_entry.rb +10 -2
- data/lib/serverspec/matchers/return_exit_status.rb +6 -2
- data/lib/serverspec/matchers/return_stderr.rb +8 -4
- data/lib/serverspec/matchers/return_stdout.rb +8 -4
- data/lib/serverspec/type/base.rb +1 -1
- data/lib/serverspec/type/command.rb +31 -0
- data/lib/serverspec/type/cron.rb +12 -0
- data/lib/serverspec/version.rb +1 -1
- data/serverspec.gemspec +2 -0
- data/spec/darwin/command_spec.rb +13 -0
- data/spec/darwin/commands_spec.rb +9 -2
- data/spec/darwin/cron_spec.rb +8 -0
- data/spec/darwin/file_spec.rb +1 -1
- data/spec/darwin/port_spec.rb +1 -1
- data/spec/debian/command_spec.rb +13 -0
- data/spec/debian/commands_spec.rb +9 -2
- data/spec/debian/cron_spec.rb +8 -0
- data/spec/debian/file_spec.rb +1 -1
- data/spec/debian/port_spec.rb +1 -1
- data/spec/gentoo/command_spec.rb +13 -0
- data/spec/gentoo/commands_spec.rb +9 -2
- data/spec/gentoo/cron_spec.rb +8 -0
- data/spec/gentoo/file_spec.rb +1 -1
- data/spec/gentoo/port_spec.rb +1 -1
- data/spec/redhat/command_spec.rb +13 -0
- data/spec/redhat/commands_spec.rb +9 -2
- data/spec/redhat/cron_spec.rb +8 -0
- data/spec/redhat/file_spec.rb +1 -1
- data/spec/redhat/port_spec.rb +1 -1
- data/spec/solaris/command_spec.rb +13 -0
- data/spec/solaris/commands_spec.rb +9 -2
- data/spec/solaris/cron_spec.rb +8 -0
- data/spec/solaris/file_spec.rb +1 -1
- data/spec/solaris/port_spec.rb +1 -1
- data/spec/support/shared_command_examples.rb +108 -0
- data/spec/support/shared_cron_examples.rb +23 -0
- metadata +61 -3
- data/lib/serverspec/matchers/be_installed_by_gem.rb +0 -16
data/Guardfile
ADDED
@@ -109,7 +109,11 @@ module Serverspec
|
|
109
109
|
|
110
110
|
def check_cron_entry user, entry
|
111
111
|
entry_escaped = entry.gsub(/\*/, '\\*')
|
112
|
-
|
112
|
+
if user.nil?
|
113
|
+
"crontab -l | grep -- #{escape(entry_escaped)}"
|
114
|
+
else
|
115
|
+
"crontab -u #{escape(user)} -l | grep -- #{escape(entry_escaped)}"
|
116
|
+
end
|
113
117
|
end
|
114
118
|
|
115
119
|
def check_link link, target
|
@@ -20,7 +20,11 @@ module Serverspec
|
|
20
20
|
|
21
21
|
def check_cron_entry user, entry
|
22
22
|
entry_escaped = entry.gsub(/\*/, '\\*')
|
23
|
-
|
23
|
+
if user.nil?
|
24
|
+
"crontab -l | grep -- #{escape(entry_escaped)}"
|
25
|
+
else
|
26
|
+
"crontab -l #{escape(user)} | grep -- #{escape(entry_escaped)}"
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
def check_zfs zfs, property=nil
|
@@ -1,14 +1,21 @@
|
|
1
|
-
require 'serverspec/type/base'
|
2
|
-
require 'serverspec/type/service'
|
3
|
-
require 'serverspec/type/package'
|
4
|
-
require 'serverspec/type/port'
|
5
|
-
require 'serverspec/type/file'
|
6
|
-
|
7
1
|
module Serverspec
|
8
2
|
module Helper
|
9
3
|
module Type
|
10
|
-
%w(
|
11
|
-
|
4
|
+
types = %w(
|
5
|
+
base
|
6
|
+
service
|
7
|
+
package
|
8
|
+
port
|
9
|
+
file
|
10
|
+
cron
|
11
|
+
command
|
12
|
+
)
|
13
|
+
|
14
|
+
types.each {|type| require "serverspec/type/#{type}" }
|
15
|
+
|
16
|
+
types.each do |type|
|
17
|
+
define_method type do |*args|
|
18
|
+
name = args.first
|
12
19
|
self.class.const_get('Serverspec').const_get('Type').const_get(type.capitalize).new(name)
|
13
20
|
end
|
14
21
|
end
|
data/lib/serverspec/matchers.rb
CHANGED
@@ -17,7 +17,6 @@ require 'serverspec/matchers/be_grouped_into'
|
|
17
17
|
require 'serverspec/matchers/have_entry'
|
18
18
|
require 'serverspec/matchers/have_cron_entry'
|
19
19
|
require 'serverspec/matchers/be_linked_to'
|
20
|
-
require 'serverspec/matchers/be_installed_by_gem'
|
21
20
|
require 'serverspec/matchers/belong_to_group'
|
22
21
|
require 'serverspec/matchers/have_gid'
|
23
22
|
require 'serverspec/matchers/have_uid'
|
@@ -1,5 +1,13 @@
|
|
1
|
-
RSpec::Matchers.define :have_entry do |
|
1
|
+
RSpec::Matchers.define :have_entry do |entry|
|
2
2
|
match do |subject|
|
3
|
-
|
3
|
+
if subject.class.name == 'Serverspec::Type::Cron'
|
4
|
+
subject.has_entry?(@user, entry)
|
5
|
+
else
|
6
|
+
backend.check_routing_table(example, entry)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
# For cron type
|
10
|
+
chain :with_user do |user|
|
11
|
+
@user = user
|
4
12
|
end
|
5
13
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
RSpec::Matchers.define :return_exit_status do |status|
|
2
2
|
match do |command|
|
3
|
-
|
4
|
-
|
3
|
+
if command.respond_to?(:return_exit_status?)
|
4
|
+
command.return_exit_status?(status)
|
5
|
+
else
|
6
|
+
ret = backend.run_command(command)
|
7
|
+
ret[:exit_status].to_i == status
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
RSpec::Matchers.define :return_stderr do |content|
|
2
2
|
match do |command|
|
3
|
-
|
4
|
-
|
5
|
-
ret[:stderr] =~ content
|
3
|
+
if command.respond_to?(:return_stderr?)
|
4
|
+
command.return_stderr?(content)
|
6
5
|
else
|
7
|
-
ret
|
6
|
+
ret = backend.run_command(command)
|
7
|
+
if content.instance_of?(Regexp)
|
8
|
+
ret[:stderr] =~ content
|
9
|
+
else
|
10
|
+
ret[:stderr].strip == content
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
RSpec::Matchers.define :return_stdout do |content|
|
2
2
|
match do |command|
|
3
|
-
|
4
|
-
|
5
|
-
ret[:stdout] =~ content
|
3
|
+
if command.respond_to?(:return_stdout?)
|
4
|
+
command.return_stdout?(content)
|
6
5
|
else
|
7
|
-
ret
|
6
|
+
ret = backend.run_command(command)
|
7
|
+
if content.instance_of?(Regexp)
|
8
|
+
ret[:stdout] =~ content
|
9
|
+
else
|
10
|
+
ret[:stdout].strip == content
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
data/lib/serverspec/type/base.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Serverspec
|
2
|
+
module Type
|
3
|
+
class Command < Base
|
4
|
+
def return_stdout?(content)
|
5
|
+
ret = backend.run_command(@name)
|
6
|
+
if content.instance_of?(Regexp)
|
7
|
+
ret[:stdout] =~ content
|
8
|
+
else
|
9
|
+
ret[:stdout].strip == content
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def return_stderr?(content)
|
14
|
+
ret = backend.run_command(@name)
|
15
|
+
# In ssh access with pty, stderr is merged to stdout
|
16
|
+
# See http://stackoverflow.com/questions/7937651/receiving-extended-data-with-ssh-using-twisted-conch-as-client
|
17
|
+
# So I use stdout instead of stderr
|
18
|
+
if content.instance_of?(Regexp)
|
19
|
+
ret[:stdout] =~ content
|
20
|
+
else
|
21
|
+
ret[:stdout].strip == content
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def return_exit_status?(status)
|
26
|
+
ret = backend.run_command(@name)
|
27
|
+
ret[:exit_status].to_i == status
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/serverspec/version.rb
CHANGED
data/serverspec.gemspec
CHANGED
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency "highline"
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
25
|
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "guard-rspec"
|
27
|
+
spec.add_development_dependency "growl"
|
26
28
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Serverspec::Helper::Darwin
|
4
|
+
|
5
|
+
describe 'Serverspec command matchers of Darwin family' do
|
6
|
+
it_behaves_like 'support command return_stdout matcher', 'cat /etc/resolv.conf', 'localhost'
|
7
|
+
it_behaves_like 'support command return_stdout matcher with regexp', 'cat /etc/resolv.conf', /localhost/
|
8
|
+
|
9
|
+
it_behaves_like 'support command return_stderr matcher', 'cat /foo', 'cat: /foo: No such file or directory'
|
10
|
+
it_behaves_like 'support command return_stderr matcher with regexp', 'cat /foo', /No such file or directory/
|
11
|
+
|
12
|
+
it_behaves_like 'support command return_exit_status matcher', 'ls /tmp', 0
|
13
|
+
end
|
@@ -130,8 +130,15 @@ describe 'check_grouped' do
|
|
130
130
|
end
|
131
131
|
|
132
132
|
describe 'check_cron_entry' do
|
133
|
-
|
134
|
-
|
133
|
+
context 'specify root user' do
|
134
|
+
subject { commands.check_cron_entry('root', '* * * * * /usr/local/bin/batch.sh') }
|
135
|
+
it { should eq 'crontab -u root -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'no specified user' do
|
139
|
+
subject { commands.check_cron_entry(nil, '* * * * * /usr/local/bin/batch.sh') }
|
140
|
+
it { should eq 'crontab -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
141
|
+
end
|
135
142
|
end
|
136
143
|
|
137
144
|
describe 'check_link' do
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Serverspec::Helper::Darwin
|
4
|
+
|
5
|
+
describe 'Serverspec cron matchers of Darwin family' do
|
6
|
+
it_behaves_like 'support cron have_entry matcher', '* * * * * /usr/local/bin/batch.sh'
|
7
|
+
it_behaves_like 'support cron have_entry with user matcher', '* * * * * /usr/local/bin/batch.sh', 'root'
|
8
|
+
end
|
data/spec/darwin/file_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Darwin
|
4
4
|
|
5
|
-
describe 'Serverspec
|
5
|
+
describe 'Serverspec file matchers of Darwin family' do
|
6
6
|
it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
|
7
7
|
it_behaves_like 'support file be_directory matcher', '/etc/ssh'
|
8
8
|
it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
|
data/spec/darwin/port_spec.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Serverspec::Helper::Debian
|
4
|
+
|
5
|
+
describe 'Serverspec command matchers of Debian family' do
|
6
|
+
it_behaves_like 'support command return_stdout matcher', 'cat /etc/resolv.conf', 'localhost'
|
7
|
+
it_behaves_like 'support command return_stdout matcher with regexp', 'cat /etc/resolv.conf', /localhost/
|
8
|
+
|
9
|
+
it_behaves_like 'support command return_stderr matcher', 'cat /foo', 'cat: /foo: No such file or directory'
|
10
|
+
it_behaves_like 'support command return_stderr matcher with regexp', 'cat /foo', /No such file or directory/
|
11
|
+
|
12
|
+
it_behaves_like 'support command return_exit_status matcher', 'ls /tmp', 0
|
13
|
+
end
|
@@ -142,8 +142,15 @@ describe 'check_grouped' do
|
|
142
142
|
end
|
143
143
|
|
144
144
|
describe 'check_cron_entry' do
|
145
|
-
|
146
|
-
|
145
|
+
context 'specify root user' do
|
146
|
+
subject { commands.check_cron_entry('root', '* * * * * /usr/local/bin/batch.sh') }
|
147
|
+
it { should eq 'crontab -u root -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'no specified user' do
|
151
|
+
subject { commands.check_cron_entry(nil, '* * * * * /usr/local/bin/batch.sh') }
|
152
|
+
it { should eq 'crontab -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
153
|
+
end
|
147
154
|
end
|
148
155
|
|
149
156
|
describe 'check_link' do
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Serverspec::Helper::Debian
|
4
|
+
|
5
|
+
describe 'Serverspec cron matchers of Debian family' do
|
6
|
+
it_behaves_like 'support cron have_entry matcher', '* * * * * /usr/local/bin/batch.sh'
|
7
|
+
it_behaves_like 'support cron have_entry with user matcher', '* * * * * /usr/local/bin/batch.sh', 'root'
|
8
|
+
end
|
data/spec/debian/file_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Debian
|
4
4
|
|
5
|
-
describe 'Serverspec
|
5
|
+
describe 'Serverspec file matchers of Debian family' do
|
6
6
|
it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
|
7
7
|
it_behaves_like 'support file be_directory matcher', '/etc/ssh'
|
8
8
|
it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
|
data/spec/debian/port_spec.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Serverspec::Helper::Gentoo
|
4
|
+
|
5
|
+
describe 'Serverspec command matchers of Gentoo family' do
|
6
|
+
it_behaves_like 'support command return_stdout matcher', 'cat /etc/resolv.conf', 'localhost'
|
7
|
+
it_behaves_like 'support command return_stdout matcher with regexp', 'cat /etc/resolv.conf', /localhost/
|
8
|
+
|
9
|
+
it_behaves_like 'support command return_stderr matcher', 'cat /foo', 'cat: /foo: No such file or directory'
|
10
|
+
it_behaves_like 'support command return_stderr matcher with regexp', 'cat /foo', /No such file or directory/
|
11
|
+
|
12
|
+
it_behaves_like 'support command return_exit_status matcher', 'ls /tmp', 0
|
13
|
+
end
|
@@ -138,8 +138,15 @@ describe 'check_grouped' do
|
|
138
138
|
end
|
139
139
|
|
140
140
|
describe 'check_cron_entry' do
|
141
|
-
|
142
|
-
|
141
|
+
context 'specify root user' do
|
142
|
+
subject { commands.check_cron_entry('root', '* * * * * /usr/local/bin/batch.sh') }
|
143
|
+
it { should eq 'crontab -u root -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'no specified user' do
|
147
|
+
subject { commands.check_cron_entry(nil, '* * * * * /usr/local/bin/batch.sh') }
|
148
|
+
it { should eq 'crontab -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
149
|
+
end
|
143
150
|
end
|
144
151
|
|
145
152
|
describe 'check_link' do
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Serverspec::Helper::Gentoo
|
4
|
+
|
5
|
+
describe 'Serverspec cron matchers of Gentoo family' do
|
6
|
+
it_behaves_like 'support cron have_entry matcher', '* * * * * /usr/local/bin/batch.sh'
|
7
|
+
it_behaves_like 'support cron have_entry with user matcher', '* * * * * /usr/local/bin/batch.sh', 'root'
|
8
|
+
end
|
data/spec/gentoo/file_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Gentoo
|
4
4
|
|
5
|
-
describe 'Serverspec
|
5
|
+
describe 'Serverspec file matchers of Gentoo family' do
|
6
6
|
it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
|
7
7
|
it_behaves_like 'support file be_directory matcher', '/etc/ssh'
|
8
8
|
it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
|
data/spec/gentoo/port_spec.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Serverspec::Helper::RedHat
|
4
|
+
|
5
|
+
describe 'Serverspec command matchers of Red Hat family' do
|
6
|
+
it_behaves_like 'support command return_stdout matcher', 'cat /etc/resolv.conf', 'localhost'
|
7
|
+
it_behaves_like 'support command return_stdout matcher with regexp', 'cat /etc/resolv.conf', /localhost/
|
8
|
+
|
9
|
+
it_behaves_like 'support command return_stderr matcher', 'cat /foo', 'cat: /foo: No such file or directory'
|
10
|
+
it_behaves_like 'support command return_stderr matcher with regexp', 'cat /foo', /No such file or directory/
|
11
|
+
|
12
|
+
it_behaves_like 'support command return_exit_status matcher', 'ls /tmp', 0
|
13
|
+
end
|
@@ -140,8 +140,15 @@ describe 'check_grouped' do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
describe 'check_cron_entry' do
|
143
|
-
|
144
|
-
|
143
|
+
context 'specify root user' do
|
144
|
+
subject { commands.check_cron_entry('root', '* * * * * /usr/local/bin/batch.sh') }
|
145
|
+
it { should eq 'crontab -u root -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'no specified user' do
|
149
|
+
subject { commands.check_cron_entry(nil, '* * * * * /usr/local/bin/batch.sh') }
|
150
|
+
it { should eq 'crontab -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
151
|
+
end
|
145
152
|
end
|
146
153
|
|
147
154
|
describe 'check_link' do
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Serverspec::Helper::RedHat
|
4
|
+
|
5
|
+
describe 'Serverspec cron matchers of Red Hat family' do
|
6
|
+
it_behaves_like 'support cron have_entry matcher', '* * * * * /usr/local/bin/batch.sh'
|
7
|
+
it_behaves_like 'support cron have_entry with user matcher', '* * * * * /usr/local/bin/batch.sh', 'root'
|
8
|
+
end
|
data/spec/redhat/file_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::RedHat
|
4
4
|
|
5
|
-
describe 'Serverspec
|
5
|
+
describe 'Serverspec file matchers of Red Hat family' do
|
6
6
|
it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
|
7
7
|
it_behaves_like 'support file be_directory matcher', '/etc/ssh'
|
8
8
|
it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
|
data/spec/redhat/port_spec.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Serverspec::Helper::Solaris
|
4
|
+
|
5
|
+
describe 'Serverspec command matchers of Solaris family' do
|
6
|
+
it_behaves_like 'support command return_stdout matcher', 'cat /etc/resolv.conf', 'localhost'
|
7
|
+
it_behaves_like 'support command return_stdout matcher with regexp', 'cat /etc/resolv.conf', /localhost/
|
8
|
+
|
9
|
+
it_behaves_like 'support command return_stderr matcher', 'cat /foo', 'cat: /foo: No such file or directory'
|
10
|
+
it_behaves_like 'support command return_stderr matcher with regexp', 'cat /foo', /No such file or directory/
|
11
|
+
|
12
|
+
it_behaves_like 'support command return_exit_status matcher', 'ls /tmp', 0
|
13
|
+
end
|
@@ -140,8 +140,15 @@ describe 'check_grouped' do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
describe 'check_cron_entry' do
|
143
|
-
|
144
|
-
|
143
|
+
context 'specify root user' do
|
144
|
+
subject { commands.check_cron_entry('root', '* * * * * /usr/local/bin/batch.sh') }
|
145
|
+
it { should eq 'crontab -l root | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'no specified user' do
|
149
|
+
subject { commands.check_cron_entry(nil, '* * * * * /usr/local/bin/batch.sh') }
|
150
|
+
it { should eq 'crontab -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
151
|
+
end
|
145
152
|
end
|
146
153
|
|
147
154
|
describe 'check_link' do
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Serverspec::Helper::Solaris
|
4
|
+
|
5
|
+
describe 'Serverspec cron matchers of Solaris family' do
|
6
|
+
it_behaves_like 'support cron have_entry matcher', '* * * * * /usr/local/bin/batch.sh'
|
7
|
+
it_behaves_like 'support cron have_entry with user matcher', '* * * * * /usr/local/bin/batch.sh', 'root'
|
8
|
+
end
|
data/spec/solaris/file_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Solaris
|
4
4
|
|
5
|
-
describe 'Serverspec
|
5
|
+
describe 'Serverspec file matchers of Solaris family' do
|
6
6
|
it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
|
7
7
|
it_behaves_like 'support file be_directory matcher', '/etc/ssh'
|
8
8
|
it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
|
data/spec/solaris/port_spec.rb
CHANGED
@@ -0,0 +1,108 @@
|
|
1
|
+
shared_examples_for 'support command return_stdout matcher' do |name, content|
|
2
|
+
describe 'return_stdout' do
|
3
|
+
describe command(name) do
|
4
|
+
before :all do
|
5
|
+
RSpec.configure do |c|
|
6
|
+
c.stdout = "#{content}\r\n"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
it { should return_stdout(content) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe command(name) do
|
13
|
+
before :all do
|
14
|
+
RSpec.configure do |c|
|
15
|
+
c.stdout = "foo#{content}bar\r\n"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
it { should_not return_stdout(content) }
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
describe command('invalid-command') do
|
23
|
+
it { should_not return_stdout(content) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
shared_examples_for 'support command return_stdout matcher with regexp' do |name, content|
|
29
|
+
describe 'return_stdout' do
|
30
|
+
describe command(name) do
|
31
|
+
before :all do
|
32
|
+
RSpec.configure do |c|
|
33
|
+
c.stdout = "foo#{content}bar\r\n"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
it { should return_stdout(content) }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe command(name) do
|
40
|
+
before :all do
|
41
|
+
RSpec.configure do |c|
|
42
|
+
c.stdout = "foobar\r\n"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
it { should_not return_stdout(content) }
|
46
|
+
end
|
47
|
+
|
48
|
+
describe command('invalid-command') do
|
49
|
+
it { should_not return_stdout(content) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
shared_examples_for 'support command return_stderr matcher' do |name, content|
|
55
|
+
describe 'return_stderr' do
|
56
|
+
describe command(name) do
|
57
|
+
before :all do
|
58
|
+
RSpec.configure do |c|
|
59
|
+
c.stdout = "#{content}\r\n"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
it { should return_stderr(content) }
|
63
|
+
end
|
64
|
+
|
65
|
+
describe command(name) do
|
66
|
+
before :all do
|
67
|
+
RSpec.configure do |c|
|
68
|
+
c.stdout = "No such file or directory\r\n"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
it { should_not return_stderr(content) }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
shared_examples_for 'support command return_stderr matcher with regexp' do |name, content|
|
77
|
+
describe 'return_stderr' do
|
78
|
+
describe command(name) do
|
79
|
+
before :all do
|
80
|
+
RSpec.configure do |c|
|
81
|
+
c.stdout = "cat: /foo: No such file or directory\r\n"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
it { should return_stdout(content) }
|
85
|
+
end
|
86
|
+
|
87
|
+
describe command(name) do
|
88
|
+
before :all do
|
89
|
+
RSpec.configure do |c|
|
90
|
+
c.stdout = "foobar\r\n"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
it { should_not return_stdout(content) }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
shared_examples_for 'support command return_exit_status matcher' do |name, status|
|
99
|
+
describe 'return_exit_status' do
|
100
|
+
describe command(name) do
|
101
|
+
it { should return_exit_status(status) }
|
102
|
+
end
|
103
|
+
|
104
|
+
describe command('invalid-command') do
|
105
|
+
it { should_not return_exit_status(status) }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
shared_examples_for 'support cron have_entry matcher' do |entry|
|
2
|
+
describe 'have_cron_entry' do
|
3
|
+
describe cron do
|
4
|
+
it { should have_cron_entry entry }
|
5
|
+
end
|
6
|
+
|
7
|
+
describe cron do
|
8
|
+
it { should_not have_cron_entry 'invalid entry' }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
shared_examples_for 'support cron have_entry with user matcher' do |entry, user|
|
14
|
+
describe 'have_cron_entry' do
|
15
|
+
describe cron do
|
16
|
+
it { should have_cron_entry(entry).with_user(user) }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe cron do
|
20
|
+
it { should_not have_cron_entry('invalid entry').with_user(user) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serverspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ssh
|
@@ -91,6 +91,38 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: guard-rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: growl
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
94
126
|
description: RSpec tests for your servers provisioned by Puppet, Chef or anything
|
95
127
|
else
|
96
128
|
email:
|
@@ -103,6 +135,7 @@ files:
|
|
103
135
|
- .gitignore
|
104
136
|
- .travis.yml
|
105
137
|
- Gemfile
|
138
|
+
- Guardfile
|
106
139
|
- LICENSE.txt
|
107
140
|
- README.md
|
108
141
|
- Rakefile
|
@@ -145,7 +178,6 @@ files:
|
|
145
178
|
- lib/serverspec/matchers/be_group.rb
|
146
179
|
- lib/serverspec/matchers/be_grouped_into.rb
|
147
180
|
- lib/serverspec/matchers/be_installed.rb
|
148
|
-
- lib/serverspec/matchers/be_installed_by_gem.rb
|
149
181
|
- lib/serverspec/matchers/be_linked_to.rb
|
150
182
|
- lib/serverspec/matchers/be_listening.rb
|
151
183
|
- lib/serverspec/matchers/be_mode.rb
|
@@ -181,44 +213,58 @@ files:
|
|
181
213
|
- lib/serverspec/setup.rb
|
182
214
|
- lib/serverspec/subject.rb
|
183
215
|
- lib/serverspec/type/base.rb
|
216
|
+
- lib/serverspec/type/command.rb
|
217
|
+
- lib/serverspec/type/cron.rb
|
184
218
|
- lib/serverspec/type/file.rb
|
185
219
|
- lib/serverspec/type/package.rb
|
186
220
|
- lib/serverspec/type/port.rb
|
187
221
|
- lib/serverspec/type/service.rb
|
188
222
|
- lib/serverspec/version.rb
|
189
223
|
- serverspec.gemspec
|
224
|
+
- spec/darwin/command_spec.rb
|
190
225
|
- spec/darwin/commands_spec.rb
|
226
|
+
- spec/darwin/cron_spec.rb
|
191
227
|
- spec/darwin/file_spec.rb
|
192
228
|
- spec/darwin/matchers_spec.rb
|
193
229
|
- spec/darwin/package_spec.rb
|
194
230
|
- spec/darwin/port_spec.rb
|
195
231
|
- spec/darwin/service_spec.rb
|
232
|
+
- spec/debian/command_spec.rb
|
196
233
|
- spec/debian/commands_spec.rb
|
234
|
+
- spec/debian/cron_spec.rb
|
197
235
|
- spec/debian/file_spec.rb
|
198
236
|
- spec/debian/matchers_spec.rb
|
199
237
|
- spec/debian/package_spec.rb
|
200
238
|
- spec/debian/port_spec.rb
|
201
239
|
- spec/debian/service_spec.rb
|
240
|
+
- spec/gentoo/command_spec.rb
|
202
241
|
- spec/gentoo/commands_spec.rb
|
242
|
+
- spec/gentoo/cron_spec.rb
|
203
243
|
- spec/gentoo/file_spec.rb
|
204
244
|
- spec/gentoo/matchers_spec.rb
|
205
245
|
- spec/gentoo/package_spec.rb
|
206
246
|
- spec/gentoo/port_spec.rb
|
207
247
|
- spec/gentoo/service_spec.rb
|
208
248
|
- spec/helpers/attributes_spec.rb
|
249
|
+
- spec/redhat/command_spec.rb
|
209
250
|
- spec/redhat/commands_spec.rb
|
251
|
+
- spec/redhat/cron_spec.rb
|
210
252
|
- spec/redhat/file_spec.rb
|
211
253
|
- spec/redhat/matchers_spec.rb
|
212
254
|
- spec/redhat/package_spec.rb
|
213
255
|
- spec/redhat/port_spec.rb
|
214
256
|
- spec/redhat/service_spec.rb
|
257
|
+
- spec/solaris/command_spec.rb
|
215
258
|
- spec/solaris/commands_spec.rb
|
259
|
+
- spec/solaris/cron_spec.rb
|
216
260
|
- spec/solaris/file_spec.rb
|
217
261
|
- spec/solaris/matchers_spec.rb
|
218
262
|
- spec/solaris/package_spec.rb
|
219
263
|
- spec/solaris/port_spec.rb
|
220
264
|
- spec/solaris/service_spec.rb
|
221
265
|
- spec/spec_helper.rb
|
266
|
+
- spec/support/shared_command_examples.rb
|
267
|
+
- spec/support/shared_cron_examples.rb
|
222
268
|
- spec/support/shared_file_examples.rb
|
223
269
|
- spec/support/shared_matcher_examples.rb
|
224
270
|
- spec/support/shared_package_examples.rb
|
@@ -250,38 +296,50 @@ signing_key:
|
|
250
296
|
specification_version: 3
|
251
297
|
summary: RSpec tests for your servers provisioned by Puppet, Chef or anything else
|
252
298
|
test_files:
|
299
|
+
- spec/darwin/command_spec.rb
|
253
300
|
- spec/darwin/commands_spec.rb
|
301
|
+
- spec/darwin/cron_spec.rb
|
254
302
|
- spec/darwin/file_spec.rb
|
255
303
|
- spec/darwin/matchers_spec.rb
|
256
304
|
- spec/darwin/package_spec.rb
|
257
305
|
- spec/darwin/port_spec.rb
|
258
306
|
- spec/darwin/service_spec.rb
|
307
|
+
- spec/debian/command_spec.rb
|
259
308
|
- spec/debian/commands_spec.rb
|
309
|
+
- spec/debian/cron_spec.rb
|
260
310
|
- spec/debian/file_spec.rb
|
261
311
|
- spec/debian/matchers_spec.rb
|
262
312
|
- spec/debian/package_spec.rb
|
263
313
|
- spec/debian/port_spec.rb
|
264
314
|
- spec/debian/service_spec.rb
|
315
|
+
- spec/gentoo/command_spec.rb
|
265
316
|
- spec/gentoo/commands_spec.rb
|
317
|
+
- spec/gentoo/cron_spec.rb
|
266
318
|
- spec/gentoo/file_spec.rb
|
267
319
|
- spec/gentoo/matchers_spec.rb
|
268
320
|
- spec/gentoo/package_spec.rb
|
269
321
|
- spec/gentoo/port_spec.rb
|
270
322
|
- spec/gentoo/service_spec.rb
|
271
323
|
- spec/helpers/attributes_spec.rb
|
324
|
+
- spec/redhat/command_spec.rb
|
272
325
|
- spec/redhat/commands_spec.rb
|
326
|
+
- spec/redhat/cron_spec.rb
|
273
327
|
- spec/redhat/file_spec.rb
|
274
328
|
- spec/redhat/matchers_spec.rb
|
275
329
|
- spec/redhat/package_spec.rb
|
276
330
|
- spec/redhat/port_spec.rb
|
277
331
|
- spec/redhat/service_spec.rb
|
332
|
+
- spec/solaris/command_spec.rb
|
278
333
|
- spec/solaris/commands_spec.rb
|
334
|
+
- spec/solaris/cron_spec.rb
|
279
335
|
- spec/solaris/file_spec.rb
|
280
336
|
- spec/solaris/matchers_spec.rb
|
281
337
|
- spec/solaris/package_spec.rb
|
282
338
|
- spec/solaris/port_spec.rb
|
283
339
|
- spec/solaris/service_spec.rb
|
284
340
|
- spec/spec_helper.rb
|
341
|
+
- spec/support/shared_command_examples.rb
|
342
|
+
- spec/support/shared_cron_examples.rb
|
285
343
|
- spec/support/shared_file_examples.rb
|
286
344
|
- spec/support/shared_matcher_examples.rb
|
287
345
|
- spec/support/shared_package_examples.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
RSpec::Matchers.define :be_installed_by_gem do
|
2
|
-
match do |name|
|
3
|
-
puts <<EOF
|
4
|
-
|
5
|
-
***************************************************
|
6
|
-
The matcher be_isntalled_by_gem will be depricated.
|
7
|
-
Please use be_installed.by('gem') instead.
|
8
|
-
***************************************************
|
9
|
-
|
10
|
-
EOF
|
11
|
-
backend.check_installed_by_gem(example, name, @version)
|
12
|
-
end
|
13
|
-
chain :with_version do |version|
|
14
|
-
@version = version
|
15
|
-
end
|
16
|
-
end
|