Merge branch '8784-dir-listings'
[arvados.git] / services / api / test / functional / arvados / v1 / keep_disks_controller_test.rb
index 2cda44f4e44b68729f44930271bda8fd2b8e7d4c..c5bff7b0ccc6597055f00591a7f9323d60fc0e7f 100644 (file)
@@ -1,16 +1,19 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'test_helper'
 
 class Arvados::V1::KeepDisksControllerTest < ActionController::TestCase
 
+  def default_ping_opts
+    {ping_secret: '', service_ssl_flag: false, service_port: 1234}
+  end
+
   test "add keep disk with admin token" do
     authorize_with :admin
-    post :ping, {
-      ping_secret: '',          # required by discovery doc, but ignored
-      service_host: '::1',
-      service_port: 55555,
-      service_ssl_flag: false,
-      filesystem_uuid: 'eb1e77a1-db84-4193-b6e6-ca2894f67d5f'
-    }
+    post :ping, default_ping_opts.
+      merge(filesystem_uuid: 'eb1e77a1-db84-4193-b6e6-ca2894f67d5f')
     assert_response :success
     assert_not_nil assigns(:object)
     new_keep_disk = JSON.parse(@response.body)
@@ -19,39 +22,28 @@ class Arvados::V1::KeepDisksControllerTest < ActionController::TestCase
     assert_not_equal '', new_keep_disk['ping_secret']
   end
 
-  test "add keep disk with no filesystem_uuid" do
-    authorize_with :admin
-    opts = {
-      ping_secret: '',
-      service_host: '::1',
-      service_port: 55555,
-      service_ssl_flag: false
-    }
-    post :ping, opts
-    assert_response :success
-    assert_not_nil JSON.parse(@response.body)['uuid']
-
-    post :ping, opts.merge(filesystem_uuid: '')
-    assert_response :success
-    assert_not_nil JSON.parse(@response.body)['uuid']
+  [
+    {},
+    {filesystem_uuid: ''},
+  ].each do |opts|
+    test "add keep disk with[out] filesystem_uuid #{opts}" do
+      authorize_with :admin
+      post :ping, default_ping_opts.merge(opts)
+      assert_response :success
+      assert_not_nil JSON.parse(@response.body)['uuid']
+    end
   end
 
   test "refuse to add keep disk without admin token" do
-    post :ping, {
-      ping_secret: '',
-      service_host: '::1',
-      service_port: 55555,
-      service_ssl_flag: false
-    }
+    post :ping, default_ping_opts
     assert_response 404
   end
 
   test "ping keep disk" do
-    post :ping, {
-      id: keep_disks(:nonfull).uuid,
-      ping_secret: keep_disks(:nonfull).ping_secret,
-      filesystem_uuid: keep_disks(:nonfull).filesystem_uuid
-    }
+    post :ping, default_ping_opts.
+      merge(id: keep_disks(:nonfull).uuid,
+            ping_secret: keep_disks(:nonfull).ping_secret,
+            filesystem_uuid: keep_disks(:nonfull).filesystem_uuid)
     assert_response :success
     assert_not_nil assigns(:object)
     keep_disk = JSON.parse(@response.body)
@@ -76,6 +68,10 @@ class Arvados::V1::KeepDisksControllerTest < ActionController::TestCase
     assert_response :success
     items = JSON.parse(@response.body)['items']
     assert_not_equal 0, items.size
+
+    # Check these are still included
+    assert items[0]['service_host']
+    assert items[0]['service_port']
   end
 
   # active user sees non-secret attributes of keep disks
@@ -94,25 +90,7 @@ class Arvados::V1::KeepDisksControllerTest < ActionController::TestCase
     end
   end
 
-  test "search keep_disks by service_port with >= query" do
-    authorize_with :active
-    get :index, {
-      filters: [['service_port', '>=', 25107]]
-    }
-    assert_response :success
-    assert_equal true, assigns(:objects).any?
-  end
-
-  test "search keep_disks by service_port with < query" do
-    authorize_with :active
-    get :index, {
-      filters: [['service_port', '<', 25107]]
-    }
-    assert_response :success
-    assert_equal false, assigns(:objects).any?
-  end
-
-  test "search keep_disks with 'any' operator" do
+  test "search keep_services with 'any' operator" do
     authorize_with :active
     get :index, {
       where: { any: ['contains', 'o2t1q5w'] }
@@ -122,4 +100,5 @@ class Arvados::V1::KeepDisksControllerTest < ActionController::TestCase
     assert_equal true, !!found.index('zzzzz-penuu-5w2o2t1q5wy7fhn')
   end
 
+
 end