[ARVADOS] updated: ea28328480051317963e31c9be155c2c28babb09

git at public.curoverse.com git at public.curoverse.com
Wed Jan 7 13:01:02 EST 2015


Summary of changes:
 services/api/app/models/collection.rb              |  2 +-
 .../20141208174653_collection_file_names.rb        |  4 +-
 services/api/db/structure.sql                      |  2 +-
 .../api/test/integration/collections_api_test.rb   | 58 ++++++++++++++++++++++
 services/api/test/unit/collection_test.rb          | 50 ++++++++++++++-----
 5 files changed, 99 insertions(+), 17 deletions(-)

       via  ea28328480051317963e31c9be155c2c28babb09 (commit)
      from  cac35f0e43192a790eee669f83c26c7d47ccbed4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit ea28328480051317963e31c9be155c2c28babb09
Author: Radhika Chippada <radhika at curoverse.com>
Date:   Wed Jan 7 12:59:26 2015 -0500

    4523: add tests to search for file name

diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb
index 2017060..6c5e1ac 100644
--- a/services/api/app/models/collection.rb
+++ b/services/api/app/models/collection.rb
@@ -136,7 +136,7 @@ class Collection < ArvadosModel
           file_names << file_name if file_name != '.'
         end
       end
-      self.file_names = file_names.uniq.join(" ")[0,2**12]
+      self.file_names = file_names.uniq.join(" ")[0,2**13]
     end
     true
   end
diff --git a/services/api/db/migrate/20141208174653_collection_file_names.rb b/services/api/db/migrate/20141208174653_collection_file_names.rb
index dc21584..8cccbba 100644
--- a/services/api/db/migrate/20141208174653_collection_file_names.rb
+++ b/services/api/db/migrate/20141208174653_collection_file_names.rb
@@ -2,7 +2,7 @@ class CollectionFileNames < ActiveRecord::Migration
   include CurrentApiClient
 
   def up
-    add_column :collections, :file_names, :string, :limit => 2**12
+    add_column :collections, :file_names, :string, :limit => 2**13
 
     act_as_system_user do
       Collection.all.each do |c|
@@ -13,7 +13,7 @@ class CollectionFileNames < ActiveRecord::Migration
             file_names << file_name if file_name != '.'
           end
 
-          c.file_names = file_names.uniq.join(" ")[0,2**12]
+          c.file_names = file_names.uniq.join(" ")[0,2**13]
           c.save!
         end
       end
diff --git a/services/api/db/structure.sql b/services/api/db/structure.sql
index 047a901..df3e58f 100644
--- a/services/api/db/structure.sql
+++ b/services/api/db/structure.sql
@@ -170,7 +170,7 @@ CREATE TABLE collections (
     description character varying(524288),
     properties text,
     expires_at date,
-    file_names character varying(4096)
+    file_names character varying(8192)
 );
 
 
diff --git a/services/api/test/integration/collections_api_test.rb b/services/api/test/integration/collections_api_test.rb
index 7680592..40b19fe 100644
--- a/services/api/test/integration/collections_api_test.rb
+++ b/services/api/test/integration/collections_api_test.rb
@@ -133,5 +133,63 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest
     assert_equal 'a name', json_response['name']
   end
 
+  test "create collection, verify file_names not returned, and search with filename" do
+    signing_opts = {
+      key: Rails.configuration.blob_signing_key,
+      api_token: api_token(:active),
+    }
+    signed_locator = Blob.sign_locator('bad42fa702ae3ea7d999fef11b46f450+44', signing_opts)
 
