3 class PipelineInstanceTest < ActiveSupport::TestCase
5 reset_api_fixtures :after_each_test, false
7 def find_pi_with(token_name, pi_name)
9 find_fixture(PipelineInstance, pi_name)
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)
16 test "admin can edit name" do
17 assert(attribute_editable_for?(:admin, "new_pipeline_in_subproject",
19 "admin not allowed to edit pipeline instance name")
22 test "project owner can edit name" do
23 assert(attribute_editable_for?(:active, "new_pipeline_in_subproject",
25 "project owner not allowed to edit pipeline instance name")
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")
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")
40 test "name editable on completed pipeline" do
41 assert(attribute_editable_for?(:active, "has_component_with_completed_jobs",
43 "name not editable on complete pipeline")
46 test "components editable on new pipeline" do
47 assert(attribute_editable_for?(:active, "new_pipeline", "components"),
48 "components not editable on new pipeline")
51 test "components not editable on completed pipeline" do
52 refute(attribute_editable_for?(:active, "has_component_with_completed_jobs",
54 "components not editable on new pipeline")
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)
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)
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? })
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)
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")
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")
95 test "has_readable_logs? for unrun pipeline" do
96 pi = find_pi_with(:active, "new_pipeline")
97 refute(pi.has_readable_logs?)
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?)
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?)
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?)