X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/3723f697b61ce60858455473b3a5464a2da65bfb..cb4efac6793d18892dde09c631895cb98c3df470:/services/api/test/unit/workflow_test.rb diff --git a/services/api/test/unit/workflow_test.rb b/services/api/test/unit/workflow_test.rb index 7bcf2f6b54..26cd7f215e 100644 --- a/services/api/test/unit/workflow_test.rb +++ b/services/api/test/unit/workflow_test.rb @@ -1,7 +1,11 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' class WorkflowTest < ActiveSupport::TestCase - test "create workflow with no workflow yaml" do + test "create workflow with no definition yaml" do set_user_from_auth :active wf = { @@ -12,24 +16,36 @@ class WorkflowTest < ActiveSupport::TestCase assert_not_nil w.uuid end - test "create workflow with valid workflow yaml" do + test "create workflow with valid definition yaml" do set_user_from_auth :active wf = { name: "test name", - workflow: "k1:\n v1: x\n v2: y" + definition: "k1:\n v1: x\n v2: y" } w = Workflow.create!(wf) assert_not_nil w.uuid end - test "create workflow with invalid workflow yaml" do + test "create workflow with simple string as definition" do set_user_from_auth :active wf = { name: "test name", - workflow: "k1:\n v1: x\n v2: y" + definition: "this is valid yaml" + } + + w = Workflow.create!(wf) + assert_not_nil w.uuid + end + + test "create workflow with invalid definition yaml" do + set_user_from_auth :active + + wf = { + name: "test name", + definition: "k1:\n v1: x\n v2: y" } assert_raises(ActiveRecord::RecordInvalid) do @@ -37,52 +53,76 @@ class WorkflowTest < ActiveSupport::TestCase end end - test "update workflow with invalid workflow yaml" do + test "update workflow with invalid definition yaml" do set_user_from_auth :active - w = Workflow.find_by_uuid(workflows(:workflow_with_workflow_yml).uuid) - wf = "k1:\n v1: x\n v2: y" + w = Workflow.find_by_uuid(workflows(:workflow_with_definition_yml).uuid) + definition = "k1:\n v1: x\n v2: y" assert_raises(ActiveRecord::RecordInvalid) do - w.update_attributes!(workflow: wf) + w.update_attributes!(definition: definition) end end test "update workflow and verify name and description" do set_user_from_auth :active - # Workflow name and desc should be set with values from workflow yaml + # Workflow name and desc should be set with values from definition yaml # when it does not already have custom values for these fields w = Workflow.find_by_uuid(workflows(:workflow_with_no_name_and_desc).uuid) - wf = "name: test name 1\ndescription: test desc 1\nother: some more" - w.update_attributes!(workflow: wf) + definition = "name: test name 1\ndescription: test desc 1\nother: some more" + w.update_attributes!(definition: definition) + w.reload assert_equal "test name 1", w.name assert_equal "test desc 1", w.description - # Workflow name and desc should be set with values from workflow yaml + # Workflow name and desc should be set with values from definition yaml # when it does not already have custom values for these fields - wf = "name: test name 2\ndescription: test desc 2\nother: some more" - w.update_attributes!(workflow: wf) + definition = "name: test name 2\ndescription: test desc 2\nother: some more" + w.update_attributes!(definition: definition) + w.reload assert_equal "test name 2", w.name assert_equal "test desc 2", w.description - # Workflow name and desc should be set with values from workflow yaml + # Workflow name and desc should be set with values from definition yaml # even if it means emptying them out - wf = "more: etc" - w.update_attributes!(workflow: wf) - assert_equal nil, w.name - assert_equal nil, w.description + definition = "more: etc" + w.update_attributes!(definition: definition) + w.reload + assert_nil w.name + assert_nil w.description + + # Workflow name and desc set using definition yaml should be cleared + # if definition yaml is cleared + definition = "name: test name 2\ndescription: test desc 2\nother: some more" + w.update_attributes!(definition: definition) + w.reload + definition = nil + w.update_attributes!(definition: definition) + w.reload + assert_nil w.name + assert_nil w.description # Workflow name and desc should be set to provided custom values - wf = "name: test name 3\ndescription: test desc 3\nother: some more" - w.update_attributes!(name: "remains", description: "remains", workflow: wf) + definition = "name: test name 3\ndescription: test desc 3\nother: some more" + w.update_attributes!(name: "remains", description: "remains", definition: definition) + w.reload assert_equal "remains", w.name assert_equal "remains", w.description # Workflow name and desc should retain provided custom values # and should not be overwritten by values from yaml - wf = "name: test name 4\ndescription: test desc 4\nother: some more" - w.update_attributes!(workflow: wf) + definition = "name: test name 4\ndescription: test desc 4\nother: some more" + w.update_attributes!(definition: definition) + w.reload + assert_equal "remains", w.name + assert_equal "remains", w.description + + # Workflow name and desc should retain provided custom values + # and not be affected by the clearing of the definition yaml + definition = nil + w.update_attributes!(definition: definition) + w.reload assert_equal "remains", w.name assert_equal "remains", w.description end