+    post "/arvados/v1/collections", {
+      format: :json,
+      collection: "{\"manifest_text\":\". #{signed_locator} 0:44:my_test_file.txt\\n\"}"
+    }, auth(:active)
+    assert_response 200
+    assert_equal '0f99f4087beb13dec46d36db9fa6cebf+60', json_response['portable_data_hash']
+    assert_nil json_response['description']
+    assert_nil json_response['file_names']
+
+    put "/arvados/v1/collections/#{json_response['uuid']}", {
+      format: :json,
+      collection: { description: "my test collection description" }
+    }, auth(:active)
+    assert_response :success
+    assert_equal 'my test collection description', json_response['description']
+    assert_equal '0f99f4087beb13dec46d36db9fa6cebf+60', json_response['portable_data_hash']
+    assert_nil json_response['file_names']
+
+    get '/arvados/v1/collections', {
+      where: { any: ['contains', '87beb13dec46d36db9fa'] }
+    }, auth(:active)
+    assert_response :success
+    response_items = json_response['items']
+    assert_not_nil response_items
+    first_item = json_response['items'].first
+    assert_not_nil first_item
+    assert_equal 'my test collection description', first_item['description']
+    assert_equal '0f99f4087beb13dec46d36db9fa6cebf+60', first_item['portable_data_hash']
+    assert_nil first_item['file_names']
+
+    get '/arvados/v1/collections', {
+      where: { any: ['contains', 'my_test_file.txt'] }
+    }, auth(:active)
+    assert_response :success
+    response_items = json_response['items']
+    assert_not_nil response_items
+    assert_equal 1, response_items.size
+    first_item = response_items.first
+    assert_not_nil first_item
+    assert_equal 'my test collection description', first_item['description']
+    assert_equal '0f99f4087beb13dec46d36db9fa6cebf+60', first_item['portable_data_hash']
+    assert_nil first_item['file_names']
+
+    get '/arvados/v1/collections', {
+      where: { any: ['contains', 'there_is_no_such_file.txt'] }
+    }, auth(:active)
+    assert_response :success
+    assert_equal 0, json_response['items_available']
+    response_items = json_response['items']
+    assert_not_nil response_items
+    assert_equal 0, response_items.size
+  end
 end
diff --git a/services/api/test/unit/collection_test.rb b/services/api/test/unit/collection_test.rb
index 1a5eee9..ed257a7 100644
--- a/services/api/test/unit/collection_test.rb
+++ b/services/api/test/unit/collection_test.rb
@@ -51,21 +51,45 @@ class CollectionTest < ActiveSupport::TestCase
     end
   end
 
-  test 'create collection with large manifest text and verify file_names' do
-    act_as_system_user do
-      manifest_text = ". d41d8cd98f00b204e9800998ecf8427e+0"
-      index = 0
-      while manifest_text.length < 2**15
-        manifest_text += ' ' + "0:0:foo#{index}.txt"
-        index += 1
-      end
-      manifest_text += "\n"
+  [
+    [2**15, 0, false],
+    [2**15, 100, false],
+    [2**15, 2**13, false],
+    [2**15, 2**18, true],
+    [100, 2**18, true],
+    [2**18, 100, false],  # file_names has a max size, hence no error even on large manifest
+  ].each do |manifest_size, description_size, expect_exception|
+    test "create collection with manifest size #{manifest_size},
+          description size #{description_size},
+          expect exception #{expect_exception}" do
+      act_as_system_user do
+        manifest_text = '. d41d8cd98f00b204e9800998ecf8427e+0'
+        index = 0
+        while manifest_text.length < manifest_size
+          manifest_text += ' ' + "0:0:longlongfile#{index}.txt"
+          index += 1
+        end
+        manifest_text += "\n"
 
-      c = Collection.create(manifest_text: manifest_text)
+        description = ''
+        while description.length < description_size
+          description += 'a'
+        end
 
-      assert c.valid?
-      created_file_names = c.file_names
-      assert created_file_names
+        begin
+          c = Collection.create(manifest_text: manifest_text, description: description)
+        rescue Exception => e
+        end
+
+        if !expect_exception
+          assert c.valid?
+          created_file_names = c.file_names
+          assert created_file_names
+        else
+          assert e
+          assert e.message.include? 'exceeds maximum'
+        end
+      end
     end
   end
 

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list