1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class WorkflowTest < ActiveSupport::TestCase
8 test "create workflow with no definition yaml" do
9 set_user_from_auth :active
15 w = Workflow.create!(wf)
19 test "create workflow with valid definition yaml" do
20 set_user_from_auth :active
24 definition: "k1:\n v1: x\n v2: y"
27 w = Workflow.create!(wf)
31 test "create workflow with simple string as definition" do
32 set_user_from_auth :active
36 definition: "this is valid yaml"
39 w = Workflow.create!(wf)
43 test "create workflow with invalid definition yaml" do
44 set_user_from_auth :active
48 definition: "k1:\n v1: x\n v2: y"
51 assert_raises(ActiveRecord::RecordInvalid) do
56 test "update workflow with invalid definition yaml" do
57 set_user_from_auth :active
59 w = Workflow.find_by_uuid(workflows(:workflow_with_definition_yml).uuid)
60 definition = "k1:\n v1: x\n v2: y"
62 assert_raises(ActiveRecord::RecordInvalid) do
63 w.update_attributes!(definition: definition)
67 test "update workflow and verify name and description" do
68 set_user_from_auth :active
70 # Workflow name and desc should be set with values from definition yaml
71 # when it does not already have custom values for these fields
72 w = Workflow.find_by_uuid(workflows(:workflow_with_no_name_and_desc).uuid)
73 definition = "name: test name 1\ndescription: test desc 1\nother: some more"
74 w.update_attributes!(definition: definition)
76 assert_equal "test name 1", w.name
77 assert_equal "test desc 1", w.description
79 # Workflow name and desc should be set with values from definition yaml
80 # when it does not already have custom values for these fields
81 definition = "name: test name 2\ndescription: test desc 2\nother: some more"
82 w.update_attributes!(definition: definition)
84 assert_equal "test name 2", w.name
85 assert_equal "test desc 2", w.description
87 # Workflow name and desc should be set with values from definition yaml
88 # even if it means emptying them out
89 definition = "more: etc"
90 w.update_attributes!(definition: definition)
93 assert_nil w.description
95 # Workflow name and desc set using definition yaml should be cleared
96 # if definition yaml is cleared
97 definition = "name: test name 2\ndescription: test desc 2\nother: some more"
98 w.update_attributes!(definition: definition)
101 w.update_attributes!(definition: definition)
104 assert_nil w.description
106 # Workflow name and desc should be set to provided custom values
107 definition = "name: test name 3\ndescription: test desc 3\nother: some more"
108 w.update_attributes!(name: "remains", description: "remains", definition: definition)
110 assert_equal "remains", w.name
111 assert_equal "remains", w.description
113 # Workflow name and desc should retain provided custom values
114 # and should not be overwritten by values from yaml
115 definition = "name: test name 4\ndescription: test desc 4\nother: some more"
116 w.update_attributes!(definition: definition)
118 assert_equal "remains", w.name
119 assert_equal "remains", w.description
121 # Workflow name and desc should retain provided custom values
122 # and not be affected by the clearing of the definition yaml
124 w.update_attributes!(definition: definition)
126 assert_equal "remains", w.name
127 assert_equal "remains", w.description