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?
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
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
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