Merge branch 'master' into 3686-sharing-repositories
[arvados.git] / apps / workbench / test / test_helper.rb
index 58e540cbeb47d95814970436911e1db7e0bc857c..7c454c9877b2bbb4c97c417cf5406cf433924ca3 100644 (file)
@@ -1,4 +1,4 @@
-ENV["RAILS_ENV"] = "test" if (ENV["RAILS_ENV"] != "diagnostics")
+ENV["RAILS_ENV"] = "test" if (ENV["RAILS_ENV"] != "diagnostics" and ENV["RAILS_ENV"] != "performance")
 
 unless ENV["NO_COVERAGE_TEST"]
   begin
@@ -160,8 +160,10 @@ class ApiServerForTests
                 '--pid-file', @pidfile)
       else
         make_ssl_cert
-        _system('bundle', 'exec', 'rake', 'db:test:load')
-        _system('bundle', 'exec', 'rake', 'db:fixtures:load')
+        if ENV['ARVADOS_TEST_API_INSTALLED'].blank?
+          _system('bundle', 'exec', 'rake', 'db:test:load')
+          _system('bundle', 'exec', 'rake', 'db:fixtures:load')
+        end
         _system('bundle', 'exec', 'passenger', 'start', '-d', '-p3000',
                 '--pid-file', @pidfile,
                 '--ssl',
@@ -182,6 +184,12 @@ class ApiServerForTests
       end
     end
   end
+
+  def run_rake_task(task_name, arg_string)
+    Dir.chdir(ARV_API_SERVER_DIR) do
+      _system('bundle', 'exec', 'rake', "#{task_name}[#{arg_string}]")
+    end
+  end
 end
 
 class ActionController::TestCase
@@ -192,7 +200,7 @@ class ActionController::TestCase
   def check_counter action
     @counter += 1
     if @counter == 2
-      assert_equal 1, 2, "Multiple actions in functional test"
+      assert_equal 1, 2, "Multiple actions in controller test"
     end
   end
 
@@ -261,6 +269,10 @@ class ActiveSupport::TestCase
 
   protected
   def self.reset_api_fixtures_now
+    # Never try to reset fixtures when we're just using test
+    # infrastructure to run performance/diagnostics suites.
+    return unless Rails.env == 'test'
+
     auth = api_fixture('api_client_authorizations')['admin_trustedclient']
     Thread.current[:arvados_api_token] = auth['api_token']
     ArvadosApiClient.new.api(nil, '../../database/reset', {})
@@ -283,7 +295,24 @@ class RequestDuck
   end
 end
 
+# Example:
+#
+# apps/workbench$ RAILS_ENV=test bundle exec irb -Ilib:test
+# > load 'test/test_helper.rb'
+# > singletest 'integration/collection_upload_test.rb', 'Upload two empty files'
+#
+def singletest test_class_file, test_name
+  load File.join('test', test_class_file)
+  Minitest.run ['-v', '-n', "test_#{test_name.gsub ' ', '_'}"]
+  Object.send(:remove_const,
+              test_class_file.gsub(/.*\/|\.rb$/, '').camelize.to_sym)
+  ::Minitest::Runnable.runnables.reject! { true }
+end
+
 if ENV["RAILS_ENV"].eql? 'test'
   ApiServerForTests.new.run
   ApiServerForTests.new.run ["--websockets"]
 end
+
+# Reset fixtures now (i.e., before any tests run).
+ActiveSupport::TestCase.reset_api_fixtures_now