mirror of
https://github.com/inspec/inspec
synced 2024-11-14 00:47:10 +00:00
improvement: unify ID generation for all tests
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
7f67a088cb
commit
cecd86a119
3 changed files with 27 additions and 17 deletions
|
@ -39,17 +39,19 @@ module Vulcano
|
||||||
src = __get_block_source(&r.instance_variable_get(:@__block))
|
src = __get_block_source(&r.instance_variable_get(:@__block))
|
||||||
end
|
end
|
||||||
r.instance_variable_set(:@__code, src)
|
r.instance_variable_set(:@__code, src)
|
||||||
fid = VulcanoBaseRule.full_id r, @profile_id
|
|
||||||
if @rules[fid].nil?
|
full_id = VulcanoBaseRule.full_id @profile_id, r
|
||||||
@rules[fid] = r
|
if @rules[full_id].nil?
|
||||||
|
@rules[full_id] = r
|
||||||
else
|
else
|
||||||
@errors.push "Duplicate definition of rule #{fid}."
|
@errors.push "Duplicate definition of rule #{fid}."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def __unregister_rule id
|
def __unregister_rule id
|
||||||
fid = "#{@profile_id}/#{id}"
|
full_id = VulcanoBaseRule.full_id @profile_id, id
|
||||||
if @rules.key? fid
|
if @rules.key?(full_id)
|
||||||
@rules.delete(fid)
|
@rules.delete(full_id)
|
||||||
else
|
else
|
||||||
@errors.push "Failed to skip rule #{fid}, it isn't defined."
|
@errors.push "Failed to skip rule #{fid}, it isn't defined."
|
||||||
end
|
end
|
||||||
|
|
|
@ -65,20 +65,28 @@ class VulcanoBaseRule
|
||||||
# for the rule. If the rule's profile id is empty,
|
# for the rule. If the rule's profile id is empty,
|
||||||
# the given profile_id will be used instead and also
|
# the given profile_id will be used instead and also
|
||||||
# set for the rule.
|
# set for the rule.
|
||||||
def self.full_id rule, profile_id
|
def self.full_id profile_id, rule
|
||||||
# As the profile context is exclusively pulled with a
|
if rule.is_a?(String) or rule.nil?
|
||||||
# profile ID, attach it to the rule if necessary.
|
rid = rule
|
||||||
rid = rule.instance_variable_get(:@id)
|
else
|
||||||
if rid.nil?
|
# As the profile context is exclusively pulled with a
|
||||||
# TODO: Message about skipping this rule
|
# profile ID, attach it to the rule if necessary.
|
||||||
# due to missing ID
|
rid = rule.instance_variable_get(:@id)
|
||||||
return nil
|
if rid.nil?
|
||||||
|
# TODO: Message about skipping this rule
|
||||||
|
# due to missing ID
|
||||||
|
return nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
pid = rule.instance_variable_get(:@profile_id)
|
pid = rule.instance_variable_get(:@profile_id)
|
||||||
if pid.nil?
|
if pid.nil?
|
||||||
rule.instance_variable_set(:@profile_id, profile_id)
|
rule.instance_variable_set(:@profile_id, profile_id)
|
||||||
pid = profile_id
|
pid = profile_id
|
||||||
end
|
end
|
||||||
return (pid || '') + "/" + rid
|
if pid.nil? or pid.empty?
|
||||||
|
return rid
|
||||||
|
else
|
||||||
|
return "#{pid}/#{rid}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -191,13 +191,13 @@ module Vulcano
|
||||||
end
|
end
|
||||||
|
|
||||||
def __unregister_rule id
|
def __unregister_rule id
|
||||||
full_id = "#{@profile_id}/#{id}"
|
full_id = VulcanoBaseRule::full_id(@profile_id, id)
|
||||||
@rules[full_id] = nil
|
@rules[full_id] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def __register_rule r
|
def __register_rule r
|
||||||
# get the full ID
|
# get the full ID
|
||||||
full_id = VulcanoBaseRule::full_id(r, @profile_id)
|
full_id = VulcanoBaseRule::full_id(@profile_id, r)
|
||||||
if full_id.nil?
|
if full_id.nil?
|
||||||
# TODO error
|
# TODO error
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue