mirror of
https://github.com/inspec/inspec
synced 2024-11-26 06:30:26 +00:00
specify methods all backends must implement
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
05b4167971
commit
1c2ab098f5
2 changed files with 50 additions and 14 deletions
|
@ -10,7 +10,18 @@ module Vulcano::Plugins
|
|||
end
|
||||
|
||||
def self.__register(name, obj)
|
||||
Vulcano::Backend.registry[name] = obj
|
||||
cl = Class.new(obj) do
|
||||
include BackendCommon
|
||||
end
|
||||
Vulcano::Backend.registry[name] = cl
|
||||
end
|
||||
|
||||
module BackendCommon
|
||||
%w{ file run_command os }.each do |name|
|
||||
define_method name do |*args|
|
||||
raise NotImplementedError.new("Backend must implement the #{name}() method.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class FileCommon
|
||||
|
@ -47,27 +58,27 @@ module Vulcano::Plugins
|
|||
end
|
||||
|
||||
def block_device?
|
||||
@file.type == :block_device
|
||||
type == :block_device
|
||||
end
|
||||
|
||||
def character_device?
|
||||
@file.type == :character_device
|
||||
type == :character_device
|
||||
end
|
||||
|
||||
def socket?
|
||||
@file.type == :socket
|
||||
type == :socket
|
||||
end
|
||||
|
||||
def directory?
|
||||
@file.type == :directory
|
||||
type == :directory
|
||||
end
|
||||
|
||||
def symlink?
|
||||
@file.type == :symlink
|
||||
type == :symlink
|
||||
end
|
||||
|
||||
def pipe?
|
||||
@file.type == :pipe?
|
||||
type == :pipe?
|
||||
end
|
||||
|
||||
def mode?(mode)
|
||||
|
|
|
@ -8,12 +8,37 @@ describe 'Vulcano::Plugins::Backend' do
|
|||
|
||||
it 'provides a name method for registering' do
|
||||
@child.must_respond_to :name
|
||||
@child.name 'test'
|
||||
# check if it's there
|
||||
reg = Vulcano::Backend.registry
|
||||
reg.keys.must_include 'test'
|
||||
reg['test'].must_equal @child
|
||||
# cleanup
|
||||
reg.delete('test')
|
||||
end
|
||||
|
||||
describe 'when registering a plugin' do
|
||||
before do
|
||||
@child.name 'test'
|
||||
@reg = Vulcano::Backend.registry
|
||||
end
|
||||
|
||||
after do
|
||||
@reg.delete('test')
|
||||
end
|
||||
|
||||
it 'must have the backend registered' do
|
||||
@reg.keys.must_include 'test'
|
||||
@reg['test'].ancestors[2].must_equal @child
|
||||
end
|
||||
|
||||
it 'must raise an error if file is not implemented' do
|
||||
t = @reg['test'].new
|
||||
proc { t.run_command }.must_raise NotImplementedError
|
||||
end
|
||||
|
||||
it 'must raise an error if run_command is not implemented' do
|
||||
t = @reg['test'].new
|
||||
proc { t.file }.must_raise NotImplementedError
|
||||
end
|
||||
|
||||
it 'must raise an error if os is not implemented' do
|
||||
t = @reg['test'].new
|
||||
proc { t.os }.must_raise NotImplementedError
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue