10111: Merge branch 'master' into 10111-cr-provenance-graph
[arvados.git] / apps / workbench / test / unit / pipeline_instance_test.rb
1 require 'test_helper'
2
3 class PipelineInstanceTest < ActiveSupport::TestCase
4
5   reset_api_fixtures :after_each_test, false
6
7   def find_pi_with(token_name, pi_name)
8     use_token token_name
9     find_fixture(PipelineInstance, pi_name)
10   end
11
12   def attribute_editable_for?(token_name, pi_name, attr_name, ever=nil)
13     find_pi_with(token_name, pi_name).attribute_editable?(attr_name, ever)
14   end
15
16   test "admin can edit name" do
17     assert(attribute_editable_for?(:admin, "new_pipeline_in_subproject",
18                                    "name"),
19            "admin not allowed to edit pipeline instance name")
20   end
21
22   test "project owner can edit name" do
23     assert(attribute_editable_for?(:active, "new_pipeline_in_subproject",
24                                    "name"),
25            "project owner not allowed to edit pipeline instance name")
26   end
27
28   test "project admin can edit name" do
29     assert(attribute_editable_for?(:subproject_admin,
30                                    "new_pipeline_in_subproject", "name"),
31            "project admin not allowed to edit pipeline instance name")
32   end
33
34   test "project viewer cannot edit name" do
35     refute(attribute_editable_for?(:project_viewer,
36                                    "new_pipeline_in_subproject", "name"),
37            "project viewer allowed to edit pipeline instance name")
38   end
39
40   test "name editable on completed pipeline" do
41     assert(attribute_editable_for?(:active, "has_component_with_completed_jobs",
42                                    "name"),
43            "name not editable on complete pipeline")
44   end
45
46   test "components editable on new pipeline" do
47     assert(attribute_editable_for?(:active, "new_pipeline", "components"),
48            "components not editable on new pipeline")
49   end
50
51   test "components not editable on completed pipeline" do
52     refute(attribute_editable_for?(:active, "has_component_with_completed_jobs",
53                                    "components"),
54            "components not editable on new pipeline")
55   end
56
57   test "job_logs for partially complete pipeline" do
58     log_uuid = api_fixture("collections", "real_log_collection", "uuid")
59     pi = find_pi_with(:active, "running_pipeline_with_complete_job")
60     assert_equal({previous: log_uuid, running: nil}, pi.job_log_ids)
61   end
62
63   test "job_logs for complete pipeline" do
64     log_uuid = api_fixture("collections", "real_log_collection", "uuid")
65     pi = find_pi_with(:active, "complete_pipeline_with_two_jobs")
66     assert_equal({ancient: log_uuid, previous: log_uuid}, pi.job_log_ids)
67   end
68
69   test "job_logs for malformed pipeline" do
70     pi = find_pi_with(:active, "components_is_jobspec")
71     assert_empty(pi.job_log_ids.select { |_, log| not log.nil? })
72   end
73
74   def check_stderr_logs(token_name, pi_name, log_name)
75     pi = find_pi_with(token_name, pi_name)
76     actual_logs = pi.stderr_log_lines
77     expected_text = api_fixture("logs", log_name, "properties", "text")
78     expected_text.each_line do |log_line|
79       assert_includes(actual_logs, log_line.chomp)
80     end
81   end
82
83   test "stderr_logs for running pipeline" do
84     check_stderr_logs(:active,
85                       "pipeline_in_publicly_accessible_project",
86                       "log_line_for_pipeline_in_publicly_accessible_project")
87   end
88
89   test "stderr_logs for job in complete pipeline" do
90     check_stderr_logs(:active,
91                       "failed_pipeline_with_two_jobs",
92                       "crunchstat_for_previous_job")
93   end
94
95   test "has_readable_logs? for unrun pipeline" do
96     pi = find_pi_with(:active, "new_pipeline")
97     refute(pi.has_readable_logs?)
98   end
99
100   test "has_readable_logs? for running pipeline" do
101     pi = find_pi_with(:active, "running_pipeline_with_complete_job")
102     assert(pi.has_readable_logs?)
103   end
104
105   test "has_readable_logs? for complete pipeline" do
106     pi = find_pi_with(:active, "pipeline_in_publicly_accessible_project_but_other_objects_elsewhere")
107     assert(pi.has_readable_logs?)
108   end
109
110   test "has_readable_logs? for complete pipeline when jobs unreadable" do
111     pi = find_pi_with(:anonymous, "pipeline_in_publicly_accessible_project_but_other_objects_elsewhere")
112     refute(pi.has_readable_logs?)
113   end
114 end