add call tracing to mock backend

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-09-04 22:54:52 +02:00
parent a1ed7788a4
commit 0125bcace8
3 changed files with 32 additions and 3 deletions

View file

@ -11,6 +11,7 @@ module Vulcano::Backends
@conf = conf
@files = {}
@commands = {}
trace_calls unless @conf[:quiet]
end
def file(path)
@ -28,10 +29,32 @@ module Vulcano::Backends
def to_s
'Mock Backend Runner'
end
private
def trace_calls
interface_methods = {
'Vulcano::Backends::Mock' => Vulcano::Backends::Mock.instance_methods(false),
'Vulcano::Backends::Mock::File' => FileCommon.instance_methods(false),
}
set_trace_func proc{|event, file, line, id, binding, classname|
next unless
classname.to_s.start_with?('Vulcano::Backends::Mock') and
event == 'call' and
interface_methods[classname.to_s].include?(id)
# kindly borrowed from the wonderful simple-tracer by matugm
arg_names = eval("method(__method__).parameters.map { |arg| arg[1].to_s }",binding)
args = eval("#{arg_names}.map { |arg| eval(arg) }",binding).join(', ')
prefix = '-' * (classname.to_s.count(':') - 2) + '> '
puts "#{prefix}#{id} #{args}"
}
end
end
class Mock
class File
class File < FileCommon
def initialize(runtime, path)
@path = path
# mock dataset

View file

@ -26,7 +26,11 @@ module Vulcano::Plugins
%w{
exists? mode owner group link_target content mtime size
selinux_label product_version file_version
}
}.each do |m|
define_method m.to_sym do
fail NotImplementedError.new("File must implement the #{m}() method.")
end
end
def type
:unknown

View file

@ -18,7 +18,9 @@ def loadResource (resource, *args)
scriptpath = ::File.realpath(::File.dirname(__FILE__))
# create mock backend
conf = Vulcano::Backend.target_config({})
conf = Vulcano::Backend.target_config({
quiet: true
})
backend_class = Vulcano::Backend.registry['mock']
@backend = backend_class.new(conf)