diff --git a/cmd/close_test.go b/cmd/close_test.go index 05e7f21..fec6f81 100644 --- a/cmd/close_test.go +++ b/cmd/close_test.go @@ -21,8 +21,8 @@ func TestClose(t *testing.T) { "success": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(closePathTemplate, "my_workflow"): { - statusCode: http.StatusOK, - body: "{}", + statusCode: http.StatusOK, + responseFile: "common_empty.json", }, }, args: []string{"-w", "my_workflow"}, @@ -33,8 +33,8 @@ func TestClose(t *testing.T) { "error": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(closePathTemplate, "my_workflow"): { - statusCode: http.StatusNotFound, - body: `{"message": "Workflow - my_workflow has no open interactive session."}`, + statusCode: http.StatusNotFound, + responseFile: "close_no_open.json", }, }, args: []string{"-w", "my_workflow"}, diff --git a/cmd/delete_test.go b/cmd/delete_test.go index 24400ed..901b4b5 100644 --- a/cmd/delete_test.go +++ b/cmd/delete_test.go @@ -17,21 +17,14 @@ import ( var deletePathTemplate = "/api/workflows/%s/status" func TestDelete(t *testing.T) { - successResponse := `{ - "message": "Workflow successfully deleted", - "status": "deleted", - "user": "user", - "workflow_id": "my_workflow_id", - "workflow_name": "my_workflow" - }` workflowName := "my_workflow" tests := map[string]TestCmdParams{ "default": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(deletePathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "delete_success.json", }, }, args: []string{"-w", workflowName}, @@ -42,8 +35,8 @@ func TestDelete(t *testing.T) { "include workspace": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(deletePathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "delete_success.json", }, }, args: []string{"-w", workflowName, "--include-workspace"}, @@ -54,8 +47,8 @@ func TestDelete(t *testing.T) { "include all runs": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(deletePathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "delete_success.json", }, }, args: []string{"-w", workflowName, "--include-all-runs"}, @@ -66,8 +59,8 @@ func TestDelete(t *testing.T) { "include all runs complete name": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(deletePathTemplate, "my_workflow.10"): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "delete_success.json", }, }, args: []string{"-w", "my_workflow.10", "--include-all-runs"}, diff --git a/cmd/diff_test.go b/cmd/diff_test.go index 985410a..75d20a8 100644 --- a/cmd/diff_test.go +++ b/cmd/diff_test.go @@ -24,38 +24,13 @@ var diffPathTemplate = "/api/workflows/%s/diff/%s" func TestDiff(t *testing.T) { workflowA := "my_workflow_a" workflowB := "my_workflow_b" - diffResponse := `{ - "reana_specification":` + `"{` + - `\"version\": [\"@@ -1 +1 @@\", \"- v0.1\", \"+ v0.2\"],` + - `\"inputs\": [\"@@ -1 +2 @@\", \"- removed input\", \"+ added input\", \"+ more input\"],` + - `\"outputs\": [\"@@ -2 +1 @@\", \"- removed output\", \"- more output\", \"+ added output\"],` + - `\"workflow\": [\"@@ +1 @@\", \"+ added specs\"]` + - `}"` + `, - "workspace_listing": "\"Only in my_workflow_a: test.yaml\"" - }` - sameSpecResponse := `{ - "reana_specification":` + `"{` + - `\"version\": [],\"inputs\": [],\"outputs\": [],\"specification\": []` + - `}"` + `, - "workspace_listing": "\"Only in my_workflow_a: test.yaml\"" - }` - noSpecResponse := `{ - "reana_specification": "", - "workspace_listing": "\"Only in my_workflow_a: test.yaml\"" - }` - noWorkspaceResponse := `{ - "reana_specification":` + `"{` + - `\"version\": [],\"inputs\": [],\"outputs\": [],\"specification\": []` + - `}"` + `, - "workspace_listing": "\"\"" - }` tests := map[string]TestCmdParams{ "all info": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(diffPathTemplate, workflowA, workflowB): { - statusCode: http.StatusOK, - body: diffResponse, + statusCode: http.StatusOK, + responseFile: "diff_complete.json", }, }, args: []string{workflowA, workflowB}, @@ -70,8 +45,8 @@ func TestDiff(t *testing.T) { "same specification": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(diffPathTemplate, workflowA, workflowB): { - statusCode: http.StatusOK, - body: sameSpecResponse, + statusCode: http.StatusOK, + responseFile: "diff_same_spec.json", }, }, args: []string{workflowA, workflowB}, @@ -87,8 +62,8 @@ func TestDiff(t *testing.T) { "no specification info": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(diffPathTemplate, workflowA, workflowB): { - statusCode: http.StatusOK, - body: noSpecResponse, + statusCode: http.StatusOK, + responseFile: "diff_no_spec.json", }, }, args: []string{workflowA, workflowB}, @@ -104,8 +79,8 @@ func TestDiff(t *testing.T) { "no workspace info": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(diffPathTemplate, workflowA, workflowB): { - statusCode: http.StatusOK, - body: noWorkspaceResponse, + statusCode: http.StatusOK, + responseFile: "diff_no_workspace.json", }, }, args: []string{workflowA, workflowB}, @@ -119,12 +94,12 @@ func TestDiff(t *testing.T) { "unexisting workflow": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(diffPathTemplate, workflowA, workflowB): { - statusCode: http.StatusNotFound, - body: `{"message": "Workflow my_workflow_a does not exist."}`, + statusCode: http.StatusNotFound, + responseFile: "common_invalid_workflow.json", }, }, args: []string{workflowA, workflowB}, - expected: []string{"Workflow my_workflow_a does not exist."}, + expected: []string{"REANA_WORKON is set to invalid, but that workflow does not exist."}, wantError: true, }, "invalid number of arguments": { diff --git a/cmd/du_test.go b/cmd/du_test.go index 8e976c2..b1c4c04 100644 --- a/cmd/du_test.go +++ b/cmd/du_test.go @@ -18,33 +18,12 @@ var duPathTemplate = "/api/workflows/%s/disk_usage" func TestDu(t *testing.T) { workflowName := "my_workflow" - successResponse := `{ - "disk_usage_info": [ - { - "name": "/code/fitdata.C", - "size": { - "human_readable": "2 KiB", - "raw": 2048 - } - }, - { - "name": "/code/gendata.C", - "size": { - "human_readable": "4.5 KiB", - "raw": 4608 - } - } - ], - "user": "user", - "workflow_id": "my_workflow_id", - "workflow_name": "my_workflow" - }` tests := map[string]TestCmdParams{ "default": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(duPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "du_regular_files.json", }, }, args: []string{"-w", workflowName}, @@ -57,20 +36,8 @@ func TestDu(t *testing.T) { "summarize": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(duPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: `{ - "disk_usage_info": [ - { - "size": { - "human_readable": "10 KiB", - "raw": 10240 - } - } - ], - "user": "user", - "workflow_id": "my_workflow_id", - "workflow_name": "my_workflow" - }`, + statusCode: http.StatusOK, + responseFile: "du_summarize.json", }, }, args: []string{"-w", workflowName, "-s"}, @@ -82,8 +49,8 @@ func TestDu(t *testing.T) { "human readable": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(duPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "du_regular_files.json", }, }, args: []string{"-w", workflowName, "-h"}, @@ -96,28 +63,8 @@ func TestDu(t *testing.T) { "files in black list": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(duPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: `{ - "disk_usage_info": [ - { - "name": ".git/test.C", - "size": { - "human_readable": "2 KiB", - "raw": 2048 - } - }, - { - "name": "/code/gendata.C", - "size": { - "human_readable": "4.5 KiB", - "raw": 4608 - } - } - ], - "user": "user", - "workflow_id": "my_workflow_id", - "workflow_name": "my_workflow" - }`, + statusCode: http.StatusOK, + responseFile: "du_ignored_files.json", }, }, args: []string{"-w", workflowName}, @@ -132,21 +79,8 @@ func TestDu(t *testing.T) { "with filters": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(duPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: `{ - "disk_usage_info": [ - { - "name": "/code/gendata.C", - "size": { - "human_readable": "4.5 KiB", - "raw": 2048 - } - } - ], - "user": "user", - "workflow_id": "my_workflow_id", - "workflow_name": "my_workflow" - }`, + statusCode: http.StatusOK, + responseFile: "du_filtered.json", }, }, args: []string{"-w", workflowName, "--filter", "name=./code/gendata.C,size=2048"}, @@ -165,13 +99,8 @@ func TestDu(t *testing.T) { "no matching files:": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(duPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: `{ - "disk_usage_info": [], - "user": "user", - "workflow_id": "my_workflow_id", - "workflow_name": "my_workflow" - }`, + statusCode: http.StatusOK, + responseFile: "du_no_files.json", }, }, args: []string{"-w", workflowName, "--filter", "name=nothing.C"}, @@ -181,13 +110,13 @@ func TestDu(t *testing.T) { "unexisting workflow": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(duPathTemplate, "invalid"): { - statusCode: http.StatusNotFound, - body: `{"message": "REANA_WORKON is set to invalid, but that workflow does not exist."}`, + statusCode: http.StatusNotFound, + responseFile: "common_invalid_workflow.json", }, }, args: []string{"-w", "invalid"}, expected: []string{ - "REANA_WORKON is set to invalid, but that workflow does not exist.", + "REANA_WORKON is set to invalid, but that workflow does not exist", }, wantError: true, }, diff --git a/cmd/info_test.go b/cmd/info_test.go index 5b5af7a..04e8be4 100644 --- a/cmd/info_test.go +++ b/cmd/info_test.go @@ -16,63 +16,12 @@ import ( var infoServerPath = "/api/info" func TestInfo(t *testing.T) { - successResponse := `{ - "compute_backends": { - "title": "List of supported compute backends", - "value": [ - "kubernetes", - "slurmcern" - ] - }, - "default_kubernetes_jobs_timeout": { - "title": "Default timeout for Kubernetes jobs", - "value": "124" - }, - "default_kubernetes_memory_limit": { - "title": "Default memory limit for Kubernetes jobs", - "value": "248" - }, - "default_workspace": { - "title": "Default workspace", - "value": "/var/reana" - }, - "kubernetes_max_memory_limit": { - "title": "Maximum allowed memory limit for Kubernetes jobs", - "value": "1000" - }, - "maximum_kubernetes_jobs_timeout": { - "title": "Maximum timeout for Kubernetes jobs", - "value": "500" - }, - "maximum_workspace_retention_period": { - "title": "Maximum retention period in days for workspace files", - "value": "250" - }, - "workspaces_available": { - "title": "List of available workspaces", - "value": [ - "/var/reana", - "/var/cern" - ] - } -} -` - minimalResponse := `{ - "kubernetes_max_memory_limit": { - "title": "Maximum allowed memory limit for Kubernetes jobs" - }, - "maximum_workspace_retention_period": { - "title": "Maximum retention period in days for workspace files" - } -} -` - tests := map[string]TestCmdParams{ "default": { serverResponses: map[string]ServerResponse{ infoServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "info_big.json", }, }, expected: []string{ @@ -89,8 +38,8 @@ func TestInfo(t *testing.T) { "json": { serverResponses: map[string]ServerResponse{ infoServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "info_big.json", }, }, args: []string{"--json"}, @@ -103,8 +52,8 @@ func TestInfo(t *testing.T) { "missing fields": { serverResponses: map[string]ServerResponse{ infoServerPath: { - statusCode: http.StatusOK, - body: minimalResponse, + statusCode: http.StatusOK, + responseFile: "info_small.json", }, }, expected: []string{ diff --git a/cmd/list_test.go b/cmd/list_test.go index 2f11dda..7305e3f 100644 --- a/cmd/list_test.go +++ b/cmd/list_test.go @@ -21,72 +21,12 @@ import ( var listServerPath = "/api/workflows" func TestList(t *testing.T) { - successResponse := `{ - "total": 2, - "items": [ - { - "created": "2022-07-28T12:04:37", - "id": "my_workflow_id", - "launcher_url": "https://test.test/url", - "name": "my_workflow.23", - "progress": { - "finished": { - "job_ids": ["job1", "job2"], - "total": 2 - }, - "total": { - "job_ids": [], - "total": 2 - }, - "run_finished_at": "2022-07-28T12:13:10", - "run_started_at": "2022-07-28T12:04:52" - }, - "size": { - "human_readable": "1 KiB", - "raw": 1024 - }, - "status": "finished", - "user": "user", - "session_status": "created", - "session_type": "jupyter", - "session_uri": "/session1uri" - }, - { - "created": "2022-08-10T17:14:12", - "id": "my_workflow2_id", - "launcher_url": "https://test.test/url2", - "name": "my_workflow2.12", - "progress": { - "finished": { - "job_ids": ["job3"], - "total": 1 - }, - "total": { - "job_ids": [], - "total": 2 - }, - "run_finished_at": null, - "run_started_at": "2022-08-10T18:04:52" - }, - "size": { - "human_readable": "", - "raw": -1 - }, - "status": "running", - "user": "user", - "session_status": "created", - "session_type": "jupyter", - "session_uri": "/session2uri" - } - ] - }` - tests := map[string]TestCmdParams{ "default": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, expected: []string{ @@ -103,8 +43,8 @@ func TestList(t *testing.T) { "interactive sessions": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, args: []string{"-s"}, @@ -121,8 +61,8 @@ func TestList(t *testing.T) { "format columns": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, args: []string{"--format", "name,status"}, @@ -140,8 +80,8 @@ func TestList(t *testing.T) { "format with filter": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, args: []string{"--format", "name=my_workflow,status"}, @@ -159,8 +99,8 @@ func TestList(t *testing.T) { "invalid format column": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, args: []string{"--format", "invalid"}, @@ -172,8 +112,8 @@ func TestList(t *testing.T) { "json": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, args: []string{"--json"}, @@ -200,8 +140,8 @@ func TestList(t *testing.T) { "verbose": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, args: []string{"-v"}, @@ -219,8 +159,8 @@ func TestList(t *testing.T) { "raw size": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, args: []string{"--include-workspace-size"}, @@ -230,8 +170,8 @@ func TestList(t *testing.T) { "human readable size": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, args: []string{"--include-workspace-size", "-h"}, @@ -241,8 +181,8 @@ func TestList(t *testing.T) { "include duration": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, args: []string{"--include-duration"}, @@ -255,8 +195,8 @@ func TestList(t *testing.T) { "include progress": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, args: []string{"--include-progress"}, @@ -269,8 +209,8 @@ func TestList(t *testing.T) { "sorted": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, args: []string{"--sort", "run_number"}, @@ -286,8 +226,8 @@ func TestList(t *testing.T) { "unexisting workflow": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusNotFound, - body: `{"message": "REANA_WORKON is set to invalid, but that workflow does not exist."}`, + statusCode: http.StatusNotFound, + responseFile: "common_invalid_workflow.json", }, }, args: []string{"-w", "invalid"}, @@ -299,8 +239,8 @@ func TestList(t *testing.T) { "invalid size": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusBadRequest, - body: `{"message": "Field 'size': Must be at least 1."}`, + statusCode: http.StatusBadRequest, + responseFile: "common_invalid_size.json", }, }, args: []string{"--size", "0"}, @@ -310,8 +250,8 @@ func TestList(t *testing.T) { "invalid sort columns": { serverResponses: map[string]ServerResponse{ listServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "list.json", }, }, args: []string{"--sort", "invalid"}, diff --git a/cmd/logs_test.go b/cmd/logs_test.go index 96c6fe4..3439610 100644 --- a/cmd/logs_test.go +++ b/cmd/logs_test.go @@ -9,10 +9,8 @@ under the terms of the MIT License; see LICENSE file for more details. package cmd import ( - "encoding/json" "fmt" "net/http" - "reanahub/reana-client-go/client/operations" "reanahub/reana-client-go/pkg/config" "reanahub/reana-client-go/pkg/filterer" "reflect" @@ -25,58 +23,12 @@ var logsPathTemplate = "/api/workflows/%s/logs" func TestLogs(t *testing.T) { workflowName := "my_workflow" - logsTemplate := `{ - "workflow_logs": "workflow logs", - "job_logs": { - "1": { - "workflow_uuid": "%s", - "job_name": "%s", - "compute_backend": "Kubernetes", - "backend_job_id": "backend1", - "docker_img": "docker1", - "cmd": "ls", - "status": "finished", - "logs": "%s", - "started_at": "2022-07-20T12:09:09", - "finished_at": "2022-07-20T19:09:09" - }, - "2": { - "workflow_uuid": "workflow_2", - "job_name": "job2", - "compute_backend": "Slurm", - "backend_job_id": "backend2", - "docker_img": "docker2", - "cmd": "cd folder", - "status": "running", - "logs": "workflow 2 logs", - "started_at": "2022-07-21T12:09:09", - "finished_at": "2022-07-21T19:09:09" - } - }, - "engine_specific": "engine logs" - }` - successResponseRaw, _ := json.Marshal(operations.GetWorkflowLogsOKBody{ - Logs: fmt.Sprintf(logsTemplate, "workflow_1", "job1", "workflow 1 logs"), - User: "user", - WorkflowID: "my_workflow_id", - WorkflowName: "my_workflow", - }) - successResponse := string(successResponseRaw) - - incompleteResponseRaw, _ := json.Marshal(operations.GetWorkflowLogsOKBody{ - Logs: fmt.Sprintf(logsTemplate, "", "", ""), - User: "user", - WorkflowID: "my_workflow_id", - WorkflowName: "my_workflow", - }) - incompleteResponse := string(incompleteResponseRaw) - tests := map[string]TestCmdParams{ "default": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(logsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "logs_complete.json", }, }, args: []string{"-w", workflowName}, @@ -93,13 +45,8 @@ func TestLogs(t *testing.T) { "without log information": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(logsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: `{ - "logs": "{}", - "user": "user", - "workflow_id": "my_workflow_id", - "workflow_name": "my_workflow" - }`, + statusCode: http.StatusOK, + responseFile: "logs_empty.json", }, }, args: []string{"-w", workflowName}, @@ -111,8 +58,8 @@ func TestLogs(t *testing.T) { "json": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(logsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "logs_complete.json", }, }, args: []string{"-w", workflowName, "--json"}, @@ -127,8 +74,8 @@ func TestLogs(t *testing.T) { "with filters": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(logsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "logs_complete.json", }, }, args: []string{"-w", workflowName, "--filter", "compute_backend=kubernetes"}, @@ -138,8 +85,8 @@ func TestLogs(t *testing.T) { "missing step names": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(logsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "logs_complete.json", }, }, args: []string{"-w", workflowName, "--filter", "step=3"}, @@ -150,8 +97,8 @@ func TestLogs(t *testing.T) { "missing fields": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(logsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: incompleteResponse, + statusCode: http.StatusOK, + responseFile: "logs_incomplete.json", }, }, args: []string{"-w", workflowName, "--filter", "compute_backend=kubernetes"}, @@ -172,8 +119,8 @@ func TestLogs(t *testing.T) { "unexisting workflow": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(logsPathTemplate, "invalid"): { - statusCode: http.StatusNotFound, - body: `{"message": "REANA_WORKON is set to invalid, but that workflow does not exist."}`, + statusCode: http.StatusNotFound, + responseFile: "common_invalid_workflow.json", }, }, args: []string{"-w", "invalid"}, @@ -185,8 +132,8 @@ func TestLogs(t *testing.T) { "invalid page": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(logsPathTemplate, workflowName): { - statusCode: http.StatusBadRequest, - body: `{"message": "Field 'page': Must be at least 1."}`, + statusCode: http.StatusBadRequest, + responseFile: "common_invalid_page.json", }, }, args: []string{"-w", workflowName, "--page", "0"}, diff --git a/cmd/ls_test.go b/cmd/ls_test.go index ab1d89c..890d750 100644 --- a/cmd/ls_test.go +++ b/cmd/ls_test.go @@ -20,33 +20,12 @@ var lsPathTemplate = "/api/workflows/%s/workspace" func TestLs(t *testing.T) { workflowName := "my_workflow" - successResponse := `{ - "items": [ - { - "last-modified": "2022-07-11T12:50:33", - "name": "code/gendata.C", - "size": { - "human_readable": "1.89 KiB", - "raw": 1937 - } - }, - { - "last-modified": "2022-07-11T13:30:17", - "name": "results/data.root", - "size": { - "human_readable": "150.83 KiB", - "raw": 154455 - } - } - ], - "total": 2 -}` tests := map[string]TestCmdParams{ "default": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(lsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "ls_complete.json", }, }, args: []string{"-w", workflowName}, @@ -59,8 +38,8 @@ func TestLs(t *testing.T) { "human readable": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(lsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "ls_complete.json", }, }, args: []string{"-w", workflowName, "-h"}, @@ -73,28 +52,8 @@ func TestLs(t *testing.T) { "files in black list": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(lsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: `{ - "items": [ - { - "last-modified": "2022-07-11T12:50:33", - "name": ".git/test.C", - "size": { - "human_readable": "1.89 KiB", - "raw": 1937 - } - }, - { - "last-modified": "2022-07-11T13:30:17", - "name": "results/data.root", - "size": { - "human_readable": "150.83 KiB", - "raw": 154455 - } - } - ], - "total": 4 - }`, + statusCode: http.StatusOK, + responseFile: "ls_ignored_files.json", }, }, args: []string{"-w", workflowName}, @@ -109,8 +68,8 @@ func TestLs(t *testing.T) { "format columns": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(lsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "ls_complete.json", }, }, args: []string{"-w", workflowName, "--format", "name,last-modified"}, @@ -126,8 +85,8 @@ func TestLs(t *testing.T) { "format with filters": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(lsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "ls_complete.json", }, }, args: []string{"-w", workflowName, "--format", "name=code/gendata.C"}, @@ -143,8 +102,8 @@ func TestLs(t *testing.T) { "invalid format column": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(lsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "ls_complete.json", }, }, args: []string{"-w", workflowName, "--format", "invalid"}, @@ -156,8 +115,8 @@ func TestLs(t *testing.T) { "json": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(lsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "ls_complete.json", }, }, args: []string{"-w", workflowName, "--json"}, @@ -177,8 +136,8 @@ func TestLs(t *testing.T) { "display URLs": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(lsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "ls_complete.json", }, }, args: []string{"-w", workflowName, "--url"}, @@ -190,20 +149,8 @@ func TestLs(t *testing.T) { "with filters": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(lsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: `{ - "items": [ - { - "last-modified": "2022-07-11T12:50:33", - "name": "code/gendata.C", - "size": { - "human_readable": "1.89 KiB", - "raw": 1937 - } - } - ], - "total": 4 - }`, + statusCode: http.StatusOK, + responseFile: "ls_filters.json", }, }, args: []string{"-w", workflowName, "--filter", "name=code/gendata.C"}, @@ -215,20 +162,8 @@ func TestLs(t *testing.T) { "filename arg": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(lsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: `{ - "items": [ - { - "last-modified": "2022-07-11T12:50:33", - "name": "code/gendata.C", - "size": { - "human_readable": "1.89 KiB", - "raw": 1937 - } - } - ], - "total": 4 - }`, + statusCode: http.StatusOK, + responseFile: "ls_filters.json", }, }, args: []string{"-w", workflowName, "code/gendata.C"}, @@ -247,8 +182,8 @@ func TestLs(t *testing.T) { "unexisting workflow": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(lsPathTemplate, "invalid"): { - statusCode: http.StatusNotFound, - body: `{"message": "REANA_WORKON is set to invalid, but that workflow does not exist."}`, + statusCode: http.StatusNotFound, + responseFile: "common_invalid_workflow.json", }, }, args: []string{"-w", "invalid"}, @@ -260,8 +195,8 @@ func TestLs(t *testing.T) { "invalid size": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(lsPathTemplate, workflowName): { - statusCode: http.StatusBadRequest, - body: `{"message": "Field 'size': Must be at least 1."}`, + statusCode: http.StatusBadRequest, + responseFile: "common_invalid_size.json", }, }, args: []string{"-w", workflowName, "--size", "0"}, diff --git a/cmd/mv_test.go b/cmd/mv_test.go index 6fa19fa..dc57d31 100644 --- a/cmd/mv_test.go +++ b/cmd/mv_test.go @@ -18,21 +18,12 @@ var movePathTemplate = "/api/workflows/move_files/%s" func TestMv(t *testing.T) { workflowName := "my_workflow" - successResponse := `{ - "message": "test", - "workflow_id": "my_workflow_id", - "workflow_name": "my_workflow" - }` - errorResponse := `{ - "message": "Path bad/ does not exists" - }` - tests := map[string]TestCmdParams{ "success": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(movePathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "mv_valid_path.json", }, }, args: []string{"-w", "my_workflow", "good/", "new/"}, @@ -43,8 +34,8 @@ func TestMv(t *testing.T) { "server error": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(movePathTemplate, workflowName): { - statusCode: http.StatusConflict, - body: errorResponse, + statusCode: http.StatusConflict, + responseFile: "mv_invalid_path.json", }, }, args: []string{"-w", "my_workflow", "bad/", "new/"}, diff --git a/cmd/open_test.go b/cmd/open_test.go index 5d44177..97a2c87 100644 --- a/cmd/open_test.go +++ b/cmd/open_test.go @@ -19,14 +19,13 @@ import ( var openPathTemplate = "/api/workflows/%s/open/%s" func TestOpen(t *testing.T) { - successResponse := `{"path": "/test/jupyter"}` workflowName := "my_workflow" tests := map[string]TestCmdParams{ "success default": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(openPathTemplate, workflowName, config.InteractiveSessionTypes[0]): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "open_jupyter.json", }, }, args: []string{"-w", workflowName}, @@ -39,8 +38,8 @@ func TestOpen(t *testing.T) { "success extra args": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(openPathTemplate, workflowName, "jupyter"): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "open_jupyter.json", }, }, args: []string{"-w", workflowName, "-i", "image", "jupyter"}, @@ -51,11 +50,6 @@ func TestOpen(t *testing.T) { }, }, "invalid session type": { - serverResponses: map[string]ServerResponse{ - fmt.Sprintf(openPathTemplate, workflowName, "invalid"): { - statusCode: http.StatusBadRequest, - }, - }, args: []string{"-w", workflowName, "invalid"}, expected: []string{ fmt.Sprintf( @@ -68,8 +62,8 @@ func TestOpen(t *testing.T) { "workflow already open": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(openPathTemplate, workflowName, "jupyter"): { - statusCode: http.StatusNotFound, - body: `{"message": "Interactive session is already open"}`, + statusCode: http.StatusNotFound, + responseFile: "open_already_open.json", }, }, args: []string{"-w", workflowName}, diff --git a/cmd/ping_test.go b/cmd/ping_test.go index d1946cc..56dbde5 100644 --- a/cmd/ping_test.go +++ b/cmd/ping_test.go @@ -15,11 +15,8 @@ func TestPing(t *testing.T) { cmd: "ping", serverResponses: map[string]ServerResponse{ pingServerPath: { - statusCode: http.StatusOK, - body: `{ - "email": "john.doe@example.org", - "reana_server_version": "0.9.0a5" - }`, + statusCode: http.StatusOK, + responseFile: "ping.json", }, }, expected: []string{ diff --git a/cmd/quota_show_test.go b/cmd/quota_show_test.go index 3523fde..4d78c8d 100644 --- a/cmd/quota_show_test.go +++ b/cmd/quota_show_test.go @@ -23,45 +23,12 @@ import ( var quotaShowServerPath = "/api/you" func TestQuotaShow(t *testing.T) { - successResponse := `{ - "quota": { - "cpu": { - "health": "healthy", - "usage": { - "human_readable": "1m 5s", - "raw": 10 - }, - "limit": { - "human_readable": "10m 50s", - "raw": 100 - } - }, - "disk": { - "health": "healthy", - "usage": { - "human_readable": "2 MiB", - "raw": 20 - }, - "limit": { - "human_readable": "20 MiB", - "raw": 200 - } - } - } - }` - noInfoResponse := `{ - "quota": { - "cpu": {}, - "disk": {} - } - }` - tests := map[string]TestCmdParams{ "show resources": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_complete.json", }, }, args: []string{"--resources"}, @@ -71,8 +38,8 @@ func TestQuotaShow(t *testing.T) { "cpu limit": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_complete.json", }, }, args: []string{"--resource", "cpu", "--report", "limit"}, @@ -82,8 +49,8 @@ func TestQuotaShow(t *testing.T) { "cpu usage": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_complete.json", }, }, args: []string{"--resource", "cpu", "--report", "usage"}, @@ -93,8 +60,8 @@ func TestQuotaShow(t *testing.T) { "cpu limit human": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_complete.json", }, }, args: []string{"--resource", "cpu", "--report", "limit", "-h"}, @@ -104,8 +71,8 @@ func TestQuotaShow(t *testing.T) { "cpu usage human": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_complete.json", }, }, args: []string{"--resource", "cpu", "--report", "usage", "-h"}, @@ -115,8 +82,8 @@ func TestQuotaShow(t *testing.T) { "cpu all reports": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_complete.json", }, }, args: []string{"--resource", "cpu"}, @@ -126,8 +93,8 @@ func TestQuotaShow(t *testing.T) { "cpu limit no info": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: noInfoResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_no_info.json", }, }, args: []string{"--resource", "cpu", "--report", "limit"}, @@ -137,8 +104,8 @@ func TestQuotaShow(t *testing.T) { "cpu usage no info": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: noInfoResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_no_info.json", }, }, args: []string{"--resource", "cpu", "--report", "usage"}, @@ -148,8 +115,8 @@ func TestQuotaShow(t *testing.T) { "cpu all reports no info": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: noInfoResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_no_info.json", }, }, args: []string{"--resource", "cpu"}, @@ -159,8 +126,8 @@ func TestQuotaShow(t *testing.T) { "disk limit": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_complete.json", }, }, args: []string{"--resource", "disk", "--report", "limit"}, @@ -170,8 +137,8 @@ func TestQuotaShow(t *testing.T) { "disk usage": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_complete.json", }, }, args: []string{"--resource", "disk", "--report", "usage"}, @@ -181,8 +148,8 @@ func TestQuotaShow(t *testing.T) { "disk limit human": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_complete.json", }, }, args: []string{"--resource", "disk", "--report", "limit", "-h"}, @@ -192,8 +159,8 @@ func TestQuotaShow(t *testing.T) { "disk usage human": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_complete.json", }, }, args: []string{"--resource", "disk", "--report", "usage", "-h"}, @@ -203,8 +170,8 @@ func TestQuotaShow(t *testing.T) { "disk all reports": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_complete.json", }, }, args: []string{"--resource", "disk"}, @@ -214,8 +181,8 @@ func TestQuotaShow(t *testing.T) { "disk limit no info": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: noInfoResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_no_info.json", }, }, args: []string{"--resource", "disk", "--report", "limit"}, @@ -225,8 +192,8 @@ func TestQuotaShow(t *testing.T) { "disk usage no info": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: noInfoResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_no_info.json", }, }, args: []string{"--resource", "disk", "--report", "usage"}, @@ -236,8 +203,8 @@ func TestQuotaShow(t *testing.T) { "disk all reports no info": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: noInfoResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_no_info.json", }, }, args: []string{"--resource", "disk"}, @@ -261,8 +228,8 @@ func TestQuotaShow(t *testing.T) { "invalid resource": { serverResponses: map[string]ServerResponse{ quotaShowServerPath: { - statusCode: http.StatusOK, - body: noInfoResponse, + statusCode: http.StatusOK, + responseFile: "quota_show_no_info.json", }, }, args: []string{"--resource", "invalid"}, diff --git a/cmd/rm_test.go b/cmd/rm_test.go index b60367a..70a3f40 100644 --- a/cmd/rm_test.go +++ b/cmd/rm_test.go @@ -18,32 +18,12 @@ var rmPathTemplate = "/api/workflows/%s/workspace/%s" func TestRm(t *testing.T) { workflowName := "my_workflow" - successResponse := `{ - "deleted": { - "files/one.py": {"size": 20}, - "files/two.py": {"size": 40} - }, - "failed": { - "files/three.py": {"error": "testing error in three.py"} - } - }` - emptyResponse := `{ - "deleted": {}, - "failed": {} - }` - noFreedResponse := `{ - "deleted": { - "files/empty.py": {"size": 0} - }, - "failed": {} - }` - tests := map[string]TestCmdParams{ "multiple files": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(rmPathTemplate, workflowName, "files/*"): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "rm_multiple_files.json", }, }, args: []string{"-w", workflowName, "files/*"}, @@ -59,8 +39,8 @@ func TestRm(t *testing.T) { "no space freed": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(rmPathTemplate, workflowName, "files/*"): { - statusCode: http.StatusOK, - body: noFreedResponse, + statusCode: http.StatusOK, + responseFile: "rm_no_freed.json", }, }, args: []string{"-w", workflowName, "files/*"}, @@ -75,8 +55,8 @@ func TestRm(t *testing.T) { "no matching files": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(rmPathTemplate, workflowName, "files/*"): { - statusCode: http.StatusOK, - body: emptyResponse, + statusCode: http.StatusOK, + responseFile: "rm_empty.json", }, }, args: []string{"-w", workflowName, "files/*"}, diff --git a/cmd/root_test.go b/cmd/root_test.go index 5c13789..a14915a 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -12,6 +12,7 @@ import ( "bytes" "net/http" "net/http/httptest" + "os" "reanahub/reana-client-go/pkg/errorhandler" "reanahub/reana-client-go/pkg/validator" "strings" @@ -47,8 +48,8 @@ type TestCmdParams struct { } type ServerResponse struct { - statusCode int - body string + statusCode int + responseFile string } func testCmdRun(t *testing.T, p TestCmdParams) { @@ -60,7 +61,16 @@ func testCmdRun(t *testing.T, p TestCmdParams) { if validPath { w.Header().Add("Content-Type", "application/json") w.WriteHeader(res.statusCode) - _, err := w.Write([]byte(res.body)) + + var body []byte + if res.responseFile != "" { + var err error + body, err = os.ReadFile("../testdata/inputs/" + res.responseFile) + if err != nil { + t.Fatalf("Error while reading response file: %v", err) + } + } + _, err := w.Write(body) if err != nil { t.Fatalf("Error while writing response body: %v", err) } diff --git a/cmd/secrets_add_test.go b/cmd/secrets_add_test.go index 67edd63..8a68150 100644 --- a/cmd/secrets_add_test.go +++ b/cmd/secrets_add_test.go @@ -32,8 +32,8 @@ func TestSecretsAdd(t *testing.T) { "valid secrets": { serverResponses: map[string]ServerResponse{ secretsAddServerPath: { - statusCode: http.StatusCreated, - body: `{"message": "OK"}`, + statusCode: http.StatusCreated, + responseFile: "common_empty.json", }, }, args: []string{"--env", "PASSWORD=password", "--file", emptyFile}, @@ -65,8 +65,8 @@ func TestSecretsAdd(t *testing.T) { "secret already exists": { serverResponses: map[string]ServerResponse{ secretsAddServerPath: { - statusCode: http.StatusConflict, - body: `{"message": "Operation cancelled. Secret PASSWORD already exists. If you want to change it use overwrite"}`, + statusCode: http.StatusConflict, + responseFile: "secrets_add_repeated.json", }, }, args: []string{"--env", "PASSWORD=password"}, diff --git a/cmd/secrets_delete_test.go b/cmd/secrets_delete_test.go index 2656b59..41d30dd 100644 --- a/cmd/secrets_delete_test.go +++ b/cmd/secrets_delete_test.go @@ -22,8 +22,8 @@ func TestSecretsDelete(t *testing.T) { "valid secrets": { serverResponses: map[string]ServerResponse{ secretsDeleteServerPath: { - statusCode: http.StatusOK, - body: `["secret1", "secret2"]`, + statusCode: http.StatusOK, + responseFile: "secrets_delete_multiple.json", }, }, args: []string{"secret1", "secret2"}, @@ -41,8 +41,8 @@ func TestSecretsDelete(t *testing.T) { "invalid secrets": { serverResponses: map[string]ServerResponse{ secretsDeleteServerPath: { - statusCode: http.StatusNotFound, - body: `["secret1", "secret2"]`, + statusCode: http.StatusNotFound, + responseFile: "secrets_delete_multiple.json", }, }, args: []string{"secret1", "secret2"}, @@ -54,8 +54,8 @@ func TestSecretsDelete(t *testing.T) { "valid and invalid secrets": { serverResponses: map[string]ServerResponse{ secretsDeleteServerPath: { - statusCode: http.StatusNotFound, - body: `["secret1"]`, + statusCode: http.StatusNotFound, + responseFile: "secrets_delete_not_found.json", }, }, args: []string{"secret1", "secret2"}, diff --git a/cmd/secrets_list_test.go b/cmd/secrets_list_test.go index e936ec1..48ec6a8 100644 --- a/cmd/secrets_list_test.go +++ b/cmd/secrets_list_test.go @@ -16,23 +16,12 @@ import ( var secretsListServerPath = "/api/secrets" func TestSecretsList(t *testing.T) { - successResponse := `[ - { - "name": "secret1", - "type": "env" - }, - { - "name": "secret2", - "type": "file" - } - ]` - tests := map[string]TestCmdParams{ "default": { serverResponses: map[string]ServerResponse{ secretsListServerPath: { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "secrets_list.json", }, }, expected: []string{ @@ -49,8 +38,8 @@ func TestSecretsList(t *testing.T) { "server error": { serverResponses: map[string]ServerResponse{ secretsListServerPath: { - statusCode: http.StatusInternalServerError, - body: `{"message": "Error while querying"}`, + statusCode: http.StatusInternalServerError, + responseFile: "common_internal_server_error.json", }, }, expected: []string{ diff --git a/cmd/start_test.go b/cmd/start_test.go index da3ac48..cab0108 100644 --- a/cmd/start_test.go +++ b/cmd/start_test.go @@ -27,57 +27,12 @@ func TestStart(t *testing.T) { }) workflowName := "my_workflow" - startResponse := `{ - "message": "Workflow successfully started", - "status": "running", - "user": "user", - "workflow_id": "my_workflow_id", - "workflow_name": "my_workflow" - }` - paramsResponse := `{ - "id": "my_workflow_id", - "name": "my_workflow", - "type": "serial", - "parameters": { - "data": "results/data.root", - "events": 20, - "plot": "results/plot.png" - } - }` - statusFinishedResponse := `{ - "status": "finished", - "user": "user", - "workflow_id": "my_workflow_id", - "workflow_name": "my_workflow", - "created": "2022-07-20T12:08:40" - }` - statusStoppedResponse := `{ - "status": "stopped", - "user": "user", - "workflow_id": "my_workflow_id", - "workflow_name": "my_workflow", - "created": "2022-07-20T12:08:40" - }` - lsResponse := `{ - "items": [ - { - "last-modified": "2022-07-11T12:50:33", - "name": "code/gendata.C", - "size": { - "human_readable": "1.89 KiB", - "raw": 1937 - } - } - ], - "total": 1 -}` - tests := map[string]TestCmdParams{ "default": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(startPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: startResponse, + statusCode: http.StatusOK, + responseFile: "start_success.json", }, }, args: []string{"-w", workflowName}, @@ -88,12 +43,12 @@ func TestStart(t *testing.T) { "valid options": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(startPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: startResponse, + statusCode: http.StatusOK, + responseFile: "start_success.json", }, fmt.Sprintf(paramsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: paramsResponse, + statusCode: http.StatusOK, + responseFile: "param_multiple.json", }, }, args: []string{"-w", workflowName, "-o", "CACHE=cache,FROM=from"}, @@ -104,12 +59,12 @@ func TestStart(t *testing.T) { "valid parameters": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(startPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: startResponse, + statusCode: http.StatusOK, + responseFile: "start_success.json", }, fmt.Sprintf(paramsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: paramsResponse, + statusCode: http.StatusOK, + responseFile: "param_multiple.json", }, }, args: []string{"-w", workflowName, "-p", "data=results/data2.root,events=100"}, @@ -120,12 +75,12 @@ func TestStart(t *testing.T) { "unsupported option": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(startPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: startResponse, + statusCode: http.StatusOK, + responseFile: "start_success.json", }, fmt.Sprintf(paramsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: paramsResponse, + statusCode: http.StatusOK, + responseFile: "param_multiple.json", }, }, args: []string{"-w", workflowName, "-o", "CACHE=cache,INVALID=invalid"}, @@ -137,12 +92,12 @@ func TestStart(t *testing.T) { "option not supported for workflow type": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(startPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: startResponse, + statusCode: http.StatusOK, + responseFile: "start_success.json", }, fmt.Sprintf(paramsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: paramsResponse, + statusCode: http.StatusOK, + responseFile: "param_multiple.json", }, }, args: []string{"-w", workflowName, "-o", "CACHE=cache,report=report"}, @@ -154,12 +109,12 @@ func TestStart(t *testing.T) { "parameter not specified": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(startPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: startResponse, + statusCode: http.StatusOK, + responseFile: "start_success.json", }, fmt.Sprintf(paramsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: paramsResponse, + statusCode: http.StatusOK, + responseFile: "param_multiple.json", }, }, args: []string{"-w", workflowName, "-p", "data=results/data2.root,invalid=100"}, @@ -171,19 +126,12 @@ func TestStart(t *testing.T) { "validated options and parameters": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(startPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: startResponse, + statusCode: http.StatusOK, + responseFile: "start_success.json", }, fmt.Sprintf(paramsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: `{ - "id": "my_workflow_id", - "name": "my_workflow", - "type": "cwl", - "parameters": { - "data": "results/data.root" - } - }`, + statusCode: http.StatusOK, + responseFile: "params_only_data.json", }, }, args: []string{ @@ -199,8 +147,8 @@ func TestStart(t *testing.T) { "workflow already finished": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(startPathTemplate, workflowName): { - statusCode: http.StatusForbidden, - body: `{"message": "Workflow my_workflow is already finished and cannot be started again."}`, + statusCode: http.StatusForbidden, + responseFile: "start_already_finished.json", }, }, args: []string{"-w", workflowName}, @@ -212,12 +160,12 @@ func TestStart(t *testing.T) { "follow stopped": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(startPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: startResponse, + statusCode: http.StatusOK, + responseFile: "start_success.json", }, fmt.Sprintf(statusPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: statusStoppedResponse, + statusCode: http.StatusOK, + responseFile: "status_stopped.json", }, }, args: []string{"-w", workflowName, "--follow"}, @@ -229,16 +177,16 @@ func TestStart(t *testing.T) { "follow finished": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(startPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: startResponse, + statusCode: http.StatusOK, + responseFile: "start_success.json", }, fmt.Sprintf(statusPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: statusFinishedResponse, + statusCode: http.StatusOK, + responseFile: "status_finished.json", }, fmt.Sprintf(lsPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: lsResponse, + statusCode: http.StatusOK, + responseFile: "ls_complete.json", }, }, args: []string{"-w", workflowName, "--follow"}, @@ -247,6 +195,7 @@ func TestStart(t *testing.T) { "my_workflow has been finished", "Listing workflow output files...", "/api/workflows/my_workflow/workspace/code/gendata.C", + "/api/workflows/my_workflow/workspace/results/data.root", }, }, } diff --git a/cmd/status_test.go b/cmd/status_test.go index e4d6f57..7258a91 100644 --- a/cmd/status_test.go +++ b/cmd/status_test.go @@ -23,42 +23,12 @@ var statusPathTemplate = "/api/workflows/%s/status" func TestStatus(t *testing.T) { workflowName := "my_workflow" - successResponse := `{ - "created": "2022-07-20T12:08:40", - "id": "my_workflow_id", - "name": "my_workflow.10", - "status": "finished", - "user": "user", - "logs": "logs", - "progress": { - "current_command": "ls", - "current_step_name": "step_name", - "failed": { - "job_ids": [], - "total": 0 - }, - "finished": { - "job_ids": ["job1", "job2"], - "total": 2 - }, - "run_finished_at": "2022-07-20T12:09:24", - "run_started_at": "2022-07-20T12:09:09", - "running": { - "job_ids": ["job3", "job4"], - "total": 2 - }, - "total": { - "job_ids": [], - "total": 2 - } - } - }` tests := map[string]TestCmdParams{ "default": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(statusPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "status_finished.json", }, }, args: []string{"-w", workflowName}, @@ -72,8 +42,8 @@ func TestStatus(t *testing.T) { "format columns": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(statusPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "status_finished.json", }, }, args: []string{"-w", workflowName, "--format", "name,progress"}, @@ -90,8 +60,8 @@ func TestStatus(t *testing.T) { "invalid format column": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(statusPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "status_finished.json", }, }, args: []string{"-w", workflowName, "--format", "invalid"}, @@ -103,8 +73,8 @@ func TestStatus(t *testing.T) { "json": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(statusPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "status_finished.json", }, }, args: []string{"-w", workflowName, "--json"}, @@ -124,8 +94,8 @@ func TestStatus(t *testing.T) { "verbose": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(statusPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "status_finished.json", }, }, args: []string{"-w", workflowName, "-v"}, @@ -140,8 +110,8 @@ func TestStatus(t *testing.T) { "include duration": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(statusPathTemplate, workflowName): { - statusCode: http.StatusOK, - body: successResponse, + statusCode: http.StatusOK, + responseFile: "status_finished.json", }, }, args: []string{"-w", workflowName, "--include-duration"}, @@ -159,8 +129,8 @@ func TestStatus(t *testing.T) { "unexisting workflow": { serverResponses: map[string]ServerResponse{ fmt.Sprintf(statusPathTemplate, "invalid"): { - statusCode: http.StatusNotFound, - body: `{"message": "REANA_WORKON is set to invalid, but that workflow does not exist."}`, + statusCode: http.StatusNotFound, + responseFile: "common_invalid_workflow.json", }, }, args: []string{"-w", "invalid"}, diff --git a/testdata/inputs/close_no_open.json b/testdata/inputs/close_no_open.json new file mode 100644 index 0000000..9c092d8 --- /dev/null +++ b/testdata/inputs/close_no_open.json @@ -0,0 +1,3 @@ +{ + "message": "Workflow - my_workflow has no open interactive session." +} \ No newline at end of file diff --git a/testdata/inputs/common_empty.json b/testdata/inputs/common_empty.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/testdata/inputs/common_empty.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/testdata/inputs/common_internal_server_error.json b/testdata/inputs/common_internal_server_error.json new file mode 100644 index 0000000..7542c28 --- /dev/null +++ b/testdata/inputs/common_internal_server_error.json @@ -0,0 +1,3 @@ +{ + "message": "Error while querying" +} \ No newline at end of file diff --git a/testdata/inputs/common_invalid_page.json b/testdata/inputs/common_invalid_page.json new file mode 100644 index 0000000..ba0284f --- /dev/null +++ b/testdata/inputs/common_invalid_page.json @@ -0,0 +1,3 @@ +{ + "message": "Field 'page': Must be at least 1." +} \ No newline at end of file diff --git a/testdata/inputs/common_invalid_size.json b/testdata/inputs/common_invalid_size.json new file mode 100644 index 0000000..af26c51 --- /dev/null +++ b/testdata/inputs/common_invalid_size.json @@ -0,0 +1,3 @@ +{ + "message": "Field 'size': Must be at least 1." +} \ No newline at end of file diff --git a/testdata/inputs/common_invalid_workflow.json b/testdata/inputs/common_invalid_workflow.json new file mode 100644 index 0000000..c74f9ed --- /dev/null +++ b/testdata/inputs/common_invalid_workflow.json @@ -0,0 +1,3 @@ +{ + "message": "REANA_WORKON is set to invalid, but that workflow does not exist." +} \ No newline at end of file diff --git a/testdata/inputs/delete_success.json b/testdata/inputs/delete_success.json new file mode 100644 index 0000000..47c935a --- /dev/null +++ b/testdata/inputs/delete_success.json @@ -0,0 +1,7 @@ +{ + "message": "Workflow successfully deleted", + "status": "deleted", + "user": "user", + "workflow_id": "my_workflow_id", + "workflow_name": "my_workflow" +} \ No newline at end of file diff --git a/testdata/inputs/diff_complete.json b/testdata/inputs/diff_complete.json new file mode 100644 index 0000000..357c05f --- /dev/null +++ b/testdata/inputs/diff_complete.json @@ -0,0 +1,4 @@ +{ + "reana_specification": "{\"version\": [\"@@ -1 +1 @@\", \"- v0.1\", \"+ v0.2\"],\"inputs\": [\"@@ -1 +2 @@\", \"- removed input\", \"+ added input\", \"+ more input\"],\"outputs\": [\"@@ -2 +1 @@\", \"- removed output\", \"- more output\", \"+ added output\"],\"workflow\": [\"@@ +1 @@\", \"+ added specs\"]}", + "workspace_listing": "\"Only in my_workflow_a: test.yaml\"" +} \ No newline at end of file diff --git a/testdata/inputs/diff_no_spec.json b/testdata/inputs/diff_no_spec.json new file mode 100644 index 0000000..3fcc23f --- /dev/null +++ b/testdata/inputs/diff_no_spec.json @@ -0,0 +1,4 @@ +{ + "reana_specification": "", + "workspace_listing": "\"Only in my_workflow_a: test.yaml\"" +} \ No newline at end of file diff --git a/testdata/inputs/diff_no_workspace.json b/testdata/inputs/diff_no_workspace.json new file mode 100644 index 0000000..e31c041 --- /dev/null +++ b/testdata/inputs/diff_no_workspace.json @@ -0,0 +1,4 @@ +{ + "reana_specification": "{\"version\": [],\"inputs\": [],\"outputs\": [],\"specification\": []}", + "workspace_listing": "\"\"" +} \ No newline at end of file diff --git a/testdata/inputs/diff_same_spec.json b/testdata/inputs/diff_same_spec.json new file mode 100644 index 0000000..5793c49 --- /dev/null +++ b/testdata/inputs/diff_same_spec.json @@ -0,0 +1,4 @@ +{ + "reana_specification": "{\"version\": [],\"inputs\": [],\"outputs\": [],\"specification\": []}", + "workspace_listing": "\"Only in my_workflow_a: test.yaml\"" +} \ No newline at end of file diff --git a/testdata/inputs/du_filtered.json b/testdata/inputs/du_filtered.json new file mode 100644 index 0000000..26865bd --- /dev/null +++ b/testdata/inputs/du_filtered.json @@ -0,0 +1,14 @@ +{ + "disk_usage_info": [ + { + "name": "/code/gendata.C", + "size": { + "human_readable": "4.5 KiB", + "raw": 2048 + } + } + ], + "user": "user", + "workflow_id": "my_workflow_id", + "workflow_name": "my_workflow" +} \ No newline at end of file diff --git a/testdata/inputs/du_ignored_files.json b/testdata/inputs/du_ignored_files.json new file mode 100644 index 0000000..3f6fbd9 --- /dev/null +++ b/testdata/inputs/du_ignored_files.json @@ -0,0 +1,21 @@ +{ + "disk_usage_info": [ + { + "name": ".git/test.C", + "size": { + "human_readable": "2 KiB", + "raw": 2048 + } + }, + { + "name": "/code/gendata.C", + "size": { + "human_readable": "4.5 KiB", + "raw": 4608 + } + } + ], + "user": "user", + "workflow_id": "my_workflow_id", + "workflow_name": "my_workflow" +} \ No newline at end of file diff --git a/testdata/inputs/du_no_files.json b/testdata/inputs/du_no_files.json new file mode 100644 index 0000000..1ae11ff --- /dev/null +++ b/testdata/inputs/du_no_files.json @@ -0,0 +1,6 @@ +{ + "disk_usage_info": [], + "user": "user", + "workflow_id": "my_workflow_id", + "workflow_name": "my_workflow" +} \ No newline at end of file diff --git a/testdata/inputs/du_regular_files.json b/testdata/inputs/du_regular_files.json new file mode 100644 index 0000000..a7d1993 --- /dev/null +++ b/testdata/inputs/du_regular_files.json @@ -0,0 +1,21 @@ +{ + "disk_usage_info": [ + { + "name": "/code/fitdata.C", + "size": { + "human_readable": "2 KiB", + "raw": 2048 + } + }, + { + "name": "/code/gendata.C", + "size": { + "human_readable": "4.5 KiB", + "raw": 4608 + } + } + ], + "user": "user", + "workflow_id": "my_workflow_id", + "workflow_name": "my_workflow" +} \ No newline at end of file diff --git a/testdata/inputs/du_summarize.json b/testdata/inputs/du_summarize.json new file mode 100644 index 0000000..65384c8 --- /dev/null +++ b/testdata/inputs/du_summarize.json @@ -0,0 +1,13 @@ +{ + "disk_usage_info": [ + { + "size": { + "human_readable": "10 KiB", + "raw": 10240 + } + } + ], + "user": "user", + "workflow_id": "my_workflow_id", + "workflow_name": "my_workflow" +} \ No newline at end of file diff --git a/testdata/inputs/info_big.json b/testdata/inputs/info_big.json new file mode 100644 index 0000000..da62788 --- /dev/null +++ b/testdata/inputs/info_big.json @@ -0,0 +1,40 @@ +{ + "compute_backends": { + "title": "List of supported compute backends", + "value": [ + "kubernetes", + "slurmcern" + ] + }, + "default_kubernetes_jobs_timeout": { + "title": "Default timeout for Kubernetes jobs", + "value": "124" + }, + "default_kubernetes_memory_limit": { + "title": "Default memory limit for Kubernetes jobs", + "value": "248" + }, + "default_workspace": { + "title": "Default workspace", + "value": "/var/reana" + }, + "kubernetes_max_memory_limit": { + "title": "Maximum allowed memory limit for Kubernetes jobs", + "value": "1000" + }, + "maximum_kubernetes_jobs_timeout": { + "title": "Maximum timeout for Kubernetes jobs", + "value": "500" + }, + "maximum_workspace_retention_period": { + "title": "Maximum retention period in days for workspace files", + "value": "250" + }, + "workspaces_available": { + "title": "List of available workspaces", + "value": [ + "/var/reana", + "/var/cern" + ] + } +} \ No newline at end of file diff --git a/testdata/inputs/info_small.json b/testdata/inputs/info_small.json new file mode 100644 index 0000000..b8c65e9 --- /dev/null +++ b/testdata/inputs/info_small.json @@ -0,0 +1,8 @@ +{ + "kubernetes_max_memory_limit": { + "title": "Maximum allowed memory limit for Kubernetes jobs" + }, + "maximum_workspace_retention_period": { + "title": "Maximum retention period in days for workspace files" + } +} \ No newline at end of file diff --git a/testdata/inputs/list.json b/testdata/inputs/list.json new file mode 100644 index 0000000..2735495 --- /dev/null +++ b/testdata/inputs/list.json @@ -0,0 +1,59 @@ +{ + "total": 2, + "items": [ + { + "created": "2022-07-28T12:04:37", + "id": "my_workflow_id", + "launcher_url": "https://test.test/url", + "name": "my_workflow.23", + "progress": { + "finished": { + "job_ids": ["job1", "job2"], + "total": 2 + }, + "total": { + "job_ids": [], + "total": 2 + }, + "run_finished_at": "2022-07-28T12:13:10", + "run_started_at": "2022-07-28T12:04:52" + }, + "size": { + "human_readable": "1 KiB", + "raw": 1024 + }, + "status": "finished", + "user": "user", + "session_status": "created", + "session_type": "jupyter", + "session_uri": "/session1uri" + }, + { + "created": "2022-08-10T17:14:12", + "id": "my_workflow2_id", + "launcher_url": "https://test.test/url2", + "name": "my_workflow2.12", + "progress": { + "finished": { + "job_ids": ["job3"], + "total": 1 + }, + "total": { + "job_ids": [], + "total": 2 + }, + "run_finished_at": null, + "run_started_at": "2022-08-10T18:04:52" + }, + "size": { + "human_readable": "", + "raw": -1 + }, + "status": "running", + "user": "user", + "session_status": "created", + "session_type": "jupyter", + "session_uri": "/session2uri" + } + ] +} \ No newline at end of file diff --git a/testdata/inputs/logs_complete.json b/testdata/inputs/logs_complete.json new file mode 100644 index 0000000..8b9559d --- /dev/null +++ b/testdata/inputs/logs_complete.json @@ -0,0 +1,6 @@ +{ + "logs": "{\"workflow_logs\": \"workflow logs\",\"job_logs\": {\"1\": {\"workflow_uuid\": \"workflow_1\",\"job_name\": \"job1\",\"compute_backend\": \"Kubernetes\",\"backend_job_id\": \"backend1\",\"docker_img\": \"docker1\",\"cmd\": \"ls\",\"status\": \"finished\",\"logs\": \"workflow 1 logs\",\"started_at\": \"2022-07-20T12:09:09\",\"finished_at\": \"2022-07-20T19:09:09\"},\"2\": {\"workflow_uuid\": \"workflow_2\",\"job_name\": \"job2\",\"compute_backend\": \"Slurm\",\"backend_job_id\": \"backend2\",\"docker_img\": \"docker2\",\"cmd\": \"cd folder\",\"status\": \"running\",\"logs\": \"workflow 2 logs\",\"started_at\": \"2022-07-21T12:09:09\",\"finished_at\": \"2022-07-21T19:09:09\"}},\"engine_specific\": \"engine logs\"}", + "user": "user", + "workflow_id": "my_workflow_id", + "workflow_name": "my_workflow" +} \ No newline at end of file diff --git a/testdata/inputs/logs_empty.json b/testdata/inputs/logs_empty.json new file mode 100644 index 0000000..e5857be --- /dev/null +++ b/testdata/inputs/logs_empty.json @@ -0,0 +1,6 @@ +{ + "logs": "{}", + "user": "user", + "workflow_id": "my_workflow_id", + "workflow_name": "my_workflow" +} \ No newline at end of file diff --git a/testdata/inputs/logs_incomplete.json b/testdata/inputs/logs_incomplete.json new file mode 100644 index 0000000..db516ab --- /dev/null +++ b/testdata/inputs/logs_incomplete.json @@ -0,0 +1,6 @@ +{ + "logs": "{\"workflow_logs\": \"workflow logs\",\"job_logs\": {\"1\": {\"compute_backend\": \"Kubernetes\",\"backend_job_id\": \"backend1\",\"docker_img\": \"docker1\",\"cmd\": \"ls\",\"status\": \"finished\",\"started_at\": \"2022-07-20T12:09:09\",\"finished_at\": \"2022-07-20T19:09:09\"},\"2\": {\"workflow_uuid\": \"workflow_2\",\"job_name\": \"job2\",\"compute_backend\": \"Slurm\",\"backend_job_id\": \"backend2\",\"docker_img\": \"docker2\",\"cmd\": \"cd folder\",\"status\": \"running\",\"logs\": \"workflow 2 logs\",\"started_at\": \"2022-07-21T12:09:09\",\"finished_at\": \"2022-07-21T19:09:09\"}},\"engine_specific\": \"engine logs\"}", + "user": "user", + "workflow_id": "my_workflow_id", + "workflow_name": "my_workflow" +} \ No newline at end of file diff --git a/testdata/inputs/ls_complete.json b/testdata/inputs/ls_complete.json new file mode 100644 index 0000000..7bc669d --- /dev/null +++ b/testdata/inputs/ls_complete.json @@ -0,0 +1,21 @@ +{ + "items": [ + { + "last-modified": "2022-07-11T12:50:33", + "name": "code/gendata.C", + "size": { + "human_readable": "1.89 KiB", + "raw": 1937 + } + }, + { + "last-modified": "2022-07-11T13:30:17", + "name": "results/data.root", + "size": { + "human_readable": "150.83 KiB", + "raw": 154455 + } + } + ], + "total": 2 +} \ No newline at end of file diff --git a/testdata/inputs/ls_filters.json b/testdata/inputs/ls_filters.json new file mode 100644 index 0000000..5a31398 --- /dev/null +++ b/testdata/inputs/ls_filters.json @@ -0,0 +1,13 @@ +{ + "items": [ + { + "last-modified": "2022-07-11T12:50:33", + "name": "code/gendata.C", + "size": { + "human_readable": "1.89 KiB", + "raw": 1937 + } + } + ], + "total": 4 +} \ No newline at end of file diff --git a/testdata/inputs/ls_ignored_files.json b/testdata/inputs/ls_ignored_files.json new file mode 100644 index 0000000..d1f9639 --- /dev/null +++ b/testdata/inputs/ls_ignored_files.json @@ -0,0 +1,21 @@ +{ + "items": [ + { + "last-modified": "2022-07-11T12:50:33", + "name": ".git/test.C", + "size": { + "human_readable": "1.89 KiB", + "raw": 1937 + } + }, + { + "last-modified": "2022-07-11T13:30:17", + "name": "results/data.root", + "size": { + "human_readable": "150.83 KiB", + "raw": 154455 + } + } + ], + "total": 4 +} \ No newline at end of file diff --git a/testdata/inputs/mv_invalid_path.json b/testdata/inputs/mv_invalid_path.json new file mode 100644 index 0000000..8f9fb90 --- /dev/null +++ b/testdata/inputs/mv_invalid_path.json @@ -0,0 +1,3 @@ +{ + "message": "Path bad/ does not exists" +} \ No newline at end of file diff --git a/testdata/inputs/mv_valid_path.json b/testdata/inputs/mv_valid_path.json new file mode 100644 index 0000000..42e4487 --- /dev/null +++ b/testdata/inputs/mv_valid_path.json @@ -0,0 +1,5 @@ +{ + "message": "test", + "workflow_id": "my_workflow_id", + "workflow_name": "my_workflow" +} \ No newline at end of file diff --git a/testdata/inputs/open_already_open.json b/testdata/inputs/open_already_open.json new file mode 100644 index 0000000..1ae90a7 --- /dev/null +++ b/testdata/inputs/open_already_open.json @@ -0,0 +1,3 @@ +{ + "message": "Interactive session is already open" +} \ No newline at end of file diff --git a/testdata/inputs/open_jupyter.json b/testdata/inputs/open_jupyter.json new file mode 100644 index 0000000..2c9a97c --- /dev/null +++ b/testdata/inputs/open_jupyter.json @@ -0,0 +1,3 @@ +{ + "path": "/test/jupyter" +} \ No newline at end of file diff --git a/testdata/inputs/param_multiple.json b/testdata/inputs/param_multiple.json new file mode 100644 index 0000000..c612174 --- /dev/null +++ b/testdata/inputs/param_multiple.json @@ -0,0 +1,10 @@ +{ + "id": "my_workflow_id", + "name": "my_workflow", + "type": "serial", + "parameters": { + "data": "results/data.root", + "events": 20, + "plot": "results/plot.png" + } +} \ No newline at end of file diff --git a/testdata/inputs/params_only_data.json b/testdata/inputs/params_only_data.json new file mode 100644 index 0000000..edbb09b --- /dev/null +++ b/testdata/inputs/params_only_data.json @@ -0,0 +1,8 @@ +{ + "id": "my_workflow_id", + "name": "my_workflow", + "type": "cwl", + "parameters": { + "data": "results/data.root" + } +} \ No newline at end of file diff --git a/testdata/inputs/ping.json b/testdata/inputs/ping.json new file mode 100644 index 0000000..008bd57 --- /dev/null +++ b/testdata/inputs/ping.json @@ -0,0 +1,4 @@ +{ + "email": "john.doe@example.org", + "reana_server_version": "0.9.0a5" +} \ No newline at end of file diff --git a/testdata/inputs/quota_show_complete.json b/testdata/inputs/quota_show_complete.json new file mode 100644 index 0000000..932a87c --- /dev/null +++ b/testdata/inputs/quota_show_complete.json @@ -0,0 +1,26 @@ +{ + "quota": { + "cpu": { + "health": "healthy", + "usage": { + "human_readable": "1m 5s", + "raw": 10 + }, + "limit": { + "human_readable": "10m 50s", + "raw": 100 + } + }, + "disk": { + "health": "healthy", + "usage": { + "human_readable": "2 MiB", + "raw": 20 + }, + "limit": { + "human_readable": "20 MiB", + "raw": 200 + } + } + } +} \ No newline at end of file diff --git a/testdata/inputs/quota_show_no_info.json b/testdata/inputs/quota_show_no_info.json new file mode 100644 index 0000000..465c8b9 --- /dev/null +++ b/testdata/inputs/quota_show_no_info.json @@ -0,0 +1,6 @@ +{ + "quota": { + "cpu": {}, + "disk": {} + } +} \ No newline at end of file diff --git a/testdata/inputs/rm_empty.json b/testdata/inputs/rm_empty.json new file mode 100644 index 0000000..eea6efb --- /dev/null +++ b/testdata/inputs/rm_empty.json @@ -0,0 +1,4 @@ +{ + "deleted": {}, + "failed": {} +} \ No newline at end of file diff --git a/testdata/inputs/rm_multiple_files.json b/testdata/inputs/rm_multiple_files.json new file mode 100644 index 0000000..7db2cf2 --- /dev/null +++ b/testdata/inputs/rm_multiple_files.json @@ -0,0 +1,9 @@ +{ + "deleted": { + "files/one.py": {"size": 20}, + "files/two.py": {"size": 40} + }, + "failed": { + "files/three.py": {"error": "testing error in three.py"} + } +} \ No newline at end of file diff --git a/testdata/inputs/rm_no_freed.json b/testdata/inputs/rm_no_freed.json new file mode 100644 index 0000000..fd89320 --- /dev/null +++ b/testdata/inputs/rm_no_freed.json @@ -0,0 +1,6 @@ +{ + "deleted": { + "files/empty.py": {"size": 0} + }, + "failed": {} +} \ No newline at end of file diff --git a/testdata/inputs/secrets_add_repeated.json b/testdata/inputs/secrets_add_repeated.json new file mode 100644 index 0000000..c1d0cbd --- /dev/null +++ b/testdata/inputs/secrets_add_repeated.json @@ -0,0 +1,3 @@ +{ + "message": "Operation cancelled. Secret PASSWORD already exists. If you want to change it use overwrite" +} \ No newline at end of file diff --git a/testdata/inputs/secrets_delete_multiple.json b/testdata/inputs/secrets_delete_multiple.json new file mode 100644 index 0000000..b97c990 --- /dev/null +++ b/testdata/inputs/secrets_delete_multiple.json @@ -0,0 +1 @@ +["secret1", "secret2"] \ No newline at end of file diff --git a/testdata/inputs/secrets_delete_not_found.json b/testdata/inputs/secrets_delete_not_found.json new file mode 100644 index 0000000..85f55da --- /dev/null +++ b/testdata/inputs/secrets_delete_not_found.json @@ -0,0 +1 @@ +["secret1"] \ No newline at end of file diff --git a/testdata/inputs/secrets_list.json b/testdata/inputs/secrets_list.json new file mode 100644 index 0000000..2bc9aa2 --- /dev/null +++ b/testdata/inputs/secrets_list.json @@ -0,0 +1,10 @@ +[ + { + "name": "secret1", + "type": "env" + }, + { + "name": "secret2", + "type": "file" + } +] \ No newline at end of file diff --git a/testdata/inputs/start_already_finished.json b/testdata/inputs/start_already_finished.json new file mode 100644 index 0000000..62fd6c1 --- /dev/null +++ b/testdata/inputs/start_already_finished.json @@ -0,0 +1,3 @@ +{ + "message": "Workflow my_workflow is already finished and cannot be started again." +} \ No newline at end of file diff --git a/testdata/inputs/start_success.json b/testdata/inputs/start_success.json new file mode 100644 index 0000000..948c6b3 --- /dev/null +++ b/testdata/inputs/start_success.json @@ -0,0 +1,7 @@ +{ + "message": "Workflow successfully started", + "status": "running", + "user": "user", + "workflow_id": "my_workflow_id", + "workflow_name": "my_workflow" +} \ No newline at end of file diff --git a/testdata/inputs/status_finished.json b/testdata/inputs/status_finished.json new file mode 100644 index 0000000..b3bc8a1 --- /dev/null +++ b/testdata/inputs/status_finished.json @@ -0,0 +1,30 @@ +{ + "created": "2022-07-20T12:08:40", + "id": "my_workflow_id", + "name": "my_workflow.10", + "status": "finished", + "user": "user", + "logs": "logs", + "progress": { + "current_command": "ls", + "current_step_name": "step_name", + "failed": { + "job_ids": [], + "total": 0 + }, + "finished": { + "job_ids": ["job1", "job2"], + "total": 2 + }, + "run_finished_at": "2022-07-20T12:09:24", + "run_started_at": "2022-07-20T12:09:09", + "running": { + "job_ids": ["job3", "job4"], + "total": 2 + }, + "total": { + "job_ids": [], + "total": 2 + } + } +} \ No newline at end of file diff --git a/testdata/inputs/status_stopped.json b/testdata/inputs/status_stopped.json new file mode 100644 index 0000000..78d7c52 --- /dev/null +++ b/testdata/inputs/status_stopped.json @@ -0,0 +1,7 @@ +{ + "status": "stopped", + "user": "user", + "workflow_id": "my_workflow_id", + "workflow_name": "my_workflow", + "created": "2022-07-20T12:08:40" +} \ No newline at end of file