6859: mocking Kernel system method had the undersirable side effect of impacting...
authorradhika <radhika@curoverse.com>
Tue, 18 Aug 2015 04:29:24 +0000 (00:29 -0400)
committerradhika <radhika@curoverse.com>
Tue, 18 Aug 2015 04:29:24 +0000 (00:29 -0400)
services/api/lib/salvage_collection.rb
services/api/test/unit/salvage_collection_test.rb

index 80b96b87c76ac20a777a5d3f7efbfe8a0aa16eec..8854cb77611fdf69e12416a10f31c3230ff57515 100755 (executable)
@@ -15,6 +15,10 @@ module SalvageCollection
   require 'tempfile'
   require 'shellwords'
 
+  def self.salvage_collection_arv_put temp_file
+    %x(arv-put --as-stream --use-filename invalid_manifest_text.txt #{Shellwords::shellescape(temp_file.path)})
+  end
+
   def self.salvage_collection uuid, reason='salvaged - see #6277, #6859'
     act_as_system_user do
       if !ENV['ARVADOS_API_TOKEN'].present? or !ENV['ARVADOS_API_HOST'].present?
@@ -53,7 +57,8 @@ module SalvageCollection
         temp_file = Tempfile.new('temp')
         temp_file.write(src_manifest)
         temp_file.close
-        new_manifest = %x(arv-put --as-stream --use-filename invalid_manifest_text.txt #{Shellwords::shellescape(temp_file.path)})
+
+        new_manifest = salvage_collection_arv_put temp_file
 
         temp_file.unlink
 
index 3efe0370b14e3788ecfd831d08060bdf329e910b..83f3c5bd7050722dc79cf0818da2935b5a2319be 100644 (file)
@@ -4,26 +4,26 @@ require 'salvage_collection'
 TEST_MANIFEST = ". 341dabea2bd78ad0d6fc3f5b926b450e+85626+Ad391622a17f61e4a254eda85d1ca751c4f368da9@55e076ce 0:85626:brca2-hg19.fa\n. d7321a918923627c972d8f8080c07d29+82570+A22e0a1d9b9bc85c848379d98bedc64238b0b1532@55e076ce 0:82570:brca1-hg19.fa\n"
 
 module Kernel
-  def `(cmd)    # override kernel ` method
-    if cmd.include? 'arv-put'
-      file_contents = file = File.new(cmd.split[-1], "r").gets
-
-      # simulate arv-put error when it is 'user_agreement'
-      if file_contents.include? 'GNU_General_Public_License'
-        return ''
-      else
-        ". " +
-        Digest::MD5.hexdigest(TEST_MANIFEST) +
-        " 0:" + TEST_MANIFEST.length.to_s + ":invalid_manifest_text.txt\n"
-      end
-    end
-  end
-
   def exit code
     raise "Exit code #{code}" if code == 200
   end
 end
 
+module SalvageCollection
+  def self.salvage_collection_arv_put(temp_file)
+    file_contents = file = File.new(temp_file.path, "r").gets
+
+    # simulate arv-put error when it is 'user_agreement'
+    if file_contents.include? 'GNU_General_Public_License'
+      return ''
+    else
+      ". " +
+      Digest::MD5.hexdigest(TEST_MANIFEST) +
+      " 0:" + TEST_MANIFEST.length.to_s + ":invalid_manifest_text.txt\n"
+    end
+  end
+end
+
 class SalvageCollectionTest < ActiveSupport::TestCase
   include SalvageCollection
 
@@ -92,7 +92,7 @@ class SalvageCollectionTest < ActiveSupport::TestCase
     assert_equal true, exited
   end
 
-  test "salvage collection with during arv-put" do
+  test "salvage collection with error during arv-put" do
     # try to salvage collection while mimicking error during arv-put
     status = SalvageCollection.salvage_collection collections('user_agreement').uuid
     assert_equal false, status