3 class PipelineInstancesControllerTest < ActionController::TestCase
4 def create_instance_long_enough_to(instance_attrs={})
5 # create 'two_part' pipeline with the given instance attributes
6 pt_fixture = api_fixture('pipeline_templates')['two_part']
8 pipeline_instance: instance_attrs.merge({
9 pipeline_template_uuid: pt_fixture['uuid']
12 }, session_for(:active)
13 assert_response :success
14 pi_uuid = assigns(:object).uuid
15 assert_not_nil assigns(:object)
18 yield pi_uuid, pt_fixture
20 # delete the pipeline instance
22 PipelineInstance.where(uuid: pi_uuid).first.destroy
25 test "pipeline instance components populated after create" do
26 create_instance_long_enough_to do |new_instance_uuid, template_fixture|
27 assert_equal(template_fixture['components'].to_json,
28 assigns(:object).components.to_json)
32 test "can render pipeline instance with tagged collections" do
33 # Make sure to pass in a tagged collection to test that part of the rendering behavior.
35 {id: api_fixture("pipeline_instances")["pipeline_with_tagged_collection_input"]["uuid"]},
37 assert_response :success
40 test "update script_parameters one at a time using merge param" do
41 template_fixture = api_fixture('pipeline_templates')['two_part']
43 id: api_fixture("pipeline_instances")["pipeline_to_merge_params"]["uuid"],
60 }, session_for(:active)
61 assert_response :success
62 assert_not_nil assigns(:object)
63 orig_params = template_fixture['components']['part-two']['script_parameters']
64 new_params = assigns(:object).components[:'part-two'][:script_parameters]
65 orig_params.keys.each do |k|
66 unless %w(integer_with_value plain_string).index(k)
67 assert_equal orig_params[k].to_json, new_params[k.to_sym].to_json
72 test "component rendering copes with unexpeceted components format" do
74 {id: api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]},
76 assert_response :success
79 test "dates in JSON components are parsed" do
81 {id: api_fixture('pipeline_instances')['has_component_with_completed_jobs']['uuid']},
83 assert_response :success
84 assert_not_nil assigns(:object)
85 assert_not_nil assigns(:object).components[:foo][:job]
86 assert assigns(:object).components[:foo][:job][:started_at].is_a? Time
87 assert assigns(:object).components[:foo][:job][:finished_at].is_a? Time
90 # The next two tests ensure that a pipeline instance can be copied
91 # when the template has components that do not exist in the
92 # instance (ticket #4000).
94 test "copy pipeline instance with components=use_latest" do
97 id: api_fixture('pipeline_instances')['pipeline_with_newer_template']['uuid'],
98 components: 'use_latest',
101 state: 'RunningOnServer'
104 session_for(:active))
106 assert_not_nil assigns(:object)
108 # Component 'foo' has script parameters only in the pipeline instance.
109 # Component 'bar' is present only in the pipeline_template.
110 # Test that the copied pipeline instance includes parameters for
111 # component 'foo' from the source instance, and parameters for
112 # component 'bar' from the source template.
114 assert_not_nil assigns(:object).components[:foo]
115 foo = assigns(:object).components[:foo]
116 assert_not_nil foo[:script_parameters]
117 assert_not_nil foo[:script_parameters][:input]
118 assert_equal 'foo instance input', foo[:script_parameters][:input][:title]
120 assert_not_nil assigns(:object).components[:bar]
121 bar = assigns(:object).components[:bar]
122 assert_not_nil bar[:script_parameters]
123 assert_not_nil bar[:script_parameters][:input]
124 assert_equal 'bar template input', bar[:script_parameters][:input][:title]
127 test "copy pipeline instance on newer template works with script=use_same" do
130 id: api_fixture('pipeline_instances')['pipeline_with_newer_template']['uuid'],
131 components: 'use_latest',
134 state: 'RunningOnServer'
137 session_for(:active))
139 assert_not_nil assigns(:object)
141 # Test that relevant component parameters were copied from both
142 # the source instance and source template, respectively (see
145 assert_not_nil assigns(:object).components[:foo]
146 foo = assigns(:object).components[:foo]
147 assert_not_nil foo[:script_parameters]
148 assert_not_nil foo[:script_parameters][:input]
149 assert_equal 'foo instance input', foo[:script_parameters][:input][:title]
151 assert_not_nil assigns(:object).components[:bar]
152 bar = assigns(:object).components[:bar]
153 assert_not_nil bar[:script_parameters]
154 assert_not_nil bar[:script_parameters][:input]
155 assert_equal 'bar template input', bar[:script_parameters][:input][:title]