Skip to content

Commit

Permalink
tests: structure command tests with testdata inputs
Browse files Browse the repository at this point in the history
closes #113
  • Loading branch information
BrunoRosendo committed Sep 2, 2022
1 parent 057bcae commit e5b446c
Show file tree
Hide file tree
Showing 64 changed files with 694 additions and 734 deletions.
8 changes: 4 additions & 4 deletions cmd/close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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"},
Expand Down
23 changes: 8 additions & 15 deletions cmd/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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"},
Expand All @@ -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"},
Expand All @@ -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"},
Expand Down
51 changes: 14 additions & 37 deletions cmd/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -119,12 +94,14 @@ 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."},
args: []string{workflowA, workflowB},
expected: []string{
"REANA_WORKON is set to invalid, but that workflow does not exist.",
},
wantError: true,
},
"invalid number of arguments": {
Expand Down
101 changes: 15 additions & 86 deletions cmd/du_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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"},
Expand All @@ -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"},
Expand All @@ -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},
Expand All @@ -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"},
Expand All @@ -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"},
Expand All @@ -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,
},
Expand Down
Loading

0 comments on commit e5b446c

Please sign in to comment.