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"
7 def `(cmd) # override kernel ` method
8 if cmd.include? 'arv-put'
9 file_contents = file = File.new(cmd.split[-1], "r").gets
11 # simulate arv-put error when it is 'user_agreement'
12 if file_contents.include? 'GNU_General_Public_License'
16 Digest::MD5.hexdigest(TEST_MANIFEST) +
17 " 0:" + TEST_MANIFEST.length.to_s + ":invalid_manifest_text.txt\n"
23 raise "Exit code #{code}" if code != 0
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'
37 test "salvage test collection" do
38 # create a collection to test salvaging
39 src_collection = Collection.new name: "test collection", manifest_text: TEST_MANIFEST
42 # salvage this collection
43 SalvageCollection.salvage_collection src_collection.uuid, 'test salvage collection - see #6277, #6859'
45 # verify the updated src_collection data
46 updated_src_collection = Collection.find_by_uuid src_collection.uuid
47 updated_name = updated_src_collection.name
48 assert_equal true, updated_name.include?(src_collection.name)
50 match = updated_name.match /^test collection.*salvaged data at (.*)\)$/
52 assert_not_nil match[1]
53 assert_empty updated_src_collection.manifest_text
55 # match[1] is the uuid of the new collection created from src_collection's salvaged data
56 # use this to get the new collection and verify
57 new_collection = Collection.find_by_uuid match[1]
58 match = new_collection.name.match /^salvaged from (.*),.*/
60 assert_equal src_collection.uuid, match[1]
62 # verify the new collection's manifest format
63 match = new_collection.manifest_text.match /^. (.*) (.*):invalid_manifest_text.txt\n. (.*) (.*):salvaged_data/
67 test "salvage collection with no uuid required argument" do
68 status = SalvageCollection.salvage_collection nil
69 assert_equal false, status
72 test "salvage collection with bogus uuid" do
73 status = SalvageCollection.salvage_collection 'bogus-uuid'
74 assert_equal false, status
77 test "salvage collection with no env ARVADOS_API_HOST" do
80 ENV['ARVADOS_API_HOST'] = ''
81 ENV['ARVADOS_API_TOKEN'] = ''
82 SalvageCollection.salvage_collection collections('user_agreement').uuid
84 assert_equal "Exit code 1", e.message
87 assert_equal true, exited
90 test "salvage collection with during arv-put" do
91 # try to salvage collection while mimicking error during arv-put
92 status = SalvageCollection.salvage_collection collections('user_agreement').uuid
93 assert_equal false, status