3 class PipelineInstanceTest < ActiveSupport::TestCase
5 test "check active and success for a pipeline in new state" do
6 pi = pipeline_instances :new_pipeline
8 assert_equal 'New', pi.state, 'expected state to be New for :new_pipeline'
10 # save the pipeline and expect state to be New
11 Thread.current[:user] = users(:admin)
14 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
15 assert_equal PipelineInstance::New, pi.state, 'expected state to be New for new pipeline'
18 test "check active and success for a newly created pipeline" do
19 set_user_from_auth :active
21 pi = PipelineInstance.create(state: 'Ready')
24 assert pi.valid?, 'expected newly created empty pipeline to be valid ' + pi.errors.messages.to_s
25 assert_equal 'Ready', pi.state, 'expected state to be Ready for a new empty pipeline'
28 test "update attributes for pipeline" do
29 Thread.current[:user] = users(:admin)
31 pi = pipeline_instances :new_pipeline
33 # add a component with no input and expect state to be New
34 component = {'script_parameters' => {"input_not_provided" => {"required" => true}}}
35 pi.components['first'] = component
36 components = pi.components
37 pi.update_attribute 'components', pi.components
38 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
39 assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
40 assert_equal pi.components.size, 1, 'expected one component'
42 # add a component with no input not required
43 component = {'script_parameters' => {"input_not_provided" => {"required" => false}}}
44 pi.components['first'] = component
45 components = pi.components
46 pi.update_attribute 'components', pi.components
47 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
48 assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
49 assert_equal pi.components.size, 1, 'expected one component'
51 # add a component with input and expect state to become Ready
52 component = {'script_parameters' => {"input" => "yyyad4b39ca5a924e481008009d94e32+210"}}
53 pi.components['first'] = component
54 components = pi.components
55 pi.update_attribute 'components', pi.components
56 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
57 assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
58 assert_equal pi.components.size, 1, 'expected one component'
60 pi.state = PipelineInstance::RunningOnServer
62 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
63 assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating state to RunningOnServer'
65 pi.state = PipelineInstance::Paused
67 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
68 assert_equal PipelineInstance::Paused, pi.state, 'expected state to be Paused after updating state to Paused'
70 pi.state = PipelineInstance::Complete
72 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
73 assert_equal PipelineInstance::Complete, pi.state, 'expected state to be Complete after updating state to Complete'
77 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
78 assert_equal PipelineInstance::Complete, pi.state, 'expected state to be unchanged with set to a bogus value'
80 pi.state = PipelineInstance::Failed
82 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
83 assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating state to Failed'
86 test "update attributes for pipeline with two components" do
87 pi = pipeline_instances :new_pipeline
89 # add two components, one with input and one with no input and expect state to be New
90 component1 = {'script_parameters' => {"something" => "xxxad4b39ca5a924e481008009d94e32+210", "input" => "c1bad4b39ca5a924e481008009d94e32+210"}}
91 component2 = {'script_parameters' => {"something_else" => "xxxad4b39ca5a924e481008009d94e32+210", "input_missing" => {"required" => true}}}
92 pi.components['first'] = component1
93 pi.components['second'] = component2
94 components = pi.components
96 Thread.current[:user] = users(:admin)
97 pi.update_attribute 'components', pi.components
99 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
100 assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
101 assert_equal pi.components.size, 2, 'expected two components'
104 [:has_component_with_no_script_parameters,
105 :has_component_with_empty_script_parameters].each do |pi_name|
106 test "update pipeline that #{pi_name}" do
107 pi = pipeline_instances pi_name
109 Thread.current[:user] = users(:active)
110 assert_equal PipelineInstance::Ready, pi.state