diff --git a/lib/vulcano/plugins/backend.rb b/lib/vulcano/plugins/backend.rb index c48ee5fb2..56c38863b 100644 --- a/lib/vulcano/plugins/backend.rb +++ b/lib/vulcano/plugins/backend.rb @@ -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) diff --git a/test/unit/plugins_v1_backend_test.rb b/test/unit/plugins_v1_backend_test.rb index 01baf1f54..2bf8ccd65 100644 --- a/test/unit/plugins_v1_backend_test.rb +++ b/test/unit/plugins_v1_backend_test.rb @@ -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