Merge pull request #31 from chef/exist-vs-exists

Exist vs exists
This commit is contained in:
Christoph Hartmann 2015-09-21 12:27:24 +02:00 committed by Dominik Richter
commit 69bdd619a3
22 changed files with 35 additions and 35 deletions

View file

@ -21,7 +21,7 @@ module Vulcano::Resources
@file.content, @file.content,
assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/, assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
multiple_values: true, multiple_values: true,
).params if @file.exists? ).params if @file.exist?
@loaded = true @loaded = true
@content @content
end end
@ -37,8 +37,8 @@ module Vulcano::Resources
@content @content
end end
def exists? def exist?
@file.exists? @file.exist?
end end
def has_interface?(interface) def has_interface?(interface)

View file

@ -24,7 +24,7 @@ class Cmd < Vulcano.resource(1)
result.exit_status.to_i result.exit_status.to_i
end end
def exists? def exist?
res = vulcano.run_command("type \"#{@command}\" > /dev/null") res = vulcano.run_command("type \"#{@command}\" > /dev/null")
res.exit_status.to_i == 0 res.exit_status.to_i == 0
end end

View file

@ -12,7 +12,7 @@ module Vulcano::Resources
end end
%w{ %w{
type exists? file? block_device? character_device? socket? directory? type exist? file? block_device? character_device? socket? directory?
symlink? pipe? mode mode? owner owned_by? group grouped_into? link_target symlink? pipe? mode mode? owner owned_by? group grouped_into? link_target
linked_to? content mtime size selinux_label mounted? immutable? linked_to? content mtime size selinux_label mounted? immutable?
product_version file_version version? md5sum sha256sum product_version file_version version? md5sum sha256sum

View file

@ -173,7 +173,7 @@ class SysV < ServiceManager
service = @vulcano.file(filename) service = @vulcano.file(filename)
# check if service is installed # check if service is installed
return nil if !service.exists? return nil if !service.exist?
# check if service is enabled # check if service is enabled
configfile = "/etc/init/#{service_name}.conf" configfile = "/etc/init/#{service_name}.conf"

View file

@ -117,7 +117,7 @@ class YumRepo
@cache @cache
end end
def exists? def exist?
!info.nil? !info.nil?
end end
@ -141,7 +141,7 @@ module Vulcano::Resources
def exists? def exists?
deprecated deprecated
@repository.exists? @repository.exist?
end end
def enabled? def enabled?

View file

@ -96,7 +96,7 @@ module Vulcano::Backends
end end
%w{ %w{
exists? file? socket? directory? symlink? pipe? exist? file? socket? directory? symlink? pipe?
}.each do |m| }.each do |m|
define_method m.to_sym do define_method m.to_sym do
::File.method(m.to_sym).call(@path) ::File.method(m.to_sym).call(@path)

View file

@ -63,11 +63,11 @@ module Vulcano::Backends
def initialize(_runtime, path) def initialize(_runtime, path)
@path = path @path = path
# mock dataset # mock dataset
@exists = (rand < 0.8) ? true : false @exist = (rand < 0.8) ? true : false
@is_file = (@exists && rand < 0.7) ? true : false @is_file = (@exist && rand < 0.7) ? true : false
@size = 0 @size = 0
@content = '' @content = ''
if @exists && @is_file if @exist && @is_file
@size = (rand**3 * 1000).to_i @size = (rand**3 * 1000).to_i
@size = 0 if rand < 0.2 @size = 0 if rand < 0.2
end end
@ -77,7 +77,7 @@ module Vulcano::Backends
@content @content
end end
%w{ size content file? exists? }.each do |m| %w{ size content file? exist? }.each do |m|
define_method m.to_sym do define_method m.to_sym do
instance_variable_get(m.sub('?', '').to_sym) instance_variable_get(m.sub('?', '').to_sym)
end end

View file

@ -218,7 +218,7 @@ module Vulcano::Backends
super(backend, path) super(backend, path)
end end
def exists? def exist?
Specinfra::Runner.check_file_exists(@path) Specinfra::Runner.check_file_exists(@path)
end end

View file

@ -5,7 +5,7 @@ class Vulcano::Plugins::Backend
# interface methods: these fields should be implemented by every # interface methods: these fields should be implemented by every
# backend File # backend File
%w{ %w{
exists? mode owner group link_target content mtime size exist? mode owner group link_target content mtime size
selinux_label product_version file_version path selinux_label product_version file_version path
}.each do |m| }.each do |m|
define_method m.to_sym do define_method m.to_sym do

View file

@ -17,8 +17,8 @@ class Vulcano::Plugins::Backend
"cat #{@spath} 2>/dev/null || echo -n").stdout "cat #{@spath} 2>/dev/null || echo -n").stdout
end end
def exists? def exist?
@exists ||= ( @exist ||= (
@backend. @backend.
run_command("test -e #{@spath}"). run_command("test -e #{@spath}").
exit_status == 0 exit_status == 0

View file

@ -17,14 +17,14 @@ describe command('exit 123') do
its(:exit_status) { should eq 123 } its(:exit_status) { should eq 123 }
end end
describe command('/bin/sh').exists? do describe command('/bin/sh').exist? do
it { should eq true } it { should eq true }
end end
describe command('sh').exists? do describe command('sh').exist? do
it { should eq true } it { should eq true }
end end
describe command('this is not existing').exists? do describe command('this is not existing').exist? do
it { should eq false } it { should eq false }
end end

View file

@ -1,5 +1,5 @@
return unless command('ssh').exists? return unless command('ssh').exist?
describe ssh_config do describe ssh_config do
its('SendEnv') { should include('GORDON_CLIENT')} its('SendEnv') { should include('GORDON_CLIENT')}

View file

@ -1,5 +1,5 @@
return unless command('sshd').exists? return unless command('sshd').exist?
describe sshd_config do describe sshd_config do
its('AcceptEnv') { should include('GORDON_SERVER')} its('AcceptEnv') { should include('GORDON_SERVER')}

View file

@ -7,7 +7,7 @@ describe 'file interface' do
let(:file) { backend.file('/tmp/block_device') } let(:file) { backend.file('/tmp/block_device') }
it 'exists' do it 'exists' do
file.exists?.must_equal(true) file.exist?.must_equal(true)
end end
it 'is a block device' do it 'is a block device' do

View file

@ -7,7 +7,7 @@ describe 'file interface' do
let(:file) { backend.file('/dev/null') } let(:file) { backend.file('/dev/null') }
it 'exists' do it 'exists' do
file.exists?.must_equal(true) file.exist?.must_equal(true)
end end
it 'is a character device' do it 'is a character device' do

View file

@ -7,7 +7,7 @@ describe 'file interface' do
let(:file) { backend.file('/tmp/file') } let(:file) { backend.file('/tmp/file') }
it 'exists' do it 'exists' do
file.exists?.must_equal(true) file.exist?.must_equal(true)
end end
it 'is a file' do it 'is a file' do

View file

@ -7,7 +7,7 @@ describe 'file interface' do
let(:file) { backend.file('/tmp/folder') } let(:file) { backend.file('/tmp/folder') }
it 'exists' do it 'exists' do
file.exists?.must_equal(true) file.exist?.must_equal(true)
end end
it 'is a directory' do it 'is a directory' do

View file

@ -9,7 +9,7 @@ describe 'file interface' do
} }
it 'does not exist' do it 'does not exist' do
file.exists?.must_equal(false) file.exist?.must_equal(false)
end end
it 'is not a file' do it 'is not a file' do

