16826: Adds catch-all check for any config potentially changed during tests.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Mon, 14 Sep 2020 18:42:15 +0000 (15:42 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Mon, 14 Sep 2020 18:42:15 +0000 (15:42 -0300)
On test suite teardown, check if all config keys are still Symbols, so that
no mistake is made by writing tests that rely on config hashes with string
keys.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

services/api/lib/config_loader.rb
services/api/test/test_helper.rb

index cf16993ca51054e220713c24cca1a33510e2a423..f421fb5b2a07817905c28bbd1a463da9be936ac5 100644 (file)
@@ -147,14 +147,14 @@ class ConfigLoader
             'Ki' => 1 << 10,
             'M' => 1000000,
             'Mi' => 1 << 20,
-           "G" =>  1000000000,
-           "Gi" => 1 << 30,
-           "T" =>  1000000000000,
-           "Ti" => 1 << 40,
-           "P" =>  1000000000000000,
-           "Pi" => 1 << 50,
-           "E" =>  1000000000000000000,
-           "Ei" => 1 << 60,
+            "G" =>  1000000000,
+            "Gi" => 1 << 30,
+            "T" =>  1000000000000,
+            "Ti" => 1 << 40,
+            "P" =>  1000000000000000,
+            "Pi" => 1 << 50,
+            "E" =>  1000000000000000000,
+            "Ei" => 1 << 60,
           }[mt[2]]
         end
       end
index c99a57aaff49b24910df17c4a745088a4903ce22..ad5fb8e2a5ac7c3def432cc64402f8efc38ae4da 100644 (file)
@@ -99,7 +99,21 @@ class ActiveSupport::TestCase
     end
   end
 
+  def confirm_keys_as_symbols(a_hash, section_name)
+    a_hash.keys.each do |k|
+      assert(k.is_a?(Symbol), "Key '#{k}' on section '#{section_name}' should be a Symbol")
+      confirm_keys_as_symbols(a_hash[k], "#{section_name}.#{k}") if a_hash[k].is_a?(Hash)
+    end
+  end
+
   def restore_configuration
+    # Confirm that any changed configuration doesn't include non-symbol keys
+    $arvados_config.keys.each do |config_section_name|
+      config_section = Rails.configuration.send("#{config_section_name}")
+      if config_section.is_a?(Hash)
+        confirm_keys_as_symbols(config_section, config_section_name)
+      end
+    end
     # Restore configuration settings changed during tests
     ConfigLoader.copy_into_config $arvados_config, Rails.configuration
     ConfigLoader.copy_into_config $remaining_config, Rails.configuration