diff --git a/lib/verify/dummy.rb b/lib/verify/dummy.rb deleted file mode 100644 index 29f8ebf37..000000000 --- a/lib/verify/dummy.rb +++ /dev/null @@ -1,69 +0,0 @@ -# encoding: utf-8 -# Copyright 2014 Dominik Richter. All rights reserved. -# author: Dominik Richter -# author: Christoph Hartmann - -# Spec file for Vulcano specs - -# Get types -module DummyTestTypes - # a few commands with special handling - def describe(*_args); end - - def context(*_args); end - - def os - {} - end - - def command(_sth) - res = OpenStruct.new - res.stdout = '' - res.stderr = '' - res - end -end - -module DummyVulcanoTypes - %w{ - attributes registry_key - }.each do |name| - define_method name do |*_arg| - end - end - - def processes(*_args) - [] - end - - def start_postgres_session(*_args) - Describer.new - end - - def start_mysql_session(*_args) - Describer.new - end - - class Describer - def describe(*_args); end - end -end - -class SshConf - def initialize(*_args); end -end -class PostgresConf - def initialize(*_args); end - - def params(*_a, &_b) - {} - end -end - -class MysqlConf - def initialize(*_args); end - - def params(*_a, &_b) - {} - end -end diff --git a/lib/vulcano/profile.rb b/lib/vulcano/profile.rb index af665e6ed..98bae13b2 100644 --- a/lib/vulcano/profile.rb +++ b/lib/vulcano/profile.rb @@ -28,6 +28,21 @@ module Vulcano @metadata = read_metadata @params = @metadata.params unless @metadata.nil? + + @params['rules'] = rules = {} + @runner = Runner.new( + id: @profile_id, + backend: :mock, + ) + @runner.add_tests([@path]) + @runner.rules.each do |id, rule| + rules[id] = { + title: rule.title, + desc: rule.desc, + impact: rule.impact, + code: rule.instance_variable_get(:@__code), + } + end end private diff --git a/lib/vulcano/rule.rb b/lib/vulcano/rule.rb index 2b7064b0c..d23d5de29 100644 --- a/lib/vulcano/rule.rb +++ b/lib/vulcano/rule.rb @@ -70,7 +70,7 @@ module Vulcano end def desc(v = nil) - @desc = v unless v.nil? + @desc = unindent(v) unless v.nil? @desc end @@ -136,5 +136,19 @@ module Vulcano return "#{pid}/#{rid}" end end + + private + + # Idio(ma)tic unindent + # TODO replace this + # + # @param [String] text string which needs to be unindented + # @return [String] input with indentation removed + def unindent(text) + return '' if text.nil? + text.strip.split("\n").map(&:strip) + .map { |x| x.empty? ? "\n" : x } + .join(' ') + end end end diff --git a/lib/vulcano/runner.rb b/lib/vulcano/runner.rb index afd9cc3c2..e40202315 100644 --- a/lib/vulcano/runner.rb +++ b/lib/vulcano/runner.rb @@ -15,9 +15,9 @@ require 'vulcano/rspec_json_formatter' module Vulcano class Runner - attr_reader :tests, :backend + attr_reader :tests, :backend, :rules def initialize(conf = {}) - @rules = [] + @rules = {} @profile_id = conf[:id] @conf = conf.dup @tests = RSpec::Core::World.new @@ -102,6 +102,7 @@ module Vulcano end def register_rule(ctx, rule_id, rule) + @rules[rule_id] = rule checks = rule.instance_variable_get(:@checks) checks.each do |m, a, b| # resource skipping