View file

@ -7,7 +7,7 @@ describe 'file interface' do
let(:file) { backend.file('/tmp/pipe') } let(:file) { backend.file('/tmp/pipe') }
it 'exists' do it 'exists' do
file.exists?.must_equal(true) file.exist?.must_equal(true)
end end
it 'is a pipe' do it 'is a pipe' do

View file

@ -7,7 +7,7 @@ describe 'file interface' do
let(:file) { backend.file('/tmp/symlink') } let(:file) { backend.file('/tmp/symlink') }
it 'exists' do it 'exists' do
file.exists?.must_equal(true) file.exist?.must_equal(true)
end end
it 'is a symlink' do it 'is a symlink' do

View file

@ -10,7 +10,7 @@ describe 'Vulcano::Resources::Bond' do
let(:resource) { loadResource('bond', 'bond0') } let(:resource) { loadResource('bond', 'bond0') }
it 'bond must be available' do it 'bond must be available' do
resource.exists?.must_equal true resource.exist?.must_equal true
end end
it 'eth0 is part of bond' do it 'eth0 is part of bond' do

View file

@ -50,31 +50,31 @@ describe 'Vulcano::Resources::YumRepo' do
# its('epel') { should exist } # its('epel') { should exist }
# its('epel') { should be_enabled } # its('epel') { should be_enabled }
it 'test its syntax repo' do it 'test its syntax repo' do
_(resource.extras.exists?).must_equal true _(resource.extras.exist?).must_equal true
_(resource.extras.enabled?).must_equal true _(resource.extras.enabled?).must_equal true
end end
it 'test enabled extra repo' do it 'test enabled extra repo' do
extras = resource.repo('extras/7/x86_64') extras = resource.repo('extras/7/x86_64')
_(extras.exists?).must_equal true _(extras.exist?).must_equal true
_(extras.enabled?).must_equal true _(extras.enabled?).must_equal true
end end
it 'test enabled extra repo with short name' do it 'test enabled extra repo with short name' do
extras = resource.repo('extras') extras = resource.repo('extras')
_(extras.exists?).must_equal true _(extras.exist?).must_equal true
_(extras.enabled?).must_equal true _(extras.enabled?).must_equal true
end end
it 'test disabled extra-source repo' do it 'test disabled extra-source repo' do
extras = resource.repo('base-debuginfo/x86_64') extras = resource.repo('base-debuginfo/x86_64')
_(extras.exists?).must_equal true _(extras.exist?).must_equal true
_(extras.enabled?).must_equal false _(extras.enabled?).must_equal false
end end
# test serverspec syntax # test serverspec syntax
let(:serverspec) { loadResource('yumrepo', 'extras') } let(:serverspec) { loadResource('yumrepo', 'extras') }
it 'test enabled extra repo' do it 'test enabled extra repo (serverspec backwards comptability)' do
_(serverspec.exists?).must_equal true _(serverspec.exists?).must_equal true
_(serverspec.enabled?).must_equal true _(serverspec.enabled?).must_equal true
end end