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