2 require 'salvage_collection'
4 TEST_MANIFEST = ". 341dabea2bd78ad0d6fc3f5b926b450e+85626+Ad391622a17f61e4a254eda85d1ca751c4f368da9@55e076ce 0:85626:brca2-hg19.fa\n. d7321a918923627c972d8f8080c07d29+82570+A22e0a1d9b9bc85c848379d98bedc64238b0b1532@55e076ce 0:82570:brca1-hg19.fa\n"
8 raise "Exit code #{code}" if code == 200
12 module SalvageCollection
13 def self.salvage_collection_arv_put(temp_file)
14 file_contents = file = File.new(temp_file.path, "r").gets
16 # simulate arv-put error when it is 'user_agreement'
17 if file_contents.include? 'GNU_General_Public_License'
21 Digest::MD5.hexdigest(TEST_MANIFEST) +
22 " 0:" + TEST_MANIFEST.length.to_s + ":invalid_manifest_text.txt\n"
27 class SalvageCollectionTest < ActiveSupport::TestCase
28 include SalvageCollection
31 set_user_from_auth :admin
32 # arv-put needs ARV env variables
33 ENV['ARVADOS_API_HOST'] = 'unused_by_test'
34 ENV['ARVADOS_API_TOKEN'] = 'unused_by_test'
38 ENV['ARVADOS_API_HOST'] = ''
39 ENV['ARVADOS_API_TOKEN'] = ''
42 test "salvage test collection" do
43 # create a collection to test salvaging
44 src_collection = Collection.new name: "test collection", manifest_text: TEST_MANIFEST
47 # salvage this collection
48 SalvageCollection.salvage_collection src_collection.uuid, 'test salvage collection - see #6277, #6859'
50 # verify the updated src_collection data
51 updated_src_collection = Collection.find_by_uuid src_collection.uuid
52 updated_name = updated_src_collection.name
53 assert_equal true, updated_name.include?(src_collection.name)
55 match = updated_name.match /^test collection.*salvaged data at (.*)\)$/
57 assert_not_nil match[1]
58 assert_empty updated_src_collection.manifest_text
60 # match[1] is the uuid of the new collection created from src_collection's salvaged data
61 # use this to get the new collection and verify
62 new_collection = Collection.find_by_uuid match[1]
63 match = new_collection.name.match /^salvaged from (.*),.*/
65 assert_equal src_collection.uuid, match[1]
67 # verify the new collection's manifest format
68 match = new_collection.manifest_text.match /^. (.*) (.*):invalid_manifest_text.txt\n. (.*) (.*):salvaged_data/
72 test "salvage collection with no uuid required argument" do
73 status = SalvageCollection.salvage_collection nil
74 assert_equal false, status
77 test "salvage collection with bogus uuid" do
78 status = SalvageCollection.salvage_collection 'bogus-uuid'
79 assert_equal false, status
82 test "salvage collection with no env ARVADOS_API_HOST" do
85 ENV['ARVADOS_API_HOST'] = ''
86 ENV['ARVADOS_API_TOKEN'] = ''
87 SalvageCollection.salvage_collection collections('user_agreement').uuid
89 assert_equal "Exit code 200", e.message
92 assert_equal true, exited
95 test "salvage collection with error during arv-put" do
96 # try to salvage collection while mimicking error during arv-put
97 status = SalvageCollection.salvage_collection collections('user_agreement').uuid
98 assert_equal false, status