Merge branch '15241-collection-input' refs #15241
[arvados.git] / apps / workbench / test / unit / pipeline_instance_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class PipelineInstanceTest < ActiveSupport::TestCase
8
9   reset_api_fixtures :after_each_test, false
10
11   def find_pi_with(token_name, pi_name)
12     use_token token_name
13     find_fixture(PipelineInstance, pi_name)
14   end
15
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)
18   end
19
20   test "admin can edit name" do
21     assert(attribute_editable_for?(:admin, "new_pipeline_in_subproject",
22                                    "name"),
23            "admin not allowed to edit pipeline instance name")
24   end
25
26   test "project owner can edit name" do
27     assert(attribute_editable_for?(:active, "new_pipeline_in_subproject",
28                                    "name"),
29            "project owner not allowed to edit pipeline instance name")
30   end
31
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")
36   end
37
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")
42   end
43
44   test "name editable on completed pipeline" do
45     assert(attribute_editable_for?(:active, "has_component_with_completed_jobs",
46                                    "name"),
47            "name not editable on complete pipeline")
48   end
49
50   test "components editable on new pipeline" do
51     assert(attribute_editable_for?(:active, "new_pipeline", "components"),
52            "components not editable on new pipeline")
53   end
54
55   test "components not editable on completed pipeline" do
56     refute(attribute_editable_for?(:active, "has_component_with_completed_jobs",
57                                    "components"),
58            "components not editable on new pipeline")
59   end
60
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)
65   end
66
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)
71   end
72
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? })
76   end
77
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)
84     end
85   end
86
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")
91   end
92
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")
97   end
98
99   test "has_readable_logs? for unrun pipeline" do
100     pi = find_pi_with(:active, "new_pipeline")
101     refute(pi.has_readable_logs?)
102   end
103
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?)
107   end
108
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?)
112   end
113
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?)
117   end
118 end