Method: Controlrepo::Test.deduplicate

Defined in:
lib/controlrepo/test.rb

.deduplicate(tests) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/controlrepo/test.rb', line 112

def self.deduplicate(tests)
  # This should take an array of tests and remove any duplicates from them

  # this will be an array of arrays, or maybe hashes
  combinations = []
  new_tests = []
  tests.each do |test|
    test.nodes.each do |node|
      test.classes.each do |cls|
        combo = {node => cls}
        if combinations.member?(combo)

          # Find the right test object:
          relevant_test = new_tests[new_tests.index do |a|
            a.nodes[0] == node and a.classes[0] == cls
          end]

          # Delete all default values in the current options hash
          test.options.delete_if do |key,value|
            test.default_options[key] == value
          end

          # Merge the non-default options right on in there
          relevant_test.options.merge!(test.options)
        else
          combinations << combo
          new_tests << Controlrepo::Test.new(node,cls,test.options)
        end
      end
    end
  end

  # The array that this returns should be ephemeral, it does not
  # represent anything defined in a controlrepo and should just
  # be passed into the thing doing the testing and then killed,
  # we don't want too many copies of the same shit going around
  #
  # Actually based on the way things are written I don't think this
  # will duplicated node or class objects, just test objects,
  # everything else is passed by reference
  new_tests
end