Merge branch 'master' into 1971-show-image-thumbnails
[arvados.git] / services / api / test / functional / arvados / v1 / collections_controller_test.rb
index 0663eb94d5be8c8644461ab7c047166b94c393d4..6990e97413e031edeaf649d3d6e22cc89bd3cc7c 100644 (file)
@@ -9,12 +9,53 @@ class Arvados::V1::CollectionsControllerTest < ActionController::TestCase
     assert_not_nil assigns(:objects)
   end
 
+  [0,1,2].each do |limit|
+    test "get index with limit=#{limit}" do
+      authorize_with :active
+      get :index, limit: limit
+      assert_response :success
+      assert_equal limit, assigns(:objects).count
+      resp = JSON.parse(@response.body)
+      assert_equal limit, resp['limit']
+    end
+  end
+
+  test "items.count == items_available" do
+    authorize_with :active
+    get :index, limit: 100000
+    assert_response :success
+    resp = JSON.parse(@response.body)
+    assert_equal resp['items_available'], assigns(:objects).length
+    assert_equal resp['items_available'], resp['items'].count
+    unique_uuids = resp['items'].collect { |i| i['uuid'] }.compact.uniq
+    assert_equal unique_uuids.count, resp['items'].count
+  end
+
+  test "get index with limit=2 offset=99999" do
+    # Assume there are not that many test fixtures.
+    authorize_with :active
+    get :index, limit: 2, offset: 99999
+    assert_response :success
+    assert_equal 0, assigns(:objects).count
+    resp = JSON.parse(@response.body)
+    assert_equal 2, resp['limit']
+    assert_equal 99999, resp['offset']
+  end
+
   test "should create" do
     authorize_with :active
     test_collection = {
-      manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",
-      uuid: "d30fe8ae534397864cb96c544f4cf102"
+      manifest_text: <<-EOS
+. d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt
+. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
+. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
+./baz acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
+EOS
     }
+    test_collection[:uuid] =
+      Digest::MD5.hexdigest(test_collection[:manifest_text]) +
+      '+' +
+      test_collection[:manifest_text].length.to_s
     post :create, {
       collection: test_collection
     }
@@ -22,13 +63,36 @@ class Arvados::V1::CollectionsControllerTest < ActionController::TestCase
     assert_nil assigns(:objects)
 
     get :show, {
-      id: "d30fe8ae534397864cb96c544f4cf102"
+      id: test_collection[:uuid]
     }
     assert_response :success
     assert_not_nil assigns(:object)
     resp = JSON.parse(@response.body)
-    assert_equal 'd30fe8ae534397864cb96c544f4cf102+47', resp['uuid']
+    assert_equal test_collection[:uuid], resp['uuid']
     assert_equal test_collection[:manifest_text], resp['manifest_text']
+    assert_equal 9, resp['data_size']
+    assert_equal [['.', 'foo.txt', 0],
+                  ['.', 'bar.txt', 6],
+                  ['./baz', 'bar.txt', 3]], resp['files']
+  end
+
+  test "list of files is correct for empty manifest" do
+    authorize_with :active
+    test_collection = {
+      manifest_text: "",
+      uuid: "d41d8cd98f00b204e9800998ecf8427e+0"
+    }
+    post :create, {
+      collection: test_collection
+    }
+    assert_response :success
+
+    get :show, {
+      id: "d41d8cd98f00b204e9800998ecf8427e+0"
+    }
+    assert_response :success
+    resp = JSON.parse(@response.body)
+    assert_equal [], resp['files']
   end
 
   test "create with owner_uuid set to owned group" do
@@ -145,4 +209,15 @@ class Arvados::V1::CollectionsControllerTest < ActionController::TestCase
     assert_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
   end
 
+  test "search collections with 'any' operator" do
+    authorize_with :active
+    get :index, {
+      where: { any: ['contains', '7f9102c395f4ffc5e3'] }
+    }
+    assert_response :success
+    found = assigns(:objects).collect(&:uuid)
+    assert_equal 1, found.count
+    assert_equal true, !!found.index('1f4b0bc7583c2a7f9102c395f4ffc5e3+45')
+  end
+
 end