4233: simple but reasonably effective tests
[arvados.git] / apps / workbench / test / test_helper.rb
index c0d6ac86e72d907c6c05042b9663dded72419d37..7f07f180db85340f07c7071c2bbe36433f44d4c1 100644 (file)
@@ -129,7 +129,7 @@ class ApiServerForTests
   def find_server_pid
     pid = nil
     begin
-      pid = IO.read(if @websocket then WEBSOCKET_PID_PATH else SERVER_PID_PATH end).to_i
+      pid = IO.read(@pidfile).to_i
       $stderr.puts "API server is running, pid #{pid.inspect}"
     rescue Errno::ENOENT
     end
@@ -143,6 +143,12 @@ class ApiServerForTests
 
     @websocket = args.include?("--websockets")
 
+    @pidfile = if @websocket
+                 WEBSOCKET_PID_PATH
+               else
+                 SERVER_PID_PATH
+               end
+
     # Kill server left over from previous test run
     self.kill_server
 
@@ -151,13 +157,13 @@ class ApiServerForTests
       ENV["NO_COVERAGE_TEST"] = "1"
       if @websocket
         _system('bundle', 'exec', 'passenger', 'start', '-d', '-p3333',
-                '--pid-file', WEBSOCKET_PID_PATH)
+                '--pid-file', @pidfile)
       else
         make_ssl_cert
         _system('bundle', 'exec', 'rake', 'db:test:load')
         _system('bundle', 'exec', 'rake', 'db:fixtures:load')
         _system('bundle', 'exec', 'passenger', 'start', '-d', '-p3000',
-                '--pid-file', SERVER_PID_PATH,
+                '--pid-file', @pidfile,
                 '--ssl',
                 '--ssl-certificate', 'self-signed.pem',
                 '--ssl-certificate-key', 'self-signed.key')
@@ -176,6 +182,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
@@ -198,6 +210,21 @@ class ActionController::TestCase
   end
 end
 
+# If it quacks like a duck, it must be a HTTP request object.
+class RequestDuck
+  def self.host
+    "localhost"
+  end
+
+  def self.port
+    8080
+  end
+
+  def self.protocol
+    "http"
+  end
+end
+
 if ENV["RAILS_ENV"].eql? 'test'
   ApiServerForTests.new.run
   ApiServerForTests.new.run ["--websockets"]