1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
6 require 'helpers/git_test_helper'
8 class Arvados::V1::JobsControllerTest < ActionController::TestCase
10 test "search jobs by uuid with >= query" do
11 authorize_with :active
13 filters: [['uuid', '>=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
15 assert_response :success
16 found = assigns(:objects).collect(&:uuid)
17 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
18 assert_equal false, !!found.index('zzzzz-8i9sb-4cf0nhn6xte809j')
21 test "search jobs by uuid with <= query" do
22 authorize_with :active
24 filters: [['uuid', '<=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
26 assert_response :success
27 found = assigns(:objects).collect(&:uuid)
28 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
29 assert_equal true, !!found.index('zzzzz-8i9sb-4cf0nhn6xte809j')
32 test "search jobs by uuid with >= and <= query" do
33 authorize_with :active
35 filters: [['uuid', '>=', 'zzzzz-8i9sb-pshmckwoma9plh7'],
36 ['uuid', '<=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
38 assert_response :success
39 found = assigns(:objects).collect(&:uuid)
40 assert_equal found, ['zzzzz-8i9sb-pshmckwoma9plh7']
43 test "search jobs by uuid with < query" do
44 authorize_with :active
46 filters: [['uuid', '<', 'zzzzz-8i9sb-pshmckwoma9plh7']]
48 assert_response :success
49 found = assigns(:objects).collect(&:uuid)
50 assert_equal false, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
51 assert_equal true, !!found.index('zzzzz-8i9sb-4cf0nhn6xte809j')
54 test "search jobs by uuid with like query" do
55 authorize_with :active
57 filters: [['uuid', 'like', '%hmckwoma9pl%']]
59 assert_response :success
60 found = assigns(:objects).collect(&:uuid)
61 assert_equal found, ['zzzzz-8i9sb-pshmckwoma9plh7']
64 test "search jobs by uuid with 'in' query" do
65 authorize_with :active
67 filters: [['uuid', 'in', ['zzzzz-8i9sb-4cf0nhn6xte809j',
68 'zzzzz-8i9sb-pshmckwoma9plh7']]]
70 assert_response :success
71 found = assigns(:objects).collect(&:uuid)
72 assert_equal found.sort, ['zzzzz-8i9sb-4cf0nhn6xte809j',
73 'zzzzz-8i9sb-pshmckwoma9plh7']
76 test "search jobs by uuid with 'not in' query" do
77 exclude_uuids = [jobs(:running).uuid,
78 jobs(:running_cancelled).uuid]
79 authorize_with :active
81 filters: [['uuid', 'not in', exclude_uuids]]
83 assert_response :success
84 found = assigns(:objects).collect(&:uuid)
85 assert_not_empty found, "'not in' query returned nothing"
86 assert_empty(found & exclude_uuids,
87 "'not in' query returned uuids I asked not to get")
90 ['=', '!='].each do |operator|
91 [['uuid', 'zzzzz-8i9sb-pshmckwoma9plh7'],
92 ['output', nil]].each do |attr, operand|
93 test "search jobs with #{attr} #{operator} #{operand.inspect} query" do
94 authorize_with :active
96 filters: [[attr, operator, operand]]
98 assert_response :success
99 values = assigns(:objects).collect { |x| x.send(attr) }
100 assert_not_empty values, "query should return non-empty result"
102 assert_empty values - [operand], "query results do not satisfy query"
104 assert_empty values & [operand], "query results do not satisfy query"
110 test "search jobs by started_at with < query" do
111 authorize_with :active
112 get :index, params: {
113 filters: [['started_at', '<', Time.now.to_s]]
115 assert_response :success
116 found = assigns(:objects).collect(&:uuid)
117 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
120 test "search jobs by started_at with > query" do
121 authorize_with :active
122 get :index, params: {
123 filters: [['started_at', '>', Time.now.to_s]]
125 assert_response :success
126 assert_equal 0, assigns(:objects).count
129 test "search jobs by started_at with >= query on metric date" do
130 authorize_with :active
131 get :index, params: {
132 filters: [['started_at', '>=', '2014-01-01']]
134 assert_response :success
135 found = assigns(:objects).collect(&:uuid)
136 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
139 test "search jobs by started_at with >= query on metric date and time" do
140 authorize_with :active
141 get :index, params: {
142 filters: [['started_at', '>=', '2014-01-01 01:23:45']]
144 assert_response :success
145 found = assigns(:objects).collect(&:uuid)
146 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
149 test "search jobs with 'any' operator" do
150 authorize_with :active
151 get :index, params: {
152 where: { any: ['contains', 'pshmckw'] }
154 assert_response :success
155 found = assigns(:objects).collect(&:uuid)
156 assert_equal 0, found.index('zzzzz-8i9sb-pshmckwoma9plh7')
157 assert_equal 1, found.count
160 test "search jobs by nonexistent column with < query" do
161 authorize_with :active
162 get :index, params: {
163 filters: [['is_borked', '<', 'fizzbuzz']]
168 [:spectator, :admin].each_with_index do |which_token, i|
169 test "get job queue as #{which_token} user" do
170 authorize_with which_token
172 assert_response :success
173 assert_equal 0, assigns(:objects).count
177 test "job includes assigned nodes" do
178 authorize_with :active
179 get :show, params: {id: jobs(:nearly_finished_job).uuid}
180 assert_response :success
181 assert_equal([nodes(:busy).uuid], json_response["node_uuids"])
184 test 'get job with components' do
185 authorize_with :active
186 get :show, params: {id: jobs(:running_job_with_components).uuid}
187 assert_response :success
188 assert_not_nil json_response["components"]
189 assert_equal ["component1", "component2"], json_response["components"].keys