From 73ccc51c3ffeaf985609de63fadbaff86721c882 Mon Sep 17 00:00:00 2001 From: Marco Donadoni Date: Mon, 13 Nov 2023 15:27:12 +0100 Subject: [PATCH] cli: fix download when workflow does not have outputs Closes #147 --- cmd/download.go | 9 +++-- cmd/download_test.go | 11 ++++- ...orkflow_specification_without_outputs.json | 40 +++++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 testdata/inputs/workflow_specification_without_outputs.json diff --git a/cmd/download.go b/cmd/download.go index 05c1611..6bc9ef0 100644 --- a/cmd/download.go +++ b/cmd/download.go @@ -1,6 +1,6 @@ /* This file is part of REANA. -Copyright (C) 2022 CERN. +Copyright (C) 2022, 2023 CERN. REANA is free software; you can redistribute it and/or modify it under the terms of the MIT License; see LICENSE file for more details. @@ -95,9 +95,10 @@ func (o *downloadOptions) run(cmd *cobra.Command, args []string) error { if err != nil { return err } - downloadFiles := spec.Specification.Outputs.Files - downloadDirs := spec.Specification.Outputs.Directories - downloadPaths = append(downloadFiles, downloadDirs...) + if outputs := spec.Specification.Outputs; outputs != nil { + downloadPaths = append(downloadPaths, outputs.Files...) + downloadPaths = append(downloadPaths, outputs.Directories...) + } } log.Debugf("Download paths: %s", strings.Join(downloadPaths, ", ")) diff --git a/cmd/download_test.go b/cmd/download_test.go index caedd3b..4bb1bc9 100644 --- a/cmd/download_test.go +++ b/cmd/download_test.go @@ -1,6 +1,6 @@ /* This file is part of REANA. -Copyright (C) 2022 CERN. +Copyright (C) 2022, 2023 CERN. REANA is free software; you can redistribute it and/or modify it under the terms of the MIT License; see LICENSE file for more details. @@ -45,6 +45,15 @@ func TestFileDownload(t *testing.T) { fmt.Sprintf("%s was successfully downloaded.", fileName), }, }, + "download from workflow without outputs": { + serverResponses: map[string]ServerResponse{ + fmt.Sprintf(downloadWorkflowSpecServerPath, "my_workflow"): { + statusCode: http.StatusOK, + responseFile: "workflow_specification_without_outputs.json", + }, + }, + args: []string{"-w", "my_workflow"}, + }, "download file specified as argument": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(downloadServerPath, "my_workflow", fileName): { diff --git a/testdata/inputs/workflow_specification_without_outputs.json b/testdata/inputs/workflow_specification_without_outputs.json new file mode 100644 index 0000000..34a47e8 --- /dev/null +++ b/testdata/inputs/workflow_specification_without_outputs.json @@ -0,0 +1,40 @@ +{ + "parameters": {}, + "specification": { + "inputs": { + "files": [ + "code/gendata.C", + "code/fitdata.C" + ], + "parameters": { + "data": "results/data.root", + "events": 20000, + "plot": "results/plot.png" + } + }, + "version": "0.6.0", + "workflow": { + "specification": { + "steps": [ + { + "commands": [ + "mkdir -p results && root -b -q 'code/gendata.C(${events},\"${data}\")'" + ], + "environment": "reanahub/reana-env-root6:6.18.04", + "kubernetes_memory_limit": "256Mi", + "name": "gendata" + }, + { + "commands": [ + "root -b -q 'code/fitdata.C(\"${data}\",\"${plot}\")'" + ], + "environment": "reanahub/reana-env-root6:6.18.04", + "kubernetes_memory_limit": "256Mi", + "name": "fitdata" + } + ] + }, + "type": "serial" + } + } +} \ No newline at end of file