1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class PipelineInstanceTest < ActiveSupport::TestCase
9 reset_api_fixtures :after_each_test, false
11 def find_pi_with(token_name, pi_name)
13 find_fixture(PipelineInstance, pi_name)
16 def attribute_editable_for?(token_name, pi_name, attr_name, ever=nil)
17 find_pi_with(token_name, pi_name).attribute_editable?(attr_name, ever)
20 test "admin can edit name" do
21 assert(attribute_editable_for?(:admin, "new_pipeline_in_subproject",
23 "admin not allowed to edit pipeline instance name")
26 test "project owner can edit name" do
27 assert(attribute_editable_for?(:active, "new_pipeline_in_subproject",
29 "project owner not allowed to edit pipeline instance name")
32 test "project admin can edit name" do
33 assert(attribute_editable_for?(:subproject_admin,
34 "new_pipeline_in_subproject", "name"),
35 "project admin not allowed to edit pipeline instance name")
38 test "project viewer cannot edit name" do
39 refute(attribute_editable_for?(:project_viewer,
40 "new_pipeline_in_subproject", "name"),
41 "project viewer allowed to edit pipeline instance name")
44 test "name editable on completed pipeline" do
45 assert(attribute_editable_for?(:active, "has_component_with_completed_jobs",
47 "name not editable on complete pipeline")
50 test "components editable on new pipeline" do
51 assert(attribute_editable_for?(:active, "new_pipeline", "components"),
52 "components not editable on new pipeline")
55 test "components not editable on completed pipeline" do
56 refute(attribute_editable_for?(:active, "has_component_with_completed_jobs",
58 "components not editable on new pipeline")
61 test "job_logs for partially complete pipeline" do
62 log_uuid = api_fixture("collections", "real_log_collection", "uuid")
63 pi = find_pi_with(:active, "running_pipeline_with_complete_job")
64 assert_equal({previous: log_uuid, running: nil}, pi.job_log_ids)
67 test "job_logs for complete pipeline" do
68 log_uuid = api_fixture("collections", "real_log_collection", "uuid")
69 pi = find_pi_with(:active, "complete_pipeline_with_two_jobs")
70 assert_equal({ancient: log_uuid, previous: log_uuid}, pi.job_log_ids)
73 test "job_logs for malformed pipeline" do
74 pi = find_pi_with(:active, "components_is_jobspec")
75 assert_empty(pi.job_log_ids.select { |_, log| not log.nil? })
78 def check_stderr_logs(token_name, pi_name, log_name)
79 pi = find_pi_with(token_name, pi_name)
80 actual_logs = pi.stderr_log_lines
81 expected_text = api_fixture("logs", log_name, "properties", "text")
82 expected_text.each_line do |log_line|
83 assert_includes(actual_logs, log_line.chomp)
87 test "stderr_logs for running pipeline" do
88 check_stderr_logs(:active,
89 "pipeline_in_publicly_accessible_project",
90 "log_line_for_pipeline_in_publicly_accessible_project")
93 test "stderr_logs for job in complete pipeline" do
94 check_stderr_logs(:active,
95 "failed_pipeline_with_two_jobs",
96 "crunchstat_for_previous_job")
99 test "has_readable_logs? for unrun pipeline" do
100 pi = find_pi_with(:active, "new_pipeline")
101 refute(pi.has_readable_logs?)
104 test "has_readable_logs? for running pipeline" do
105 pi = find_pi_with(:active, "running_pipeline_with_complete_job")
106 assert(pi.has_readable_logs?)
109 test "has_readable_logs? for complete pipeline" do
110 pi = find_pi_with(:active, "pipeline_in_publicly_accessible_project_but_other_objects_elsewhere")
111 assert(pi.has_readable_logs?)
114 test "has_readable_logs? for complete pipeline when jobs unreadable" do
115 pi = find_pi_with(:anonymous, "pipeline_in_publicly_accessible_project_but_other_objects_elsewhere")
116 refute(pi.has_readable_logs?)