add rules to profile information

This commit is contained in:
Dominik Richter 2015-10-23 00:45:09 +02:00
parent a62ce0e14b
commit 93b4db01ca
4 changed files with 33 additions and 72 deletions

View file

@ -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

View file

@ -28,6 +28,21 @@ module Vulcano
@metadata = read_metadata @metadata = read_metadata
@params = @metadata.params unless @metadata.nil? @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 end
private private

View file

@ -70,7 +70,7 @@ module Vulcano
end end
def desc(v = nil) def desc(v = nil)
@desc = v unless v.nil? @desc = unindent(v) unless v.nil?
@desc @desc
end end
@ -136,5 +136,19 @@ module Vulcano
return "#{pid}/#{rid}" return "#{pid}/#{rid}"
end end
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
end end

View file

@ -15,9 +15,9 @@ require 'vulcano/rspec_json_formatter'
module Vulcano module Vulcano
class Runner class Runner
attr_reader :tests, :backend attr_reader :tests, :backend, :rules
def initialize(conf = {}) def initialize(conf = {})
@rules = [] @rules = {}
@profile_id = conf[:id] @profile_id = conf[:id]
@conf = conf.dup @conf = conf.dup
@tests = RSpec::Core::World.new @tests = RSpec::Core::World.new
@ -102,6 +102,7 @@ module Vulcano
end end
def register_rule(ctx, rule_id, rule) def register_rule(ctx, rule_id, rule)
@rules[rule_id] = rule
checks = rule.instance_variable_get(:@checks) checks = rule.instance_variable_get(:@checks)
checks.each do |m, a, b| checks.each do |m, a, b|
# resource skipping # resource skipping