Skip to content

Commit

Permalink
Merge pull request #156 from kitak/add-socket
Browse files Browse the repository at this point in the history
add socket type, matcher
  • Loading branch information
mizzy committed Jun 19, 2013
2 parents 89a6bd7 + 32d0396 commit a5ba496
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/serverspec/commands/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def check_file file
"test -f #{escape(file)}"
end

def check_socket file
"test -S #{escape(file)}"
end

def check_directory directory
"test -d #{escape(directory)}"
end
Expand Down
4 changes: 4 additions & 0 deletions lib/serverspec/type/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def file?
backend.check_file(@name)
end

def socket?
backend.check_socket(@name)
end

def directory?
backend.check_directory(@name)
end
Expand Down
1 change: 1 addition & 0 deletions spec/darwin/commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe 'Serverspec commands of Darwin family' do
it_behaves_like 'support command check_file', '/etc/passwd'
it_behaves_like 'support command check_directory', '/var/log'
it_behaves_like 'support command check_socket', '/var/run/unicorn.sock'

it_behaves_like 'support command check_installed_by_gem', 'jekyll'
it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
Expand Down
1 change: 1 addition & 0 deletions spec/darwin/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe 'Serverspec file matchers of Darwin family' do
it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
it_behaves_like 'support file be_directory matcher', '/etc/ssh'
it_behaves_like 'support file be_socket matcher', '/var/run/unicorn.sock'
it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
it_behaves_like 'support file contain from to matcher', 'Gemfile', 'rspec', /^group :test do/, /^end/
it_behaves_like 'support file contain after matcher', 'Gemfile', 'rspec', /^group :test do/
Expand Down
1 change: 1 addition & 0 deletions spec/debian/commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe 'Serverspec commands of Debian family' do
it_behaves_like 'support command check_file', '/etc/passwd'
it_behaves_like 'support command check_directory', '/var/log'
it_behaves_like 'support command check_socket', '/var/run/unicorn.sock'

it_behaves_like 'support command check_installed_by_gem', 'jekyll'
it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
Expand Down
1 change: 1 addition & 0 deletions spec/debian/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe 'Serverspec file matchers of Debian family' do
it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
it_behaves_like 'support file be_directory matcher', '/etc/ssh'
it_behaves_like 'support file be_socket matcher', '/var/run/unicorn.sock'
it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
it_behaves_like 'support file contain from to matcher', 'Gemfile', 'rspec', /^group :test do/, /^end/
it_behaves_like 'support file contain after matcher', 'Gemfile', 'rspec', /^group :test do/
Expand Down
1 change: 1 addition & 0 deletions spec/gentoo/commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe 'Serverspec commands of Gentoo family' do
it_behaves_like 'support command check_file', '/etc/passwd'
it_behaves_like 'support command check_directory', '/var/log'
it_behaves_like 'support command check_socket', '/var/run/unicorn.sock'

it_behaves_like 'support command check_installed_by_gem', 'jekyll'
it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
Expand Down
1 change: 1 addition & 0 deletions spec/gentoo/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe 'Serverspec file matchers of Gentoo family' do
it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
it_behaves_like 'support file be_directory matcher', '/etc/ssh'
it_behaves_like 'support file be_socket matcher', '/var/run/unicorn.sock'
it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
it_behaves_like 'support file contain from to matcher', 'Gemfile', 'rspec', /^group :test do/, /^end/
it_behaves_like 'support file contain after matcher', 'Gemfile', 'rspec', /^group :test do/
Expand Down
1 change: 1 addition & 0 deletions spec/redhat/commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe 'Serverspec commands of Red Hat' do
it_behaves_like 'support command check_file', '/etc/passwd'
it_behaves_like 'support command check_directory', '/var/log'
it_behaves_like 'support command check_socket', '/var/run/unicorn.sock'

it_behaves_like 'support command check_installed_by_gem', 'jekyll'
it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
Expand Down
1 change: 1 addition & 0 deletions spec/redhat/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe 'Serverspec file matchers of Red Hat family' do
it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
it_behaves_like 'support file be_directory matcher', '/etc/ssh'
it_behaves_like 'support file be_socket matcher', '/var/run/unicorn.sock'
it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
it_behaves_like 'support file contain from to matcher', 'Gemfile', 'rspec', /^group :test do/, /^end/
it_behaves_like 'support file contain after matcher', 'Gemfile', 'rspec', /^group :test do/
Expand Down
1 change: 1 addition & 0 deletions spec/solaris/commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe 'Serverspec commands of Solaris family' do
it_behaves_like 'support command check_file', '/etc/passwd'
it_behaves_like 'support command check_directory', '/var/log'
it_behaves_like 'support command check_socket', '/var/run/unicorn.sock'

it_behaves_like 'support command check_installed_by_gem', 'jekyll'
it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
Expand Down
1 change: 1 addition & 0 deletions spec/solaris/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe 'Serverspec file matchers of Solaris family' do
it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
it_behaves_like 'support file be_directory matcher', '/etc/ssh'
it_behaves_like 'support file be_socket matcher', '/var/run/unicorn.sock'
it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
it_behaves_like 'support file contain from to matcher', 'Gemfile', 'rspec', /^group :test do/, /^end/
it_behaves_like 'support file contain after matcher', 'Gemfile', 'rspec', /^group :test do/
Expand Down
5 changes: 5 additions & 0 deletions spec/support/shared_commands_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
it { should eq "test -d #{dir}" }
end

shared_examples_for 'support command check_socket' do |socket|
subject { commands.check_socket(socket) }
it { should eq "test -S #{socket}" }
end

shared_examples_for 'support command check_mounted' do |path|
subject { commands.check_mounted('/') }
it { should eq "mount | grep -w -- on\\ #{path}" }
Expand Down
12 changes: 12 additions & 0 deletions spec/support/shared_file_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
end
end

shared_examples_for 'support file be_socket matcher' do |name|
describe 'be_socket' do
describe file(name) do
it { should be_socket }
end

describe file('/etc/invalid_socket') do
it { should_not be_socket }
end
end
end

shared_examples_for 'support file contain matcher' do |name, pattern|
describe 'contain' do
describe file(name) do
Expand Down

0 comments on commit a5ba496

Please sign in to comment.