X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/0df7a1c38affbc50a9c7d8834f9822e398860d91..06a0c1d9f2e6cf1d5a9fd00b53071d857252f9fa:/services/api/test/integration/select_test.rb diff --git a/services/api/test/integration/select_test.rb b/services/api/test/integration/select_test.rb index 522daa7ff8..b5f09df7c7 100644 --- a/services/api/test/integration/select_test.rb +++ b/services/api/test/integration/select_test.rb @@ -5,14 +5,78 @@ class SelectTest < ActionDispatch::IntegrationTest get "/arvados/v1/links", {:format => :json, :select => ['uuid', 'link_class']}, auth(:active) assert_response :success assert_equal json_response['items'].count, json_response['items'].select { |i| - i['uuid'] != nil and i['link_class'] != nil and i['head_uuid'] == nil and i['tail_uuid'] == nil + i.count == 2 and i['uuid'] != nil and i['link_class'] != nil }.count end - test "should only get distinct values" do - get "/arvados/v1/links", {:format => :json, :select => ['link_class'], :distinct => "link_class"}, auth(:active) + test "fewer distinct than total count" do + get "/arvados/v1/links", {:format => :json, :select => ['link_class'], :distinct => false}, auth(:active) assert_response :success - assert_equal json_response['items'].uniq.count, json_response['items'].count + links = json_response['items'] + + get "/arvados/v1/links", {:format => :json, :select => ['link_class'], :distinct => true}, auth(:active) + assert_response :success + distinct = json_response['items'] + + assert distinct.count < links.count, "distinct count should be less than link count" + assert_equal links.uniq.count, distinct.count + end + + test "select with order" do + get "/arvados/v1/links", {:format => :json, :select => ['uuid'], :order => ["uuid asc"]}, auth(:active) + assert_response :success + + assert json_response['items'].length > 0 + + p = "" + json_response['items'].each do |i| + assert i['uuid'] > p + p = i['uuid'] + end + end + + test "select two columns with order" do + get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => ['link_class asc', "uuid desc"]}, auth(:active) + assert_response :success + + assert json_response['items'].length > 0 + + prev_link_class = "" + prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz" + + json_response['items'].each do |i| + if prev_link_class != i['link_class'] + prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz" + end + + assert i['link_class'] >= prev_link_class + assert i['uuid'] < prev_uuid + + prev_link_class = i['link_class'] + prev_uuid = i['uuid'] + end + end + + test "select two columns with old-style order syntax" do + get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => 'link_class asc, uuid desc'}, auth(:active) + assert_response :success + + assert json_response['items'].length > 0 + + prev_link_class = "" + prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz" + + json_response['items'].each do |i| + if prev_link_class != i['link_class'] + prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz" + end + + assert i['link_class'] >= prev_link_class + assert i['uuid'] < prev_uuid + + prev_link_class = i['link_class'] + prev_uuid = i['uuid'] + end end end