3 class PipelineInstanceTest < ActiveSupport::TestCase
4 def find_pi_with(token_name, pi_name)
6 find_fixture(PipelineInstance, pi_name)
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)
13 test "admin can edit name" do
14 assert(attribute_editable_for?(:admin, "new_pipeline_in_subproject",
16 "admin not allowed to edit pipeline instance name")
19 test "project owner can edit name" do
20 assert(attribute_editable_for?(:active, "new_pipeline_in_subproject",
22 "project owner not allowed to edit pipeline instance name")
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")
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")
37 test "name editable on completed pipeline" do
38 assert(attribute_editable_for?(:active, "has_component_with_completed_jobs",
40 "name not editable on complete pipeline")
43 test "components editable on new pipeline" do
44 assert(attribute_editable_for?(:active, "new_pipeline", "components"),
45 "components not editable on new pipeline")
48 test "components not editable on completed pipeline" do
49 refute(attribute_editable_for?(:active, "has_component_with_completed_jobs",
51 "components not editable on new pipeline")
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)
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)
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? })
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)
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")
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")
92 test "has_readable_logs? for unrun pipeline" do
93 pi = find_pi_with(:active, "new_pipeline")
94 refute(pi.has_readable_logs?)
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?)
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?)
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?)