From ab2af780d14e05c95df23a163e96401b84f512ab Mon Sep 17 00:00:00 2001 From: Aashir Siddiqui <66883041+aashir21@users.noreply.github.com> Date: Mon, 13 Jan 2025 13:45:03 +0000 Subject: [PATCH] CLI now returns and filter test on group name (#321) * CLI now returns and filter test on group name Signed-off-by: Aashir Siddiqui * Added validation for group name Signed-off-by: Aashir Siddiqui * Added unit test Signed-off-by: Aashir Siddiqui * Added a unit test for checking mutually exclusive flags Signed-off-by: Aashir Siddiqui * Updated integration tests Signed-off-by: Aashir Siddiqui * review: Formatting fixes, revert unwanted changes Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> * review: Add group validation, stop erroring out when --age is not given with --group Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> * Restore ecosystem script constants and add group name validation test Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> * Add group to more unit tests Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> * Add group to runs submit output, add runs get --group ecosystem tests Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> * Empty commit to kick off build Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> * Create RunsQuery struct to store run query parameters and get pages of runs Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> * Replace Latin-1 validation for group and secret names with alphanumeric + dashes and underscores Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> * Update role name validation to use common name validation function Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> --------- Signed-off-by: Aashir Siddiqui Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> Co-authored-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> --- docs/generated/errors-list.md | 7 +- docs/generated/galasactl_runs_get.md | 1 + pkg/cmd/runsGet.go | 5 + pkg/cmd/runsGet_test.go | 36 +++ pkg/errors/errorMessage.go | 7 +- pkg/roles/roles.go | 18 +- pkg/runs/groups.go | 23 ++ pkg/runs/jsonReporter_test.go | 23 +- pkg/runs/runTypes.go | 1 + pkg/runs/runs.go | 3 +- pkg/runs/runsConverter.go | 2 + pkg/runs/runsDelete.go | 10 +- pkg/runs/runsDownload.go | 3 +- pkg/runs/runsGet.go | 210 ++++++---------- pkg/runs/runsGet_test.go | 226 +++++++++++++----- pkg/runs/runsQuery.go | 122 ++++++++++ pkg/runs/submitter.go | 1 + pkg/runs/yamlReporter_test.go | 27 ++- pkg/runsformatter/detailsFormatter.go | 1 + pkg/runsformatter/detailsFormatter_test.go | 85 ++++--- pkg/runsformatter/rawFormatter.go | 1 + pkg/runsformatter/rawFormatter_test.go | 57 ++--- pkg/runsformatter/runsFormatter.go | 2 + pkg/runsformatter/summaryFormatter.go | 4 +- pkg/runsformatter/summaryFormatter_test.go | 156 ++++++------ pkg/secrets/secrets.go | 22 +- pkg/utils/validationUtils.go | 55 +++++ test-galasactl-ecosystem.sh | 8 +- .../calculate-galasactl-executables.sh | 11 - test-scripts/gherkin-runs-tests.sh | 11 - test-scripts/properties-tests.sh | 11 - test-scripts/resources-tests.sh | 11 - test-scripts/runs-tests.sh | 78 +++++- 33 files changed, 757 insertions(+), 481 deletions(-) create mode 100644 pkg/runs/groups.go create mode 100644 pkg/runs/runsQuery.go create mode 100644 pkg/utils/validationUtils.go diff --git a/docs/generated/errors-list.md b/docs/generated/errors-list.md index 88ab87f8..e92b0735 100644 --- a/docs/generated/errors-list.md +++ b/docs/generated/errors-list.md @@ -79,7 +79,7 @@ The `galasactl` tool can generate the following errors: - GAL1076E: Badly formed from or to value '{}' specified in the age parameter. The value could not be converted into an integer value. - GAL1077E: Invalid value '{}' detected for age parameter. The 'from' value must be greater than the 'to' value. - GAL1078E: Badly formed '--age' parameter value '{}' specified. Age of the test runs should be specified in the format '{FROM}{TIME-UNIT}:{TO}{TIME-UNIT}' or '{FROM}{TIME-UNIT}', where 'FROM' is a positive, non-zero integer, 'TO' is a non-negative integer, and 'TIME-UNIT' can be {}. 'FROM' must be greater than 'TO'. 'TO' defaults to 0 if not specified. Use the --help flag for more information, or refer to the documentation at https://galasa.dev/docs/reference/cli-commands. -- GAL1079E: The --age or the --name parameter must be used to identify which test run(s) you want see. Use the --help flag for more information, or refer to the documentation at https://galasa.dev/docs/reference/cli-commands. +- GAL1079E: The --age, --name, or --group parameter must be used to identify which test run(s) you want see. Use the --help flag for more information, or refer to the documentation at https://galasa.dev/docs/reference/cli-commands. - GAL1080E: Invalid 'from' value '{}' in the '--age' parameter. Age of the test runs should be specified in the format '{FROM}{TIME-UNIT}:{TO}{TIME-UNIT}' or '{FROM}{TIME-UNIT}', where 'FROM' is a positive, non-zero integer, 'TO' is a non-negative integer, and 'TIME-UNIT' can be {}. 'FROM' must be greater than 'TO'. 'TO' defaults to 0 if not specified. Use the --help flag for more information, or refer to the documentation at https://galasa.dev/docs/reference/cli-commands. - GAL1081E: Unable use a negative value '{}' in the '--age' parameter. Age of the test runs should be specified in the format '{FROM}{TIME-UNIT}:{TO}{TIME-UNIT}' or '{FROM}{TIME-UNIT}', where 'FROM' is a positive, non-zero integer, 'TO' is a non-negative integer, and 'TIME-UNIT' can be {}. 'FROM' must be greater than 'TO'. 'TO' defaults to 0 if not specified. Use the --help flag for more information, or refer to the documentation at https://galasa.dev/docs/reference/cli-commands. - GAL1082E: Invalid time unit specified '{}' in the '--age' parameter. Age of the test runs should be specified in the format '{FROM}{TIME-UNIT}:{TO}{TIME-UNIT}' or '{FROM}{TIME-UNIT}', where 'FROM' is a positive, non-zero integer, 'TO' is a non-negative integer, and 'TIME-UNIT' can be {}. 'FROM' must be greater than 'TO'. 'TO' defaults to 0 if not specified. Use the --help flag for more information, or refer to the documentation at https://galasa.dev/docs/reference/cli-commands. @@ -105,6 +105,7 @@ The `galasactl` tool can generate the following errors: - GAL1102E: name '{}' is invalid. '--name' is a mandatory flag for this command. Use the --help flag for more information, or refer to the documentation at https://galasa.dev/docs/reference/cli-commands. - GAL1103E: Could not query CPS results. Reason: '{}' - GAL1104E: Unable to delete the bearer token file '{}'. +- GAL1105E: Invalid group name provided. Group names must only contain characters in the following ranges: 'a'-'z', 'A'-'Z', '0'-'9', '-' (dash), '_' (underscore). - GAL1106E: Could not get security bearer token from API server. Reason: '{}'. Ensure you have allocated a personal access token and configured your client program by setting your GALASA_TOKEN as an environment variable or by storing it in your galasactl.properties file - GAL1107E: Could not get security bearer token from file '{}'. Reason: '{}'. Ensure you are authenticated by running 'galasactl auth login' and that your personal access token has not expired or been revoked - GAL1108E: Invalid bearer token. Ensure you are authenticated by running 'galasactl auth login' and that your personal access token has not expired or been revoked @@ -167,7 +168,7 @@ The `galasactl` tool can generate the following errors: - GAL1169E: An attempt to delete a secret named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}' - GAL1170E: An attempt to delete a secret named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are: '{}' - GAL1171E: An attempt to delete a secret named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in the json format. -- GAL1172E: Invalid secret name provided. The name provided with the --name flag cannot be empty, contain spaces or dots (.), and must only contain characters in the Latin-1 character set. +- GAL1172E: Invalid secret name provided. The name provided with the --name flag cannot be empty and must only contain characters in the following ranges: 'a'-'z', 'A'-'Z', '0'-'9', '-' (dash), '_' (underscore). - GAL1173E: An attempt to delete a secret named '{}' failed. Sending the delete request to the Galasa service failed. Cause is {} - GAL1174E: An attempt to get a secret named '{}' failed. Unexpected http status code {} received from the server. - GAL1175E: An attempt to get a secret named '{}' failed. Unexpected http status code {} received from the server. Error details from the server could not be read. Cause: {} @@ -204,7 +205,7 @@ The `galasactl` tool can generate the following errors: - GAL1206E: Failed to get roles. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}' - GAL1207E: Failed to get roles. Unexpected http status code {} received from the server. Error details from the server are: '{}' - GAL1208E: Failed to get roles. Unexpected http status code {} received from the server. Error details from the server are not in the json format. -- GAL1209E: Invalid role name provided. The name provided with the --name flag cannot be empty, contain spaces or dots (.), and must only contain characters in the Latin-1 character set. +- GAL1209E: Invalid role name provided. The name provided with the --name flag cannot be empty and must only contain characters in the following ranges: 'a'-'z', 'A'-'Z', '0'-'9', '-' (dash), '_' (underscore). - GAL1210E: Role name {} is not known on the Galasa service. - GAL1225E: Failed to open file '{}' cause: {}. Check that this file exists, and that you have read permissions. - GAL1226E: Internal failure. Contents of gzip could be read, but not decoded. New gzip reader failed: file: {} error: {} diff --git a/docs/generated/galasactl_runs_get.md b/docs/generated/galasactl_runs_get.md index ce9d4983..0e5fceba 100644 --- a/docs/generated/galasactl_runs_get.md +++ b/docs/generated/galasactl_runs_get.md @@ -16,6 +16,7 @@ galasactl runs get [flags] --active parameter to retrieve runs that have not finished yet. Cannot be used in conjunction with --name or --result flag. --age string the age of the test run(s) we want information about. Supported formats are: 'FROM' or 'FROM:TO', where FROM and TO are each ages, made up of an integer and a time-unit qualifier. Supported time-units are 'w' (weeks), 'd' (days), 'h' (hours), 'm' (minutes). If missing, the TO part is defaulted to '0h'. Examples: '--age 1d', '--age 6h:1h' (list test runs which happened from 6 hours ago to 1 hour ago). The TO part must be a smaller time-span than the FROM part. --format string output format for the data returned. Supported formats are: 'details', 'raw', 'summary'. (default "summary") + --group string the name of the group to return tests under that group. Cannot be used in conjunction with --name -h, --help Displays the options for the 'runs get' command. --name string the name of the test run we want information about. Cannot be used in conjunction with --requestor, --result or --active flags --requestor string the requestor of the test run we want information about. Cannot be used in conjunction with --name flag. diff --git a/pkg/cmd/runsGet.go b/pkg/cmd/runsGet.go index 280f7cd1..345fdb99 100644 --- a/pkg/cmd/runsGet.go +++ b/pkg/cmd/runsGet.go @@ -28,6 +28,7 @@ type RunsGetCmdValues struct { requestor string result string isActiveRuns bool + group string } type RunsGetCommand struct { @@ -93,6 +94,8 @@ func (cmd *RunsGetCommand) createCobraCommand( formatters := runs.GetFormatterNamesString(runs.CreateFormatters()) runsGetCobraCmd.PersistentFlags().StringVar(&cmd.values.runName, "name", "", "the name of the test run we want information about."+ " Cannot be used in conjunction with --requestor, --result or --active flags") + runsGetCobraCmd.PersistentFlags().StringVar(&cmd.values.group, "group", "", "the name of the group to return tests under that group."+ + " Cannot be used in conjunction with --name") runsGetCobraCmd.PersistentFlags().StringVar(&cmd.values.age, "age", "", "the age of the test run(s) we want information about. Supported formats are: 'FROM' or 'FROM:TO', where FROM and TO are each ages,"+ " made up of an integer and a time-unit qualifier. Supported time-units are "+units+". If missing, the TO part is defaulted to '0h'. Examples: '--age 1d',"+ " '--age 6h:1h' (list test runs which happened from 6 hours ago to 1 hour ago)."+ @@ -109,6 +112,7 @@ func (cmd *RunsGetCommand) createCobraCommand( runsGetCobraCmd.MarkFlagsMutuallyExclusive("name", "result") runsGetCobraCmd.MarkFlagsMutuallyExclusive("name", "active") runsGetCobraCmd.MarkFlagsMutuallyExclusive("result", "active") + runsGetCobraCmd.MarkFlagsMutuallyExclusive("group", "name") runsCommand.CobraCommand().AddCommand(runsGetCobraCmd) @@ -165,6 +169,7 @@ func (cmd *RunsGetCommand) executeRunsGet( cmd.values.result, cmd.values.isActiveRuns, cmd.values.outputFormatString, + cmd.values.group, timeService, console, apiServerUrl, diff --git a/pkg/cmd/runsGet_test.go b/pkg/cmd/runsGet_test.go index 949b3ebb..cbc92a91 100644 --- a/pkg/cmd/runsGet_test.go +++ b/pkg/cmd/runsGet_test.go @@ -135,6 +135,25 @@ func TestRunsGetNameFlagReturnsOk(t *testing.T) { assert.Contains(t, cmd.Values().(*RunsGetCmdValues).runName, "gerald") } +func TestRunsGetGroupFlagReturnsOk(t *testing.T) { + // Given... + factory := utils.NewMockFactory() + commandCollection, cmd := setupTestCommandCollection(COMMAND_NAME_RUNS_GET, factory, t) + + var args []string = []string{"runs", "get", "--group", "someGroup"} + + // When... + err := commandCollection.Execute(args) + + // Then... + assert.Nil(t, err) + + // Check what the user saw was reasonable + checkOutput("", "", factory, t) + + assert.Contains(t, cmd.Values().(*RunsGetCmdValues).group, "someGroup") +} + func TestRunsGetageFlagReturnsOk(t *testing.T) { // Given... factory := utils.NewMockFactory() @@ -297,3 +316,20 @@ func TestRunsGetResultActiveMutuallyExclusive(t *testing.T) { // Check what the user saw is reasonable. checkOutput("", "Error: if any flags in the group [result active] are set none of the others can be; [active result] were all set", factory, t) } + +func TestRunsGetGroupRunNameMutuallyExclusive(t *testing.T) { + // Given... + factory := utils.NewMockFactory() + + var args []string = []string{"runs", "get", "--group", "group-1", "--name", "CV123"} + + // When... + err := Execute(factory, args) + + // Then... + assert.NotNil(t, err) + assert.Contains(t, err.Error(), "if any flags in the group [group name] are set none of the others can be; [group name] were all set") + + // Check what the user saw is reasonable. + checkOutput("", "Error: if any flags in the group [group name] are set none of the others can be; [group name] were all set", factory, t) +} diff --git a/pkg/errors/errorMessage.go b/pkg/errors/errorMessage.go index 4759a8ce..d78b8377 100644 --- a/pkg/errors/errorMessage.go +++ b/pkg/errors/errorMessage.go @@ -241,7 +241,7 @@ var ( GALASA_ERROR_INVALID_FROM_OR_TO_PARAMETER = NewMessageType("GAL1076E: Badly formed from or to value '%s' specified in the age parameter. The value could not be converted into an integer value.", 1076, STACK_TRACE_NOT_WANTED) GALASA_ERROR_FROM_AGE_SMALLER_THAN_TO_AGE = NewMessageType("GAL1077E: Invalid value '%s' detected for age parameter. The 'from' value must be greater than the 'to' value.", 1077, STACK_TRACE_NOT_WANTED) GALASA_ERROR_INVALID_AGE_PARAMETER = NewMessageType("GAL1078E: Badly formed '--age' parameter value '%s' specified. Age of the test runs should be specified in the format '{FROM}{TIME-UNIT}:{TO}{TIME-UNIT}' or '{FROM}{TIME-UNIT}', where 'FROM' is a positive, non-zero integer, 'TO' is a non-negative integer, and 'TIME-UNIT' can be %s. 'FROM' must be greater than 'TO'. 'TO' defaults to 0 if not specified."+SEE_COMMAND_REFERENCE, 1078, STACK_TRACE_NOT_WANTED) - GALASA_ERROR_NO_RUNNAME_OR_AGE_SPECIFIED = NewMessageType("GAL1079E: The --age or the --name parameter must be used to identify which test run(s) you want see."+SEE_COMMAND_REFERENCE, 1079, STACK_TRACE_NOT_WANTED) + GALASA_ERROR_NO_TEST_RUN_IDENTIFIER_FLAG_SPECIFIED = NewMessageType("GAL1079E: The --age, --name, or --group parameter must be used to identify which test run(s) you want see."+SEE_COMMAND_REFERENCE, 1079, STACK_TRACE_NOT_WANTED) GALASA_ERROR_INVALID_FROM_AGE_SPECIFIED = NewMessageType("GAL1080E: Invalid 'from' value '%s' in the '--age' parameter. Age of the test runs should be specified in the format '{FROM}{TIME-UNIT}:{TO}{TIME-UNIT}' or '{FROM}{TIME-UNIT}', where 'FROM' is a positive, non-zero integer, 'TO' is a non-negative integer, and 'TIME-UNIT' can be %s. 'FROM' must be greater than 'TO'. 'TO' defaults to 0 if not specified."+SEE_COMMAND_REFERENCE, 1080, STACK_TRACE_NOT_WANTED) GALASA_ERROR_NEGATIVE_AGE_SPECIFIED = NewMessageType("GAL1081E: Unable use a negative value '%s' in the '--age' parameter. Age of the test runs should be specified in the format '{FROM}{TIME-UNIT}:{TO}{TIME-UNIT}' or '{FROM}{TIME-UNIT}', where 'FROM' is a positive, non-zero integer, 'TO' is a non-negative integer, and 'TIME-UNIT' can be %s. 'FROM' must be greater than 'TO'. 'TO' defaults to 0 if not specified."+SEE_COMMAND_REFERENCE, 1081, STACK_TRACE_NOT_WANTED) GALASA_ERROR_BAD_TIME_UNIT_AGE_SPECIFIED = NewMessageType("GAL1082E: Invalid time unit specified '%s' in the '--age' parameter. Age of the test runs should be specified in the format '{FROM}{TIME-UNIT}:{TO}{TIME-UNIT}' or '{FROM}{TIME-UNIT}', where 'FROM' is a positive, non-zero integer, 'TO' is a non-negative integer, and 'TIME-UNIT' can be %s. 'FROM' must be greater than 'TO'. 'TO' defaults to 0 if not specified."+SEE_COMMAND_REFERENCE, 1082, STACK_TRACE_NOT_WANTED) @@ -268,6 +268,7 @@ var ( GALASA_ERROR_MISSING_NAME_FLAG = NewMessageType("GAL1102E: name '%s' is invalid. '--name' is a mandatory flag for this command."+SEE_COMMAND_REFERENCE, 1102, STACK_TRACE_WANTED) GALASA_ERROR_QUERY_CPS_FAILED = NewMessageType("GAL1103E: Could not query CPS results. Reason: '%s'", 1103, STACK_TRACE_WANTED) GALASA_ERROR_UNABLE_TO_DELETE_BEARER_TOKEN_FILE = NewMessageType("GAL1104E: Unable to delete the bearer token file '%s'.", 1104, STACK_TRACE_NOT_WANTED) + GALASA_ERROR_INVALID_GROUP_NAME_PROVIDED = NewMessageType("GAL1105E: Invalid group name provided. Group names must only contain characters in the following ranges: 'a'-'z', 'A'-'Z', '0'-'9', '-' (dash), '_' (underscore).", 1105, STACK_TRACE_NOT_WANTED) GALASA_ERROR_RETRIEVING_BEARER_TOKEN_FROM_API_SERVER = NewMessageType("GAL1106E: Could not get security bearer token from API server. Reason: '%s'. Ensure you have allocated a personal access token and configured your client program by setting your GALASA_TOKEN as an environment variable or by storing it in your galasactl.properties file", 1106, STACK_TRACE_WANTED) GALASA_ERROR_RETRIEVING_BEARER_TOKEN_FROM_FILE = NewMessageType("GAL1107E: Could not get security bearer token from file '%s'. Reason: '%s'. Ensure you are authenticated by running 'galasactl auth login' and that your personal access token has not expired or been revoked", 1107, STACK_TRACE_NOT_WANTED) GALASA_ERROR_INVALID_BEARER_TOKEN = NewMessageType("GAL1108E: Invalid bearer token. Ensure you are authenticated by running 'galasactl auth login' and that your personal access token has not expired or been revoked", 1108, STACK_TRACE_NOT_WANTED) @@ -345,7 +346,7 @@ var ( GALASA_ERROR_DELETE_SECRET_UNPARSEABLE_CONTENT = NewMessageType("GAL1169E: An attempt to delete a secret named '%s' failed. Unexpected http status code %v received from the server. Error details from the server are not in a valid json format. Cause: '%s'", 1169, STACK_TRACE_NOT_WANTED) GALASA_ERROR_DELETE_SECRET_SERVER_REPORTED_ERROR = NewMessageType("GAL1170E: An attempt to delete a secret named '%s' failed. Unexpected http status code %v received from the server. Error details from the server are: '%s'", 1170, STACK_TRACE_NOT_WANTED) GALASA_ERROR_DELETE_SECRET_EXPLANATION_NOT_JSON = NewMessageType("GAL1171E: An attempt to delete a secret named '%s' failed. Unexpected http status code %v received from the server. Error details from the server are not in the json format.", 1171, STACK_TRACE_NOT_WANTED) - GALASA_ERROR_INVALID_SECRET_NAME = NewMessageType("GAL1172E: Invalid secret name provided. The name provided with the --name flag cannot be empty, contain spaces or dots (.), and must only contain characters in the Latin-1 character set.", 1172, STACK_TRACE_NOT_WANTED) + GALASA_ERROR_INVALID_SECRET_NAME = NewMessageType("GAL1172E: Invalid secret name provided. The name provided with the --name flag cannot be empty and must only contain characters in the following ranges: 'a'-'z', 'A'-'Z', '0'-'9', '-' (dash), '_' (underscore).", 1172, STACK_TRACE_NOT_WANTED) GALASA_ERROR_DELETE_SECRET_REQUEST_FAILED = NewMessageType("GAL1173E: An attempt to delete a secret named '%s' failed. Sending the delete request to the Galasa service failed. Cause is %v", 1173, STACK_TRACE_NOT_WANTED) GALASA_ERROR_GET_SECRET_NO_RESPONSE_CONTENT = NewMessageType("GAL1174E: An attempt to get a secret named '%s' failed. Unexpected http status code %v received from the server.", 1174, STACK_TRACE_NOT_WANTED) @@ -390,7 +391,7 @@ var ( GALASA_ERROR_GET_ROLES_EXPLANATION_NOT_JSON = NewMessageType("GAL1208E: Failed to get roles. Unexpected http status code %v received from the server. Error details from the server are not in the json format.", 1208, STACK_TRACE_NOT_WANTED) // When getting a single named role... - GALASA_ERROR_INVALID_ROLE_NAME = NewMessageType("GAL1209E: Invalid role name provided. The name provided with the --name flag cannot be empty, contain spaces or dots (.), and must only contain characters in the Latin-1 character set.", 1209, STACK_TRACE_NOT_WANTED) + GALASA_ERROR_INVALID_ROLE_NAME = NewMessageType("GAL1209E: Invalid role name provided. The name provided with the --name flag cannot be empty and must only contain characters in the following ranges: 'a'-'z', 'A'-'Z', '0'-'9', '-' (dash), '_' (underscore).", 1209, STACK_TRACE_NOT_WANTED) GALASA_ERROR_ROLE_NAME_NOT_FOUND = NewMessageType("GAL1210E: Role name %v is not known on the Galasa service.", 1210, STACK_TRACE_NOT_WANTED) // Warnings... diff --git a/pkg/roles/roles.go b/pkg/roles/roles.go index 75de23e3..f10194c1 100644 --- a/pkg/roles/roles.go +++ b/pkg/roles/roles.go @@ -9,29 +9,15 @@ import ( "strings" galasaErrors "github.com/galasa-dev/cli/pkg/errors" + "github.com/galasa-dev/cli/pkg/utils" ) func validateRoleName(nameToValidate string) (string, error) { var err error name := strings.TrimSpace(nameToValidate) - if name == "" || !usesValidRoleCharacters(name) { + if name == "" || !utils.IsNameValid(name) { err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_INVALID_ROLE_NAME) } return name, err } - -// Checks if a given string contains only characters in the Latin-1 character set (codepoints 0-255), -// returning true if so, and false otherwise -func usesValidRoleCharacters(str string) bool { - isValidLatin1 := true - for _, character := range str { - if !((character >= 'a' && character <= 'z') || - (character >= 'A' && character <= 'Z') || - (character >= '0' && character <= '9')) { - isValidLatin1 = false - break - } - } - return isValidLatin1 -} diff --git a/pkg/runs/groups.go b/pkg/runs/groups.go new file mode 100644 index 00000000..4d28ae18 --- /dev/null +++ b/pkg/runs/groups.go @@ -0,0 +1,23 @@ +/* + * Copyright contributors to the Galasa project + * + * SPDX-License-Identifier: EPL-2.0 + */ +package runs + +import ( + "strings" + + galasaErrors "github.com/galasa-dev/cli/pkg/errors" + "github.com/galasa-dev/cli/pkg/utils" +) + +func validateGroupname(groupName string) (string, error) { + var err error + trimmedName := strings.TrimSpace(groupName) + + if trimmedName == "" || !utils.IsNameValid(trimmedName) { + err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_INVALID_GROUP_NAME_PROVIDED) + } + return trimmedName, err +} diff --git a/pkg/runs/jsonReporter_test.go b/pkg/runs/jsonReporter_test.go index 6d5c6799..c6e6eae7 100644 --- a/pkg/runs/jsonReporter_test.go +++ b/pkg/runs/jsonReporter_test.go @@ -18,16 +18,16 @@ func TestJsonReportWorks(t *testing.T) { mockFileSystem := files.NewMockFileSystem() finishedRuns := TestRun{ - Name: "myTestRun", - Bundle: "myBundle", - Class: "com.myco.MyClass", - Stream: "myStream", - Obr: "myOBR", - Status: "myStatus", - Result: "PASSED", - Overrides: make(map[string]string, 1), - Tests: []TestMethod{{Method: "method1", Result: "passed"}, {Method: "method2", Result: "passed"}}, - GherkinUrl: "file:///my.feature", + Name: "myTestRun", + Bundle: "myBundle", + Class: "com.myco.MyClass", + Stream: "myStream", + Obr: "myOBR", + Status: "myStatus", + Result: "PASSED", + Overrides: make(map[string]string, 1), + Tests: []TestMethod{{Method: "method1", Result: "passed"}, {Method: "method2", Result: "passed"}}, + GherkinUrl: "file:///my.feature", GherkinFeature: "my", } @@ -78,7 +78,8 @@ func TestJsonReportWorks(t *testing.T) { } ], "GherkinUrl":"file:///my.feature", - "GherkinFeature":"my" + "GherkinFeature":"my", + "group":"" } ] }` diff --git a/pkg/runs/runTypes.go b/pkg/runs/runTypes.go index 41efd92d..cc04137e 100644 --- a/pkg/runs/runTypes.go +++ b/pkg/runs/runTypes.go @@ -19,6 +19,7 @@ type TestRun struct { Tests []TestMethod `yaml:"tests" json:"tests"` GherkinUrl string `yaml:"gherkin"` GherkinFeature string `yaml:"feature"` + Group string `yaml:"group" json:"group"` } type TestMethod struct { diff --git a/pkg/runs/runs.go b/pkg/runs/runs.go index f7904e01..3c504fc4 100644 --- a/pkg/runs/runs.go +++ b/pkg/runs/runs.go @@ -25,11 +25,12 @@ func getRunIdFromRunName(runName string, requestorParameter := "" resultParameter := "" + group := "" fromAgeHours := 0 toAgeHours := 0 shouldGetActive := true - runs, err = GetRunsFromRestApi(runName, requestorParameter, resultParameter, fromAgeHours, toAgeHours, shouldGetActive, timeService, apiClient) + runs, err = GetRunsFromRestApi(runName, requestorParameter, resultParameter, fromAgeHours, toAgeHours, shouldGetActive, timeService, apiClient, group) if err == nil { diff --git a/pkg/runs/runsConverter.go b/pkg/runs/runsConverter.go index 3de4ddf7..96a28a33 100644 --- a/pkg/runs/runsConverter.go +++ b/pkg/runs/runsConverter.go @@ -117,6 +117,7 @@ func getTestStructureData(run galasaapi.Run, apiServerUrl string) runsformatter. newFormattableTest.Requestor = run.TestStructure.GetRequestor() newFormattableTest.Bundle = run.TestStructure.GetBundle() newFormattableTest.Methods = run.TestStructure.GetMethods() + newFormattableTest.Group = run.TestStructure.GetGroup() return newFormattableTest } @@ -160,6 +161,7 @@ func getTestRunData(run TestRun, isLost bool) runsformatter.FormattableTest { newFormattableTest.Bundle = run.Bundle newFormattableTest.Methods = nil newFormattableTest.Lost = isLost + newFormattableTest.Group = run.Group return newFormattableTest } diff --git a/pkg/runs/runsDelete.go b/pkg/runs/runsDelete.go index 1e25a312..12612995 100644 --- a/pkg/runs/runsDelete.go +++ b/pkg/runs/runsDelete.go @@ -43,9 +43,10 @@ func RunsDelete( resultParameter := "" fromAgeHours := 0 toAgeHours := 0 + group := "" shouldGetActive := false var runs []galasaapi.Run - runs, err = GetRunsFromRestApi(runName, requestorParameter, resultParameter, fromAgeHours, toAgeHours, shouldGetActive, timeService, apiClient) + runs, err = GetRunsFromRestApi(runName, requestorParameter, resultParameter, fromAgeHours, toAgeHours, shouldGetActive, timeService, apiClient, group) if err == nil { @@ -81,14 +82,14 @@ func deleteRuns( for _, run := range runs { runId := run.GetRunId() runName := *run.GetTestStructure().RunName - + apicall := apiClient.ResultArchiveStoreAPIApi.DeleteRasRunById(context, runId).ClientApiVersion(restApiVersion) httpResponse, err = apicall.Execute() if httpResponse != nil { defer httpResponse.Body.Close() } - + // 200-299 http status codes manifest in an error. if err != nil { if httpResponse == nil { @@ -107,7 +108,7 @@ func deleteRuns( ) } } - + if err != nil { break } else { @@ -118,4 +119,3 @@ func deleteRuns( return err } - diff --git a/pkg/runs/runsDownload.go b/pkg/runs/runsDownload.go index b55947f8..50010a2d 100644 --- a/pkg/runs/runsDownload.go +++ b/pkg/runs/runsDownload.go @@ -45,10 +45,11 @@ func DownloadArtifacts( if err == nil { requestorParameter := "" resultParameter := "" + group := "" fromAgeHours := 0 toAgeHours := 0 shouldGetActive := false - runs, err = GetRunsFromRestApi(runName, requestorParameter, resultParameter, fromAgeHours, toAgeHours, shouldGetActive, timeService, apiClient) + runs, err = GetRunsFromRestApi(runName, requestorParameter, resultParameter, fromAgeHours, toAgeHours, shouldGetActive, timeService, apiClient, group) if err == nil { if len(runs) > 1 { // get list of runs that are reRuns - get list of runs that are reRuns of each other diff --git a/pkg/runs/runsGet.go b/pkg/runs/runsGet.go index d2fe8739..68005ce9 100644 --- a/pkg/runs/runsGet.go +++ b/pkg/runs/runsGet.go @@ -13,7 +13,6 @@ import ( "sort" "strconv" "strings" - "time" "github.com/galasa-dev/cli/pkg/embedded" galasaErrors "github.com/galasa-dev/cli/pkg/errors" @@ -47,6 +46,7 @@ func GetRuns( resultParameter string, shouldGetActive bool, outputFormatString string, + group string, timeService spi.TimeService, console spi.Console, apiServerUrl string, @@ -58,20 +58,24 @@ func GetRuns( log.Printf("GetRuns entered.") - if (runName == "") && (age == "") { - err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_NO_RUNNAME_OR_AGE_SPECIFIED) + if runName == "" && age == "" && group == "" { + err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_NO_TEST_RUN_IDENTIFIER_FLAG_SPECIFIED) } - if (err == nil) && (runName != "") { + if err == nil && runName != "" { // Validate the runName as best we can without contacting the ecosystem. err = ValidateRunName(runName) } - if (err == nil) && (age != "") { + if err == nil && age != "" { fromAge, toAge, err = getTimesFromAge(age) } - if (err == nil) && (resultParameter != "") { + if err == nil && group != "" { + group, err = validateGroupname(group) + } + + if err == nil && resultParameter != "" { if shouldGetActive { err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_ACTIVE_AND_RESULT_ARE_MUTUALLY_EXCLUSIVE) } @@ -85,7 +89,7 @@ func GetRuns( chosenFormatter, err = validateOutputFormatFlagValue(outputFormatString, validFormatters) if err == nil { var runJson []galasaapi.Run - runJson, err = GetRunsFromRestApi(runName, requestorParameter, resultParameter, fromAge, toAge, shouldGetActive, timeService, apiClient) + runJson, err = GetRunsFromRestApi(runName, requestorParameter, resultParameter, fromAge, toAge, shouldGetActive, timeService, apiClient, group) if err == nil { // Some formatters need extra fields filled-in so they can be displayed. if chosenFormatter.IsNeedingMethodDetails() { @@ -178,10 +182,10 @@ func GetRunDetailsFromRasSearchRuns(runs []galasaapi.Run, apiClient *galasaapi.A if err == nil { for _, run := range runs { - details, err = getRunByRunIdFromRestApi(run.GetRunId(), apiClient, restApiVersion) - if err == nil && details != nil { - runsDetails = append(runsDetails, *details) - } + details, err = getRunByRunIdFromRestApi(run.GetRunId(), apiClient, restApiVersion) + if err == nil && details != nil { + runsDetails = append(runsDetails, *details) + } } } @@ -189,99 +193,32 @@ func GetRunDetailsFromRasSearchRuns(runs []galasaapi.Run, apiClient *galasaapi.A } func getRunByRunIdFromRestApi( - runId string, - apiClient *galasaapi.APIClient, - restApiVersion string, + runId string, + apiClient *galasaapi.APIClient, + restApiVersion string, ) (*galasaapi.Run, error) { - var err error - var details *galasaapi.Run - var httpResponse *http.Response - var context context.Context = nil - - log.Printf("Getting details for run %v\n", runId) - details, httpResponse, err = apiClient.ResultArchiveStoreAPIApi.GetRasRunById(context, runId).ClientApiVersion(restApiVersion).Execute() - - var statusCode int - if httpResponse != nil { - defer httpResponse.Body.Close() - statusCode = httpResponse.StatusCode - } - - if err != nil { - err = galasaErrors.NewGalasaErrorWithHttpStatusCode(statusCode, galasaErrors.GALASA_ERROR_QUERY_RUNS_FAILED, err.Error()) - } else { - if statusCode != http.StatusOK { - err = galasaErrors.NewGalasaErrorWithHttpStatusCode(statusCode, galasaErrors.GALASA_ERROR_QUERY_RUNS_NON_OK_STATUS, strconv.Itoa(httpResponse.StatusCode)) - } - } - return details, err -} + var err error + var details *galasaapi.Run + var httpResponse *http.Response + var context context.Context = nil -func getRunsPageFromRestApi( - pageCursor string, - runName string, - requestorParameter string, - resultParameter string, - fromAgeMins int, - toAgeMins int, - fromTime time.Time, - toTime time.Time, - shouldGetActive bool, - apiClient *galasaapi.APIClient, - restApiVersion string, -) (*galasaapi.RunResults, error) { - var err error - var runData *galasaapi.RunResults - var httpResponse *http.Response - var context context.Context = nil - - apicall := apiClient.ResultArchiveStoreAPIApi.GetRasSearchRuns(context).ClientApiVersion(restApiVersion).IncludeCursor("true") - if fromAgeMins != 0 { - apicall = apicall.From(fromTime) - } - if toAgeMins != 0 { - apicall = apicall.To(toTime) - } - if runName != "" { - apicall = apicall.Runname(runName) - } - if requestorParameter != "" { - apicall = apicall.Requestor(requestorParameter) - } - if resultParameter != "" { - apicall = apicall.Result(resultParameter) - } - if shouldGetActive { - apicall = apicall.Status(activeStatusNames) - } - if pageCursor != "" { - apicall = apicall.Cursor(pageCursor) - } - apicall = apicall.Sort("from:desc") - runData, httpResponse, err = apicall.Execute() - - var statusCode int - if httpResponse != nil { - defer httpResponse.Body.Close() - statusCode = httpResponse.StatusCode - } - - if err != nil { - err = galasaErrors.NewGalasaErrorWithHttpStatusCode(statusCode, galasaErrors.GALASA_ERROR_QUERY_RUNS_FAILED, err.Error()) - } else { - if statusCode != http.StatusOK { - httpError := "\nhttp response status code: " + strconv.Itoa(statusCode) - errString := httpError - err = galasaErrors.NewGalasaErrorWithHttpStatusCode(statusCode, galasaErrors.GALASA_ERROR_QUERY_RUNS_FAILED, errString) - } else { - - log.Printf("HTTP status was OK") - - // Copy the results from this page into our bigger list of results. - log.Printf("runsOnThisPage: %v", len(runData.GetRuns())) - } - } - return runData, err + log.Printf("Getting details for run %v\n", runId) + details, httpResponse, err = apiClient.ResultArchiveStoreAPIApi.GetRasRunById(context, runId).ClientApiVersion(restApiVersion).Execute() + + var statusCode int + if httpResponse != nil { + defer httpResponse.Body.Close() + statusCode = httpResponse.StatusCode + } + + if err != nil { + err = galasaErrors.NewGalasaErrorWithHttpStatusCode(statusCode, galasaErrors.GALASA_ERROR_QUERY_RUNS_FAILED, err.Error()) + } else { + if statusCode != http.StatusOK { + err = galasaErrors.NewGalasaErrorWithHttpStatusCode(statusCode, galasaErrors.GALASA_ERROR_QUERY_RUNS_NON_OK_STATUS, strconv.Itoa(httpResponse.StatusCode)) + } + } + return details, err } // Retrieves test runs from the ecosystem API that match a given runName. @@ -295,60 +232,53 @@ func GetRunsFromRestApi( shouldGetActive bool, timeService spi.TimeService, apiClient *galasaapi.APIClient, + group string, ) ([]galasaapi.Run, error) { var err error var results []galasaapi.Run = make([]galasaapi.Run, 0) - now := timeService.Now() - fromTime := now.Add(-(time.Duration(fromAgeMins) * time.Minute)).UTC() // Add a minus, so subtract - - toTime := now.Add(-(time.Duration(toAgeMins) * time.Minute)).UTC() // Add a minus, so subtract - var pageNumberWanted int32 = 1 gotAllResults := false var restApiVersion string - var pageCursor string restApiVersion, err = embedded.GetGalasactlRestApiVersion() - if err == nil { + runsQuery := NewRunsQuery( + runName, + requestorParameter, + resultParameter, + group, + fromAgeMins, + toAgeMins, + shouldGetActive, + timeService.Now(), + ) + for !gotAllResults && err == nil { - log.Printf("Requesting page '%d' ", pageNumberWanted) + log.Printf("Requesting page '%d' ", pageNumberWanted) var runData *galasaapi.RunResults - runData, err = getRunsPageFromRestApi( - pageCursor, - runName, - requestorParameter, - resultParameter, - fromAgeMins, - toAgeMins, - fromTime, - toTime, - shouldGetActive, - apiClient, - restApiVersion, - ) - - if err == nil { - // Add all the runs into our set of results. - // Note: The ... syntax means 'all of the array', so they all get appended at once. - runsOnThisPage := runData.GetRuns() - results = append(results, runsOnThisPage...) - - log.Printf("total runs: %v", len(results)) - - // Have we processed the last page ? - if !runData.HasNextCursor() || len(runsOnThisPage) < int(runData.GetPageSize()) { - gotAllResults = true - } else { - pageCursor = runData.GetNextCursor() - pageNumberWanted++ - } - } + runData, err = runsQuery.GetRunsPageFromRestApi(apiClient, restApiVersion) + + if err == nil { + // Add all the runs into our set of results. + // Note: The ... syntax means 'all of the array', so they all get appended at once. + runsOnThisPage := runData.GetRuns() + results = append(results, runsOnThisPage...) + + log.Printf("total runs: %v", len(results)) + + // Have we processed the last page ? + if !runData.HasNextCursor() || len(runsOnThisPage) < int(runData.GetPageSize()) { + gotAllResults = true + } else { + runsQuery.SetPageCursor(runData.GetNextCursor()) + pageNumberWanted++ + } + } } } diff --git a/pkg/runs/runsGet_test.go b/pkg/runs/runsGet_test.go index bc7b8638..e92cc766 100644 --- a/pkg/runs/runsGet_test.go +++ b/pkg/runs/runsGet_test.go @@ -28,8 +28,9 @@ const ( "testName": "myTestPackage.MyTestName", "testShortName": "MyTestName", "requestor": "unitTesting", - "status" : "Finished", - "result" : "Passed", + "status": "Finished", + "result": "Passed", + "group": "dummyGroup", "queued" : "2023-05-10T06:00:13.043037Z", "startTime": "2023-05-10T06:00:36.159003Z", "endTime": "2023-05-10T06:02:53.823338Z", @@ -89,7 +90,7 @@ const ( "pageSize": 1, "amountOfRuns": 0, "runs":[] - }` + }` ) func NewRunsGetServletMock(t *testing.T, status int, nextPageCursors []string, pages map[string][]string, pageSize int, runName string, runResultStrings ...string) *httptest.Server { @@ -239,14 +240,15 @@ func TestRunsGetOfRunNameWhichExistsProducesExpectedSummary(t *testing.T) { // Given ... pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456 } - nextPageCursors := []string{ "" } + pages[""] = []string{RUN_U456} + nextPageCursors := []string{""} runName := "U456" age := "2d:24h" requestor := "" result := "" pageSize := 100 + group := "" server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) shouldGetActive := false @@ -260,7 +262,7 @@ func TestRunsGetOfRunNameWhichExistsProducesExpectedSummary(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then... // We expect @@ -270,8 +272,8 @@ func TestRunsGetOfRunNameWhichExistsProducesExpectedSummary(t *testing.T) { textGotBack := mockConsole.ReadText() assert.Contains(t, textGotBack, runName) want := - "submitted-time(UTC) name requestor status result test-name\n" + - "2023-05-10 06:00:13 U456 unitTesting Finished Passed myTestPackage.MyTestName\n" + + "submitted-time(UTC) name requestor status result test-name group\n" + + "2023-05-10 06:00:13 U456 unitTesting Finished Passed myTestPackage.MyTestName dummyGroup\n" + "\n" + "Total:1 Passed:1\n" assert.Equal(t, want, textGotBack) @@ -283,11 +285,12 @@ func TestRunsGetOfRunNameWhichDoesNotExistProducesError(t *testing.T) { age := "2d:24h" runName := "garbage" pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456 } - nextPageCursors := []string{ "" } + pages[""] = []string{RUN_U456} + nextPageCursors := []string{""} requestor := "" result := "" shouldGetActive := false + group := "" pageSize := 100 server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) @@ -301,7 +304,7 @@ func TestRunsGetOfRunNameWhichDoesNotExistProducesError(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then... // We expect @@ -316,14 +319,15 @@ func TestRunsGetOfRunNameWhichDoesNotExistProducesError(t *testing.T) { func TestRunsGetWhereRunNameExistsTwiceProducesTwoRunResultLines(t *testing.T) { // Given ... pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456, RUN_U456_v2 } - nextPageCursors := []string{ "" } + pages[""] = []string{RUN_U456, RUN_U456_v2} + nextPageCursors := []string{""} age := "" runName := "U456" requestor := "" result := "" shouldGetActive := false pageSize := 100 + group := "" server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) defer server.Close() @@ -335,7 +339,7 @@ func TestRunsGetWhereRunNameExistsTwiceProducesTwoRunResultLines(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then... // We expect @@ -345,9 +349,9 @@ func TestRunsGetWhereRunNameExistsTwiceProducesTwoRunResultLines(t *testing.T) { textGotBack := mockConsole.ReadText() assert.Contains(t, textGotBack, runName) want := - "submitted-time(UTC) name requestor status result test-name\n" + - "2023-05-10 06:00:13 U456 unitTesting Finished Passed myTestPackage.MyTestName\n" + - "2023-05-10 06:00:13 U456 unitTesting22 Finished LongResultString myTestPackage.MyTest2\n" + + "submitted-time(UTC) name requestor status result test-name group\n" + + "2023-05-10 06:00:13 U456 unitTesting Finished Passed myTestPackage.MyTestName dummyGroup\n" + + "2023-05-10 06:00:13 U456 unitTesting22 Finished LongResultString myTestPackage.MyTest2 \n" + "\n" + "Total:2 Passed:1\n" assert.Equal(t, textGotBack, want) @@ -373,9 +377,10 @@ func TestFailingGetRunsRequestReturnsError(t *testing.T) { apiServerUrl := server.URL apiClient := api.InitialiseAPI(apiServerUrl) mockTimeService := utils.NewMockTimeService() + group := "" // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then... assert.Contains(t, err.Error(), "GAL1075") @@ -394,13 +399,14 @@ func TestRunsGetOfRunNameWhichExistsProducesExpectedDetails(t *testing.T) { // Given ... pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456 } - nextPageCursors := []string{ "" } + pages[""] = []string{RUN_U456} + nextPageCursors := []string{""} age := "" runName := "U456" requestor := "" result := "" shouldGetActive := false + group := "" pageSize := 100 server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName, RUN_U456) @@ -414,7 +420,7 @@ func TestRunsGetOfRunNameWhichExistsProducesExpectedDetails(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then... // We expect @@ -434,6 +440,7 @@ func TestRunsGetOfRunNameWhichExistsProducesExpectedDetails(t *testing.T) { "test-name : myTestPackage.MyTestName\n" + "requestor : unitTesting\n" + "bundle : myBundleId\n" + + "group : dummyGroup\n" + "run-log : " + apiServerUrl + "/ras/runs/xxx876xxx/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -458,8 +465,9 @@ func TestGetFormatterNamesStringMultipleFormattersFormatsOk(t *testing.T) { func TestAPIInternalErrorIsHandledOk(t *testing.T) { // Given ... pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456 } - nextPageCursors := []string{ "" } + pages[""] = []string{RUN_U456} + nextPageCursors := []string{""} + group := "" age := "" runName := "U456" requestor := "" @@ -478,7 +486,7 @@ func TestAPIInternalErrorIsHandledOk(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then... // We expect @@ -491,14 +499,15 @@ func TestRunsGetOfRunNameWhichExistsProducesExpectedRaw(t *testing.T) { // Given ... pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456 } - nextPageCursors := []string{ "" } + pages[""] = []string{RUN_U456} + nextPageCursors := []string{""} age := "" runName := "U456" requestor := "" result := "" shouldGetActive := false pageSize := 100 + group := "" server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) defer server.Close() @@ -511,14 +520,14 @@ func TestRunsGetOfRunNameWhichExistsProducesExpectedRaw(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then... // We expect assert.Nil(t, err) textGotBack := mockConsole.ReadText() assert.Contains(t, textGotBack, runName) - want := "U456|Finished|Passed|2023-05-10T06:00:13.043037Z|2023-05-10T06:00:36.159003Z|2023-05-10T06:02:53.823338Z|137664|myTestPackage.MyTestName|unitTesting|myBundleId|" + apiServerUrl + "/ras/runs/xxx876xxx/runlog\n" + want := "U456|Finished|Passed|2023-05-10T06:00:13.043037Z|2023-05-10T06:00:36.159003Z|2023-05-10T06:02:53.823338Z|137664|myTestPackage.MyTestName|unitTesting|myBundleId|dummyGroup|" + apiServerUrl + "/ras/runs/xxx876xxx/runlog\n" assert.Equal(t, textGotBack, want) } @@ -625,6 +634,7 @@ func TestRunsGetURLQueryWithFromAndToDate(t *testing.T) { requestor := "" result := "" shouldGetActive := false + group := "" server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() @@ -646,7 +656,7 @@ func TestRunsGetURLQueryWithFromAndToDate(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) @@ -659,6 +669,7 @@ func TestRunsGetURLQueryJustFromAge(t *testing.T) { requestor := "" result := "" shouldGetActive := false + group := "" server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() @@ -679,7 +690,7 @@ func TestRunsGetURLQueryJustFromAge(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) @@ -692,6 +703,7 @@ func TestRunsGetURLQueryWithNoRunNameAndNoFromAgeReturnsError(t *testing.T) { requestor := "" result := "" shouldGetActive := false + group := "" server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() @@ -712,7 +724,7 @@ func TestRunsGetURLQueryWithNoRunNameAndNoFromAgeReturnsError(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.NotNil(t, err) @@ -726,6 +738,7 @@ func TestRunsGetURLQueryWithOlderToAgeThanFromAgeReturnsError(t *testing.T) { requestor := "" result := "" shouldGetActive := false + group := "" server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() @@ -746,7 +759,7 @@ func TestRunsGetURLQueryWithOlderToAgeThanFromAgeReturnsError(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.NotNil(t, err) @@ -760,6 +773,7 @@ func TestRunsGetURLQueryWithBadlyFormedFromAndToParameterReturnsError(t *testing requestor := "" result := "" shouldGetActive := false + group := "" server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() @@ -780,7 +794,7 @@ func TestRunsGetURLQueryWithBadlyFormedFromAndToParameterReturnsError(t *testing mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.NotNil(t, err) @@ -945,6 +959,7 @@ func TestRunsGetURLQueryWithRequestorNotSuppliedReturnsOK(t *testing.T) { requestor := "" result := "" shouldGetActive := false + group := "" server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() @@ -969,7 +984,7 @@ func TestRunsGetURLQueryWithRequestorNotSuppliedReturnsOK(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) @@ -982,6 +997,7 @@ func TestRunsGetURLQueryWithRequestorSuppliedReturnsOK(t *testing.T) { requestor := "User123" result := "" shouldGetActive := false + group := "" server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() @@ -1004,7 +1020,7 @@ func TestRunsGetURLQueryWithRequestorSuppliedReturnsOK(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) @@ -1017,6 +1033,7 @@ func TestRunsGetURLQueryWithNumericRequestorSuppliedReturnsOK(t *testing.T) { requestor := "9876543210" result := "" shouldGetActive := false + group := "" server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() @@ -1039,7 +1056,7 @@ func TestRunsGetURLQueryWithNumericRequestorSuppliedReturnsOK(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) @@ -1052,6 +1069,7 @@ func TestRunsGetURLQueryWithDashInRequestorSuppliedReturnsOK(t *testing.T) { requestor := "User-123" result := "" shouldGetActive := false + group := "" server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() @@ -1074,7 +1092,7 @@ func TestRunsGetURLQueryWithDashInRequestorSuppliedReturnsOK(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) @@ -1087,6 +1105,7 @@ func TestRunsGetURLQueryWithAmpersandRequestorSuppliedReturnsOK(t *testing.T) { requestor := "User&123" result := "" shouldGetActive := false + group := "" server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() @@ -1109,7 +1128,7 @@ func TestRunsGetURLQueryWithAmpersandRequestorSuppliedReturnsOK(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) @@ -1122,6 +1141,7 @@ func TestRunsGetURLQueryWithSpecialCharactersRequestorSuppliedReturnsOK(t *testi requestor := "User&!@£$%^&*(){}#/',." result := "" shouldGetActive := false + group := "" server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() @@ -1145,7 +1165,7 @@ func TestRunsGetURLQueryWithSpecialCharactersRequestorSuppliedReturnsOK(t *testi mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) @@ -1154,14 +1174,15 @@ func TestRunsGetURLQueryWithSpecialCharactersRequestorSuppliedReturnsOK(t *testi func TestRunsGetURLQueryWithResultSuppliedReturnsOK(t *testing.T) { // Given ... pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456 } - nextPageCursors := []string{ "" } + pages[""] = []string{RUN_U456} + nextPageCursors := []string{""} age := "" runName := "U456" requestor := "" result := "Passed" shouldGetActive := false pageSize := 100 + group := "" server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) defer server.Close() @@ -1174,7 +1195,7 @@ func TestRunsGetURLQueryWithResultSuppliedReturnsOK(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) @@ -1185,14 +1206,15 @@ func TestRunsGetURLQueryWithResultSuppliedReturnsOK(t *testing.T) { func TestRunsGetURLQueryWithMultipleResultSuppliedReturnsOK(t *testing.T) { // Given ... pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456 } - nextPageCursors := []string{ "" } + pages[""] = []string{RUN_U456} + nextPageCursors := []string{""} age := "" runName := "U456" requestor := "" result := "Passed,envfail" shouldGetActive := false pageSize := 100 + group := "" server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) defer server.Close() @@ -1206,7 +1228,7 @@ func TestRunsGetURLQueryWithMultipleResultSuppliedReturnsOK(t *testing.T) { // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) @@ -1217,13 +1239,14 @@ func TestRunsGetURLQueryWithMultipleResultSuppliedReturnsOK(t *testing.T) { func TestRunsGetURLQueryWithResultNotSuppliedReturnsOK(t *testing.T) { // Given ... pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456 } - nextPageCursors := []string{ "" } + pages[""] = []string{RUN_U456} + nextPageCursors := []string{""} age := "" runName := "U456" requestor := "" result := "" shouldGetActive := false + group := "" pageSize := 100 server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) @@ -1237,7 +1260,7 @@ func TestRunsGetURLQueryWithResultNotSuppliedReturnsOK(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) @@ -1246,14 +1269,15 @@ func TestRunsGetURLQueryWithResultNotSuppliedReturnsOK(t *testing.T) { func TestRunsGetURLQueryWithInvalidResultSuppliedReturnsError(t *testing.T) { // Given ... pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456 } - nextPageCursors := []string{ "" } + pages[""] = []string{RUN_U456} + nextPageCursors := []string{""} age := "" runName := "U456" requestor := "" result := "garbage" shouldGetActive := false pageSize := 100 + group := "" server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) defer server.Close() @@ -1266,7 +1290,7 @@ func TestRunsGetURLQueryWithInvalidResultSuppliedReturnsError(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Error(t, err) @@ -1277,14 +1301,15 @@ func TestRunsGetURLQueryWithInvalidResultSuppliedReturnsError(t *testing.T) { func TestActiveAndResultAreMutuallyExclusiveShouldReturnError(t *testing.T) { // Given ... pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456 } - nextPageCursors := []string{ "" } + pages[""] = []string{RUN_U456} + nextPageCursors := []string{""} age := "" runName := "U456" requestor := "" result := "Passed" shouldGetActive := true pageSize := 100 + group := "" server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) defer server.Close() @@ -1297,7 +1322,7 @@ func TestActiveAndResultAreMutuallyExclusiveShouldReturnError(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Error(t, err) @@ -1307,14 +1332,15 @@ func TestActiveAndResultAreMutuallyExclusiveShouldReturnError(t *testing.T) { func TestActiveParameterReturnsOk(t *testing.T) { // Given ... pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456 } - nextPageCursors := []string{ "" } + pages[""] = []string{RUN_U456} + nextPageCursors := []string{""} age := "" runName := "U456" requestor := "" result := "" shouldGetActive := true pageSize := 100 + group := "" server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) defer server.Close() @@ -1327,7 +1353,7 @@ func TestActiveParameterReturnsOk(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) @@ -1340,6 +1366,7 @@ func TestRunsGetActiveRunsBuildsQueryCorrectly(t *testing.T) { requestor := "tester" result := "" shouldGetActive := true + group := "" mockEnv := utils.NewMockEnv() mockEnv.SetUserName(requestor) @@ -1365,21 +1392,20 @@ func TestRunsGetActiveRunsBuildsQueryCorrectly(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then ... assert.Nil(t, err) } - func TestRunsGetWithNextCursorGetsNextPageOfRuns(t *testing.T) { // Given ... pages := make(map[string][]string, 0) - pages[""] = []string{ RUN_U456 } - pages["page2"] = []string{ RUN_U456 } + pages[""] = []string{RUN_U456} + pages["page2"] = []string{RUN_U456} pages["page3"] = []string{} - nextPageCursors := []string{ "page2", "page3" } + nextPageCursors := []string{"page2", "page3"} age := "" runName := "U456" @@ -1387,6 +1413,7 @@ func TestRunsGetWithNextCursorGetsNextPageOfRuns(t *testing.T) { result := "" shouldGetActive := false pageSize := 1 + group := "" server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) defer server.Close() @@ -1399,14 +1426,85 @@ func TestRunsGetWithNextCursorGetsNextPageOfRuns(t *testing.T) { mockTimeService := utils.NewMockTimeService() // When... - err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, mockTimeService, mockConsole, apiServerUrl, apiClient) + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) // Then... assert.Nil(t, err) runsReturned := mockConsole.ReadText() assert.Contains(t, runsReturned, runName) - run := "U456|Finished|Passed|2023-05-10T06:00:13.043037Z|2023-05-10T06:00:36.159003Z|2023-05-10T06:02:53.823338Z|137664|myTestPackage.MyTestName|unitTesting|myBundleId|" + apiServerUrl + "/ras/runs/xxx876xxx/runlog\n" + run := "U456|Finished|Passed|2023-05-10T06:00:13.043037Z|2023-05-10T06:00:36.159003Z|2023-05-10T06:02:53.823338Z|137664|myTestPackage.MyTestName|unitTesting|myBundleId|dummyGroup|" + apiServerUrl + "/ras/runs/xxx876xxx/runlog\n" expectedResults := run + run assert.Equal(t, runsReturned, expectedResults) } + +func TestRunsGetOfGroupWhichExistsProducesExpectedRaw(t *testing.T) { + + // Given ... + pages := make(map[string][]string, 0) + pages[""] = []string{RUN_U456} + nextPageCursors := []string{""} + age := "" + runName := "U456" + requestor := "" + result := "" + shouldGetActive := false + pageSize := 100 + group := "dummyGroup" + + server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) + defer server.Close() + + outputFormat := "raw" + mockConsole := utils.NewMockConsole() + + apiServerUrl := server.URL + apiClient := api.InitialiseAPI(apiServerUrl) + mockTimeService := utils.NewMockTimeService() + + // When... + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) + + // Then... + // We expect + assert.Nil(t, err) + textGotBack := mockConsole.ReadText() + assert.Contains(t, textGotBack, runName) + want := "U456|Finished|Passed|2023-05-10T06:00:13.043037Z|2023-05-10T06:00:36.159003Z|2023-05-10T06:02:53.823338Z|137664|myTestPackage.MyTestName|unitTesting|myBundleId|dummyGroup|" + apiServerUrl + "/ras/runs/xxx876xxx/runlog\n" + assert.Equal(t, textGotBack, want) +} + +func TestRunsGetWithBadGroupNameThrowsError(t *testing.T) { + + // Given ... + pages := make(map[string][]string, 0) + pages[""] = []string{} + nextPageCursors := []string{ "" } + + runName := "U457" + age := "" + requestor := "" + result := "" + shouldGetActive := false + pageSize := 100 + outputFormat := "raw" + + group := string(rune(300)) + "NONLATIN1" + + server := NewRunsGetServletMock(t, http.StatusOK, nextPageCursors, pages, pageSize, runName) + defer server.Close() + + mockConsole := utils.NewMockConsole() + + apiServerUrl := server.URL + apiClient := api.InitialiseAPI(apiServerUrl) + mockTimeService := utils.NewMockTimeService() + + // When... + err := GetRuns(runName, age, requestor, result, shouldGetActive, outputFormat, group, mockTimeService, mockConsole, apiServerUrl, apiClient) + + // Then... + assert.NotNil(t, err, "A non-Latin-1 group name should throw an error") + assert.ErrorContains(t, err, "GAL1105E") + assert.ErrorContains(t, err, "Invalid group name provided") +} \ No newline at end of file diff --git a/pkg/runs/runsQuery.go b/pkg/runs/runsQuery.go new file mode 100644 index 00000000..eab06b14 --- /dev/null +++ b/pkg/runs/runsQuery.go @@ -0,0 +1,122 @@ +/* + * Copyright contributors to the Galasa project + * + * SPDX-License-Identifier: EPL-2.0 + */ +package runs + +import ( + "context" + "log" + "net/http" + "strconv" + "time" + + galasaErrors "github.com/galasa-dev/cli/pkg/errors" + "github.com/galasa-dev/cli/pkg/galasaapi" +) + +type RunsQuery struct { + pageCursor string + runName string + requestor string + result string + group string + fromTime time.Time + toTime time.Time + shouldGetActive bool +} + +func NewRunsQuery( + runName string, + requestor string, + result string, + group string, + fromAgeMins int, + toAgeMins int, + shouldGetActive bool, + now time.Time, +) *RunsQuery { + runsQuery := &RunsQuery{ + runName: runName, + requestor: requestor, + result: result, + group: group, + shouldGetActive: shouldGetActive, + } + + if fromAgeMins != 0 { + runsQuery.fromTime = now.Add(-(time.Duration(fromAgeMins) * time.Minute)).UTC() // Add a minus, so subtract + } + + if toAgeMins != 0 { + runsQuery.toTime = now.Add(-(time.Duration(toAgeMins) * time.Minute)).UTC() // Add a minus, so subtract + } + + return runsQuery +} + +func (query *RunsQuery) SetPageCursor(newPageCursor string) { + query.pageCursor = newPageCursor +} + +func (query *RunsQuery) GetRunsPageFromRestApi( + apiClient *galasaapi.APIClient, + restApiVersion string, +) (*galasaapi.RunResults, error) { + var err error + var runData *galasaapi.RunResults + var httpResponse *http.Response + var context context.Context = nil + + apicall := apiClient.ResultArchiveStoreAPIApi.GetRasSearchRuns(context).ClientApiVersion(restApiVersion).IncludeCursor("true") + if !query.fromTime.IsZero() { + apicall = apicall.From(query.fromTime) + } + if !query.toTime.IsZero() { + apicall = apicall.To(query.toTime) + } + if query.runName != "" { + apicall = apicall.Runname(query.runName) + } + if query.requestor != "" { + apicall = apicall.Requestor(query.requestor) + } + if query.result != "" { + apicall = apicall.Result(query.result) + } + if query.shouldGetActive { + apicall = apicall.Status(activeStatusNames) + } + if query.pageCursor != "" { + apicall = apicall.Cursor(query.pageCursor) + } + if query.group != "" { + apicall = apicall.Group(query.group) + } + apicall = apicall.Sort("from:desc") + runData, httpResponse, err = apicall.Execute() + + var statusCode int + if httpResponse != nil { + defer httpResponse.Body.Close() + statusCode = httpResponse.StatusCode + } + + if err != nil { + err = galasaErrors.NewGalasaErrorWithHttpStatusCode(statusCode, galasaErrors.GALASA_ERROR_QUERY_RUNS_FAILED, err.Error()) + } else { + if statusCode != http.StatusOK { + httpError := "\nhttp response status code: " + strconv.Itoa(statusCode) + errString := httpError + err = galasaErrors.NewGalasaErrorWithHttpStatusCode(statusCode, galasaErrors.GALASA_ERROR_QUERY_RUNS_FAILED, errString) + } else { + + log.Printf("HTTP status was OK") + + // Copy the results from this page into our bigger list of results. + log.Printf("runsOnThisPage: %v", len(runData.GetRuns())) + } + } + return runData, err +} diff --git a/pkg/runs/submitter.go b/pkg/runs/submitter.go index 3dd04590..84b6827e 100644 --- a/pkg/runs/submitter.go +++ b/pkg/runs/submitter.go @@ -347,6 +347,7 @@ func (submitter *Submitter) submitRun( if err == nil { submittedRun := resultGroup.GetRuns()[0] + nextRun.Group = *submittedRun.Group nextRun.Name = *submittedRun.Name submittedRuns[nextRun.Name] = &nextRun diff --git a/pkg/runs/yamlReporter_test.go b/pkg/runs/yamlReporter_test.go index a74ab09c..0dc8320a 100644 --- a/pkg/runs/yamlReporter_test.go +++ b/pkg/runs/yamlReporter_test.go @@ -19,18 +19,18 @@ func TestYamlReportWorks(t *testing.T) { mockFileSystem := files.NewMockFileSystem() finishedRuns := TestRun{ - Name: "myTestRun", - Bundle: "myBundle", - Class: "com.myco.MyClass", - Stream: "myStream", - Obr: "myObr", - Status: "myStatus", - QueuedTimeUTC: "", - Requestor: "me", - Result: "PASSED", - Overrides: make(map[string]string, 1), - Tests: []TestMethod{{Method: "method1", Result: "passed"}, {Method: "method2", Result: "passed"}}, - GherkinUrl: "file:///my.feature", + Name: "myTestRun", + Bundle: "myBundle", + Class: "com.myco.MyClass", + Stream: "myStream", + Obr: "myObr", + Status: "myStatus", + QueuedTimeUTC: "", + Requestor: "me", + Result: "PASSED", + Overrides: make(map[string]string, 1), + Tests: []TestMethod{{Method: "method1", Result: "passed"}, {Method: "method2", Result: "passed"}}, + GherkinUrl: "file:///my.feature", GherkinFeature: "my", } @@ -73,7 +73,8 @@ func TestYamlReportWorks(t *testing.T) { - name: method2 result: passed gherkin: file:///my.feature - feature: my` + feature: my + group:""` actualContents, err := mockFileSystem.ReadTextFile("myReportYamlFilename") if err != nil { diff --git a/pkg/runsformatter/detailsFormatter.go b/pkg/runsformatter/detailsFormatter.go index b1ad940c..5f6b7d9f 100644 --- a/pkg/runsformatter/detailsFormatter.go +++ b/pkg/runsformatter/detailsFormatter.go @@ -104,6 +104,7 @@ func tabulateCoreRunDetails(run FormattableTest) [][]string { {HEADER_TEST_NAME, ": " + run.TestName}, {HEADER_REQUESTOR, ": " + run.Requestor}, {HEADER_BUNDLE, ": " + run.Bundle}, + {HEADER_GROUP, ": " + run.Group}, {HEADER_RUN_LOG, ": " + run.ApiServerUrl + RAS_RUNS_URL + run.RunId + "/runlog"}, } return table diff --git a/pkg/runsformatter/detailsFormatter_test.go b/pkg/runsformatter/detailsFormatter_test.go index 643743d5..1b02ce59 100644 --- a/pkg/runsformatter/detailsFormatter_test.go +++ b/pkg/runsformatter/detailsFormatter_test.go @@ -42,19 +42,9 @@ func createFormattableTestForDetails(runId string, endTimeUTC string, apiServerUrl string, methods []galasaapi.TestMethod, - isLost bool) FormattableTest { - // runId := "" - // name := "" - // testName := "" - // status := "" - // result := "" - // startTimeUTC := "" - // endTimeUTC := "" - // queuedTimeUTC := "" - // requestor := "" - // bundle := "" - // apiServerUrl := "" - // isLost = false + isLost bool, + group string, +) FormattableTest { formattableTest := FormattableTest{ RunId: runId, Name: name, @@ -69,6 +59,7 @@ func createFormattableTestForDetails(runId string, ApiServerUrl: apiServerUrl, Methods: methods, Lost: isLost, + Group: group, } return formattableTest } @@ -97,7 +88,7 @@ func TestDetailsFormatterReturnsExpectedFormat(t *testing.T) { formattableTest := make([]FormattableTest, 0) formattableTest1 := createFormattableTestForDetails("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", - "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) + "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") formattableTest = append(formattableTest, formattableTest1) // When... @@ -115,6 +106,7 @@ func TestDetailsFormatterReturnsExpectedFormat(t *testing.T) { "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-123/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -133,9 +125,9 @@ func TestDetailsFormatterWithMultipleRunsReturnsSeparatedWithDashes(t *testing.T methods = append(methods, method1) formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForDetails("cbd-123", "U123", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest2 := createFormattableTestForDetails("cbd-456", "U456", "Finished", "Failed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest3 := createFormattableTestForDetails("cbd-789", "U789", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) + formattableTest1 := createFormattableTestForDetails("cbd-123", "U123", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest2 := createFormattableTestForDetails("cbd-456", "U456", "Finished", "Failed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest3 := createFormattableTestForDetails("cbd-789", "U789", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") formattableTest = append(formattableTest, formattableTest1, formattableTest2, formattableTest3) // When... @@ -153,6 +145,7 @@ func TestDetailsFormatterWithMultipleRunsReturnsSeparatedWithDashes(t *testing.T "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-123/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -170,6 +163,7 @@ func TestDetailsFormatterWithMultipleRunsReturnsSeparatedWithDashes(t *testing.T "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-456/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -187,6 +181,7 @@ func TestDetailsFormatterWithMultipleRunsReturnsSeparatedWithDashes(t *testing.T "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-789/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -205,7 +200,7 @@ func TestDetailsNoRunEndtimeReturnsBlankEndtimeFieldAndNoDuration(t *testing.T) methods = append(methods, method1) formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForDetails("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", methods, false) + formattableTest1 := createFormattableTestForDetails("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", methods, false, "none") formattableTest = append(formattableTest, formattableTest1) // When... @@ -223,6 +218,7 @@ func TestDetailsNoRunEndtimeReturnsBlankEndtimeFieldAndNoDuration(t *testing.T) "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-123/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -241,7 +237,7 @@ func TestMethodTableRendersOkIfNoEndtime(t *testing.T) { methods = append(methods, method1) formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForDetails("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) + formattableTest1 := createFormattableTestForDetails("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") formattableTest = append(formattableTest, formattableTest1) // When... @@ -259,6 +255,7 @@ func TestMethodTableRendersOkIfNoEndtime(t *testing.T) { "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-123/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -277,15 +274,15 @@ func TestDetailsFormatterMultipleRunsDifferentResultsProducesExpectedTotalsCount methods = append(methods, method1) formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForDetails("cbd-123", "U123", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest2 := createFormattableTestForDetails("cbd-456", "U456", "Finished", "Failed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest3 := createFormattableTestForDetails("cbd-789", "U789", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest4 := createFormattableTestForDetails("cbd-12345", "C123", "Finished", "Passed With Defects", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest5 := createFormattableTestForDetails("cbd-67890", "C456", "UNKNOWN", "EnvFail", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest6 := createFormattableTestForDetails("cbd-98765", "C789", "Finished", "Failed With Defects", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest7 := createFormattableTestForDetails("cbd-543210", "L111", "Finished", "Failed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest8 := createFormattableTestForDetails("cbd-222", "L222", "Building", "", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", methods, false) - formattableTest9 := createFormattableTestForDetails("cbd-333", "L333", "Generating", "", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", methods, false) + formattableTest1 := createFormattableTestForDetails("cbd-123", "U123", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest2 := createFormattableTestForDetails("cbd-456", "U456", "Finished", "Failed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest3 := createFormattableTestForDetails("cbd-789", "U789", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest4 := createFormattableTestForDetails("cbd-12345", "C123", "Finished", "Passed With Defects", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest5 := createFormattableTestForDetails("cbd-67890", "C456", "UNKNOWN", "EnvFail", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest6 := createFormattableTestForDetails("cbd-98765", "C789", "Finished", "Failed With Defects", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest7 := createFormattableTestForDetails("cbd-543210", "L111", "Finished", "Failed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest8 := createFormattableTestForDetails("cbd-222", "L222", "Building", "", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", methods, false, "none") + formattableTest9 := createFormattableTestForDetails("cbd-333", "L333", "Generating", "", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", methods, false, "none") formattableTest = append(formattableTest, formattableTest1, formattableTest2, formattableTest3, formattableTest4, formattableTest5, formattableTest6, formattableTest7, formattableTest8, formattableTest9) // When... @@ -303,6 +300,7 @@ func TestDetailsFormatterMultipleRunsDifferentResultsProducesExpectedTotalsCount "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-123/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -320,6 +318,7 @@ func TestDetailsFormatterMultipleRunsDifferentResultsProducesExpectedTotalsCount "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-456/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -337,6 +336,7 @@ func TestDetailsFormatterMultipleRunsDifferentResultsProducesExpectedTotalsCount "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-789/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -354,6 +354,7 @@ func TestDetailsFormatterMultipleRunsDifferentResultsProducesExpectedTotalsCount "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-12345/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -371,6 +372,7 @@ func TestDetailsFormatterMultipleRunsDifferentResultsProducesExpectedTotalsCount "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-67890/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -388,6 +390,7 @@ func TestDetailsFormatterMultipleRunsDifferentResultsProducesExpectedTotalsCount "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-98765/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -405,6 +408,7 @@ func TestDetailsFormatterMultipleRunsDifferentResultsProducesExpectedTotalsCount "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-543210/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -422,6 +426,7 @@ func TestDetailsFormatterMultipleRunsDifferentResultsProducesExpectedTotalsCount "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-222/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -439,6 +444,7 @@ func TestDetailsFormatterMultipleRunsDifferentResultsProducesExpectedTotalsCount "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-333/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -457,15 +463,15 @@ func TestDetailsFormatterMultipleRunsDoesNotDisplayLostRunsAndProducesExpectedTo methods = append(methods, method1) formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForDetails("cbd-123", "U123", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, true) - formattableTest2 := createFormattableTestForDetails("cbd-456", "U456", "Finished", "Failed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest3 := createFormattableTestForDetails("cbd-789", "U789", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, true) - formattableTest4 := createFormattableTestForDetails("cbd-12345", "C123", "Finished", "Passed With Defects", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest5 := createFormattableTestForDetails("cbd-67890", "C456", "UNKNOWN", "EnvFail", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, true) - formattableTest6 := createFormattableTestForDetails("cbd-98765", "C789", "Finished", "Failed With Defects", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest7 := createFormattableTestForDetails("cbd-543210", "L111", "Finished", "Failed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false) - formattableTest8 := createFormattableTestForDetails("cbd-222", "L222", "Building", "", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", methods, true) - formattableTest9 := createFormattableTestForDetails("cbd-333", "L333", "Generating", "", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", methods, false) + formattableTest1 := createFormattableTestForDetails("cbd-123", "U123", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, true, "none") + formattableTest2 := createFormattableTestForDetails("cbd-456", "U456", "Finished", "Failed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest3 := createFormattableTestForDetails("cbd-789", "U789", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, true, "none") + formattableTest4 := createFormattableTestForDetails("cbd-12345", "C123", "Finished", "Passed With Defects", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest5 := createFormattableTestForDetails("cbd-67890", "C456", "UNKNOWN", "EnvFail", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, true, "none") + formattableTest6 := createFormattableTestForDetails("cbd-98765", "C789", "Finished", "Failed With Defects", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest7 := createFormattableTestForDetails("cbd-543210", "L111", "Finished", "Failed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", methods, false, "none") + formattableTest8 := createFormattableTestForDetails("cbd-222", "L222", "Building", "", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", methods, true, "none") + formattableTest9 := createFormattableTestForDetails("cbd-333", "L333", "Generating", "", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", methods, false, "none") formattableTest = append(formattableTest, formattableTest1, formattableTest2, formattableTest3, formattableTest4, formattableTest5, formattableTest6, formattableTest7, formattableTest8, formattableTest9) // When... @@ -483,6 +489,7 @@ func TestDetailsFormatterMultipleRunsDoesNotDisplayLostRunsAndProducesExpectedTo "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-456/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -500,6 +507,7 @@ func TestDetailsFormatterMultipleRunsDoesNotDisplayLostRunsAndProducesExpectedTo "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-12345/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -517,6 +525,7 @@ func TestDetailsFormatterMultipleRunsDoesNotDisplayLostRunsAndProducesExpectedTo "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-98765/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -534,6 +543,7 @@ func TestDetailsFormatterMultipleRunsDoesNotDisplayLostRunsAndProducesExpectedTo "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-543210/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + @@ -551,6 +561,7 @@ func TestDetailsFormatterMultipleRunsDoesNotDisplayLostRunsAndProducesExpectedTo "test-name : dev.galasa.Zos3270LocalJava11Ubuntu\n" + "requestor : galasa\n" + "bundle : dev.galasa\n" + + "group : none\n" + "run-log : https://127.0.0.1/ras/runs/cbd-333/runlog\n" + "\n" + "method type status result start-time(UTC) end-time(UTC) duration(ms)\n" + diff --git a/pkg/runsformatter/rawFormatter.go b/pkg/runsformatter/rawFormatter.go index 7bf9bd8b..761195dc 100644 --- a/pkg/runsformatter/rawFormatter.go +++ b/pkg/runsformatter/rawFormatter.go @@ -55,6 +55,7 @@ func (*RawFormatter) FormatRuns(runs []FormattableTest) (string, error) { run.TestName + "|" + run.Requestor + "|" + run.Bundle + "|" + + run.Group + "|" + runLog, ) diff --git a/pkg/runsformatter/rawFormatter_test.go b/pkg/runsformatter/rawFormatter_test.go index e36916c5..048989f2 100644 --- a/pkg/runsformatter/rawFormatter_test.go +++ b/pkg/runsformatter/rawFormatter_test.go @@ -22,19 +22,9 @@ func createFormattableTestForRaw(runId string, startTimeUTC string, endTimeUTC string, apiServerUrl string, - isLost bool) FormattableTest { - // runId := "" - // name := "" - // testName := "" - // status := "" - // result := "" - // startTimeUTC := "" - // endTimeUTC := "" - // queuedTimeUTC := "" - // requestor := "" - // bundle := "" - // apiServerUrl := "" - // isLost := false + isLost bool, + group string, +) FormattableTest { formattableTest := FormattableTest{ RunId: runId, Name: name, @@ -47,6 +37,7 @@ func createFormattableTestForRaw(runId string, Requestor: requestor, Bundle: bundle, ApiServerUrl: apiServerUrl, + Group: group, Lost: isLost, } return formattableTest @@ -70,14 +61,14 @@ func TestRawFormatterReturnsExpectedFormat(t *testing.T) { formatter := NewRawFormatter() formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForRaw("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", false) + formattableTest1 := createFormattableTestForRaw("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", false, "none") formattableTest = append(formattableTest, formattableTest1) // When... actualFormattedOutput, err := formatter.FormatRuns(formattableTest) assert.Nil(t, err) - expectedFormattedOutput := "U456|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|2023-05-05T06:00:15.654565Z|1157|dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|https://127.0.0.1/ras/runs/cbd-123/runlog\n" + expectedFormattedOutput := "U456|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|2023-05-05T06:00:15.654565Z|1157|dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|none|https://127.0.0.1/ras/runs/cbd-123/runlog\n" assert.Equal(t, expectedFormattedOutput, actualFormattedOutput) } @@ -86,9 +77,9 @@ func TestRawFormatterWithMultipleFormattableTestsSeparatesWithNewLine(t *testing formatter := NewRawFormatter() formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForRaw("cbd-123", "U123", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", false) - formattableTest2 := createFormattableTestForRaw("cbd-456", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", false) - formattableTest3 := createFormattableTestForRaw("cbd-789", "U789", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", false) + formattableTest1 := createFormattableTestForRaw("cbd-123", "U123", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", false, "none") + formattableTest2 := createFormattableTestForRaw("cbd-456", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", false, "none") + formattableTest3 := createFormattableTestForRaw("cbd-789", "U789", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", false, "none") formattableTest = append(formattableTest, formattableTest1, formattableTest2, formattableTest3) // When... @@ -96,9 +87,9 @@ func TestRawFormatterWithMultipleFormattableTestsSeparatesWithNewLine(t *testing assert.Nil(t, err) expectedFormattedOutput := - "U123|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|2023-05-05T06:00:15.654565Z|1157|dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|https://127.0.0.1/ras/runs/cbd-123/runlog\n" + - "U456|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|2023-05-05T06:00:15.654565Z|1157|dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|https://127.0.0.1/ras/runs/cbd-456/runlog\n" + - "U789|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|2023-05-05T06:00:15.654565Z|1157|dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|https://127.0.0.1/ras/runs/cbd-789/runlog\n" + "U123|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|2023-05-05T06:00:15.654565Z|1157|dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|none|https://127.0.0.1/ras/runs/cbd-123/runlog\n" + + "U456|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|2023-05-05T06:00:15.654565Z|1157|dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|none|https://127.0.0.1/ras/runs/cbd-456/runlog\n" + + "U789|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|2023-05-05T06:00:15.654565Z|1157|dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|none|https://127.0.0.1/ras/runs/cbd-789/runlog\n" assert.Equal(t, expectedFormattedOutput, actualFormattedOutput) } @@ -106,14 +97,14 @@ func TestRawFormatterNoRunEndtimeReturnsBlankEndtimeFieldAndNoDuration(t *testin formatter := NewRawFormatter() formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForRaw("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", false) + formattableTest1 := createFormattableTestForRaw("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", false, "none") formattableTest = append(formattableTest, formattableTest1) // When... actualFormattedOutput, err := formatter.FormatRuns(formattableTest) assert.Nil(t, err) - expectedFormattedOutput := "U456|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|||dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|https://127.0.0.1/ras/runs/cbd-123/runlog\n" + expectedFormattedOutput := "U456|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|||dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|none|https://127.0.0.1/ras/runs/cbd-123/runlog\n" assert.Equal(t, expectedFormattedOutput, actualFormattedOutput) } @@ -122,8 +113,8 @@ func TestRawFormatterOnlyLostRunReturnsEmpty(t *testing.T) { formatter := NewRawFormatter() formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForRaw("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", true) - formattableTest2 := createFormattableTestForRaw("cbd-456", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", true) + formattableTest1 := createFormattableTestForRaw("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", true, "none") + formattableTest2 := createFormattableTestForRaw("cbd-456", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", true, "none") formattableTest = append(formattableTest, formattableTest1, formattableTest2) // When... @@ -140,20 +131,20 @@ func TestRawFormatterMultipleRunsPrintsOnlyFinishedRuns(t *testing.T) { formatter := NewRawFormatter() formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForRaw("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", true) - formattableTest2 := createFormattableTestForRaw("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", false) - formattableTest3 := createFormattableTestForRaw("cbd-456", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", true) - formattableTest4 := createFormattableTestForRaw("cbd-456", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", false) - formattableTest5 := createFormattableTestForRaw("cbd-789", "U789", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", false) + formattableTest1 := createFormattableTestForRaw("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", true, "none") + formattableTest2 := createFormattableTestForRaw("cbd-123", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "", "https://127.0.0.1", false, "none") + formattableTest3 := createFormattableTestForRaw("cbd-456", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", true, "none") + formattableTest4 := createFormattableTestForRaw("cbd-456", "U456", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", false, "none") + formattableTest5 := createFormattableTestForRaw("cbd-789", "U789", "Finished", "Passed", "dev.galasa", "dev.galasa.Zos3270LocalJava11Ubuntu", "galasa", "2023-05-04T10:55:29.545323Z", "2023-05-05T06:00:14.496953Z", "2023-05-05T06:00:15.654565Z", "https://127.0.0.1", false, "none") formattableTest = append(formattableTest, formattableTest1, formattableTest2, formattableTest3, formattableTest4, formattableTest5) // When... actualFormattedOutput, err := formatter.FormatRuns(formattableTest) assert.Nil(t, err) - expectedFormattedOutput := "U456|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|||dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|https://127.0.0.1/ras/runs/cbd-123/runlog\n" + - "U456|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|2023-05-05T06:00:15.654565Z|1157|dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|https://127.0.0.1/ras/runs/cbd-456/runlog\n" + - "U789|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|2023-05-05T06:00:15.654565Z|1157|dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|https://127.0.0.1/ras/runs/cbd-789/runlog\n" + expectedFormattedOutput := "U456|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|||dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|none|https://127.0.0.1/ras/runs/cbd-123/runlog\n" + + "U456|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|2023-05-05T06:00:15.654565Z|1157|dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|none|https://127.0.0.1/ras/runs/cbd-456/runlog\n" + + "U789|Finished|Passed|2023-05-04T10:55:29.545323Z|2023-05-05T06:00:14.496953Z|2023-05-05T06:00:15.654565Z|1157|dev.galasa.Zos3270LocalJava11Ubuntu|galasa|dev.galasa|none|https://127.0.0.1/ras/runs/cbd-789/runlog\n" assert.Equal(t, len(formattableTest), 5) assert.Equal(t, expectedFormattedOutput, actualFormattedOutput) diff --git a/pkg/runsformatter/runsFormatter.go b/pkg/runsformatter/runsFormatter.go index 77a8fe1e..55e62cc7 100644 --- a/pkg/runsformatter/runsFormatter.go +++ b/pkg/runsformatter/runsFormatter.go @@ -44,6 +44,7 @@ const ( HEADER_RUN_LOG = "run-log" HEADER_METHOD_NAME = "method" HEADER_METHOD_TYPE = "type" + HEADER_GROUP = "group" RAS_RUNS_URL = "/ras/runs/" ) @@ -62,6 +63,7 @@ type FormattableTest struct { Requestor string Bundle string ApiServerUrl string + Group string Methods []galasaapi.TestMethod Lost bool } diff --git a/pkg/runsformatter/summaryFormatter.go b/pkg/runsformatter/summaryFormatter.go index 86d3c706..4c399f7b 100644 --- a/pkg/runsformatter/summaryFormatter.go +++ b/pkg/runsformatter/summaryFormatter.go @@ -45,7 +45,7 @@ func (*SummaryFormatter) FormatRuns(testResultsData []FormattableTest) (string, if totalResults > 0 { var table [][]string - var headers = []string{HEADER_SUBMITTED_TIME, HEADER_RUNNAME, HEADER_REQUESTOR, HEADER_STATUS, HEADER_RESULT, HEADER_TEST_NAME} + var headers = []string{HEADER_SUBMITTED_TIME, HEADER_RUNNAME, HEADER_REQUESTOR, HEADER_STATUS, HEADER_RESULT, HEADER_TEST_NAME, HEADER_GROUP} table = append(table, headers) for _, run := range testResultsData { @@ -58,7 +58,7 @@ func (*SummaryFormatter) FormatRuns(testResultsData []FormattableTest) (string, accumulateResults(resultCountsMap, run) - line = append(line, submittedTimeReadable, run.Name, run.Requestor, run.Status, run.Result, run.TestName) + line = append(line, submittedTimeReadable, run.Name, run.Requestor, run.Status, run.Result, run.TestName, run.Group) table = append(table, line) } } diff --git a/pkg/runsformatter/summaryFormatter_test.go b/pkg/runsformatter/summaryFormatter_test.go index 15f1a5e4..6aed9af4 100644 --- a/pkg/runsformatter/summaryFormatter_test.go +++ b/pkg/runsformatter/summaryFormatter_test.go @@ -25,26 +25,24 @@ func TestSummaryFormatterNoDataReturnsTotalCountAllZeros(t *testing.T) { assert.Equal(t, expectedFormattedOutput, actualFormattedOutput) } -func createFormattableTestForSummary(queuedTimeUTC string, name string, testName string, status string, result string, requestor string, isLost bool) FormattableTest { - // run1Id := "ar" - // bundle := "" - // testName := "" - // requestor := "" - // queued := "" - // startTime := "" - // endTime := "" - // isLost := false +func createFormattableTestForSummary( + queuedTimeUTC string, + name string, + testName string, + status string, + result string, + requestor string, + isLost bool, + group string, +) FormattableTest { formattableTest := FormattableTest{ Name: name, - //Bundle: &bundle, - //TestName: &testName, TestName: testName, Requestor: requestor, Status: status, Result: result, QueuedTimeUTC: queuedTimeUTC, - // StartTime: &startTime, - // EndTime: &endTime, + Group: group, Lost: isLost, } return formattableTest @@ -54,7 +52,7 @@ func TestSummaryFormatterLongResultStringReturnsExpectedFormat(t *testing.T) { formatter := NewSummaryFormatter() formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U456", "MyTestName", "Finished", "MyLongResultString", "myUserId1", false) + formattableTest1 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U456", "MyTestName", "Finished", "MyLongResultString", "myUserId1", false, "none") formattableTest = append(formattableTest, formattableTest1) // When... @@ -62,8 +60,8 @@ func TestSummaryFormatterLongResultStringReturnsExpectedFormat(t *testing.T) { assert.Nil(t, err) expectedFormattedOutput := - "submitted-time(UTC) name requestor status result test-name\n" + - "2023-05-04 10:55:29 U456 myUserId1 Finished MyLongResultString MyTestName\n" + + "submitted-time(UTC) name requestor status result test-name group\n" + + "2023-05-04 10:55:29 U456 myUserId1 Finished MyLongResultString MyTestName none\n" + "\n" + "Total:1\n" assert.Equal(t, expectedFormattedOutput, actualFormattedOutput) @@ -73,7 +71,7 @@ func TestSummaryFormatterShortResultStringReturnsExpectedFormat(t *testing.T) { formatter := NewSummaryFormatter() formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U456", "MyTestName", "Finished", "Short", "myUserId1", false) + formattableTest1 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U456", "MyTestName", "Finished", "Short", "myUserId1", false, "none") formattableTest = append(formattableTest, formattableTest1) // When... @@ -81,8 +79,8 @@ func TestSummaryFormatterShortResultStringReturnsExpectedFormat(t *testing.T) { assert.Nil(t, err) expectedFormattedOutput := - "submitted-time(UTC) name requestor status result test-name\n" + - "2023-05-04 10:55:29 U456 myUserId1 Finished Short MyTestName\n" + + "submitted-time(UTC) name requestor status result test-name group\n" + + "2023-05-04 10:55:29 U456 myUserId1 Finished Short MyTestName none\n" + "\n" + "Total:1\n" assert.Equal(t, expectedFormattedOutput, actualFormattedOutput) @@ -92,8 +90,8 @@ func TestSummaryFormatterShortAndLongStatusReturnsExpectedFormat(t *testing.T) { formatter := NewSummaryFormatter() formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForSummary("2023-05-04T10:45:29.545323Z", "LongRunName", "TestName", "LongStatus", "Short", "myUserId1", false) - formattableTest2 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U456", "MyTestName", "short", "MyLongResultString", "myUserId1", false) + formattableTest1 := createFormattableTestForSummary("2023-05-04T10:45:29.545323Z", "LongRunName", "TestName", "LongStatus", "Short", "myUserId1", false, "none") + formattableTest2 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U456", "MyTestName", "short", "MyLongResultString", "myUserId1", false, "none") formattableTest = append(formattableTest, formattableTest1, formattableTest2) // When... @@ -101,9 +99,9 @@ func TestSummaryFormatterShortAndLongStatusReturnsExpectedFormat(t *testing.T) { assert.Nil(t, err) expectedFormattedOutput := - "submitted-time(UTC) name requestor status result test-name\n" + - "2023-05-04 10:45:29 LongRunName myUserId1 LongStatus Short TestName\n" + - "2023-05-04 10:55:29 U456 myUserId1 short MyLongResultString MyTestName\n" + + "submitted-time(UTC) name requestor status result test-name group\n" + + "2023-05-04 10:45:29 LongRunName myUserId1 LongStatus Short TestName none\n" + + "2023-05-04 10:55:29 U456 myUserId1 short MyLongResultString MyTestName none\n" + "\n" + "Total:2\n" assert.Equal(t, expectedFormattedOutput, actualFormattedOutput) @@ -113,15 +111,15 @@ func TestSummaryFormatterWithMultipleRunsPrintsOnlyFinishedRuns(t *testing.T) { formatter := NewSummaryFormatter() formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForSummary("2023-05-04T10:45:29.545323Z", "U123", "TestName", "Finished", "Passed", "myUserId1", false) - formattableTest2 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U456", "MyTestName1", "Finished", "Failed", "myUserId2", false) - formattableTest3 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U789", "MyTestName2", "Finished", "EnvFail", "myUserId1", false) - formattableTest4 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L123", "MyTestName3", "UNKNOWN", "", "myUserId2", false) - formattableTest5 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L456", "MyTestName4", "Building", "EnvFail", "myUserId1", false) - formattableTest6 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L789", "MyTestName5", "Finished", "Passed With Defects", "myUserId2", false) - formattableTest7 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C111", "MyTestName6", "Finished", "Failed", "myUserId1", false) - formattableTest8 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C222", "MyTestName7", "Finished", "UNKNOWN", "myUserId2", false) - formattableTest9 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C333", "MyTestName8", "Finished", "Ignored", "myUserId1", false) + formattableTest1 := createFormattableTestForSummary("2023-05-04T10:45:29.545323Z", "U123", "TestName", "Finished", "Passed", "myUserId1", false, "none") + formattableTest2 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U456", "MyTestName1", "Finished", "Failed", "myUserId2", false, "none") + formattableTest3 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U789", "MyTestName2", "Finished", "EnvFail", "myUserId1", false, "none") + formattableTest4 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L123", "MyTestName3", "UNKNOWN", "", "myUserId2", false, "none") + formattableTest5 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L456", "MyTestName4", "Building", "EnvFail", "myUserId1", false, "none") + formattableTest6 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L789", "MyTestName5", "Finished", "Passed With Defects", "myUserId2", false, "none") + formattableTest7 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C111", "MyTestName6", "Finished", "Failed", "myUserId1", false, "none") + formattableTest8 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C222", "MyTestName7", "Finished", "UNKNOWN", "myUserId2", false, "none") + formattableTest9 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C333", "MyTestName8", "Finished", "Ignored", "myUserId1", false, "none") formattableTest = append(formattableTest, formattableTest1, formattableTest2, formattableTest3, formattableTest4, formattableTest5, formattableTest6, formattableTest7, formattableTest8, formattableTest9) // When... @@ -129,16 +127,16 @@ func TestSummaryFormatterWithMultipleRunsPrintsOnlyFinishedRuns(t *testing.T) { assert.Nil(t, err) expectedFormattedOutput := - "submitted-time(UTC) name requestor status result test-name\n" + - "2023-05-04 10:45:29 U123 myUserId1 Finished Passed TestName\n" + - "2023-05-04 10:55:29 U456 myUserId2 Finished Failed MyTestName1\n" + - "2023-05-04 10:55:29 U789 myUserId1 Finished EnvFail MyTestName2\n" + - "2023-05-04 10:55:29 L123 myUserId2 UNKNOWN MyTestName3\n" + - "2023-05-04 10:55:29 L456 myUserId1 Building EnvFail MyTestName4\n" + - "2023-05-04 10:55:29 L789 myUserId2 Finished Passed With Defects MyTestName5\n" + - "2023-05-04 10:55:29 C111 myUserId1 Finished Failed MyTestName6\n" + - "2023-05-04 10:55:29 C222 myUserId2 Finished UNKNOWN MyTestName7\n" + - "2023-05-04 10:55:29 C333 myUserId1 Finished Ignored MyTestName8\n" + + "submitted-time(UTC) name requestor status result test-name group\n" + + "2023-05-04 10:45:29 U123 myUserId1 Finished Passed TestName none\n" + + "2023-05-04 10:55:29 U456 myUserId2 Finished Failed MyTestName1 none\n" + + "2023-05-04 10:55:29 U789 myUserId1 Finished EnvFail MyTestName2 none\n" + + "2023-05-04 10:55:29 L123 myUserId2 UNKNOWN MyTestName3 none\n" + + "2023-05-04 10:55:29 L456 myUserId1 Building EnvFail MyTestName4 none\n" + + "2023-05-04 10:55:29 L789 myUserId2 Finished Passed With Defects MyTestName5 none\n" + + "2023-05-04 10:55:29 C111 myUserId1 Finished Failed MyTestName6 none\n" + + "2023-05-04 10:55:29 C222 myUserId2 Finished UNKNOWN MyTestName7 none\n" + + "2023-05-04 10:55:29 C333 myUserId1 Finished Ignored MyTestName8 none\n" + "\n" + "Total:9 Passed:1 PassedWithDefects:1 Failed:2 EnvFail:2 UNKNOWN:1 Active:1 Ignored:1\n" assert.Equal(t, expectedFormattedOutput, actualFormattedOutput) @@ -148,15 +146,15 @@ func TestSummaryFormatterMultipleRunsWithLostRunsDoesNotDisplayLostRunsAndCounts formatter := NewSummaryFormatter() formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForSummary("2023-05-04T10:45:29.545323Z", "U123", "TestName", "Finished", "Passed", "myUserId1", false) - formattableTest2 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U456", "MyTestName1", "Finished", "Failed", "myUserId2", true) - formattableTest3 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U789", "MyTestName2", "Finished", "EnvFail", "myUserId1", true) - formattableTest4 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L123", "MyTestName3", "UNKNOWN", "", "myUserId2", false) - formattableTest5 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L456", "MyTestName4", "Building", "EnvFail", "myUserId1", false) - formattableTest6 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L789", "MyTestName5", "Finished", "Passed With Defects", "myUserId2", false) - formattableTest7 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C111", "MyTestName6", "Finished", "Failed", "myUserId1", false) - formattableTest8 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C222", "MyTestName7", "Finished", "UNKNOWN", "myUserId2", false) - formattableTest9 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C333", "MyTestName8", "Finished", "Ignored", "myUserId1", true) + formattableTest1 := createFormattableTestForSummary("2023-05-04T10:45:29.545323Z", "U123", "TestName", "Finished", "Passed", "myUserId1", false, "none") + formattableTest2 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U456", "MyTestName1", "Finished", "Failed", "myUserId2", true, "none") + formattableTest3 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U789", "MyTestName2", "Finished", "EnvFail", "myUserId1", true, "none") + formattableTest4 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L123", "MyTestName3", "UNKNOWN", "", "myUserId2", false, "none") + formattableTest5 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L456", "MyTestName4", "Building", "EnvFail", "myUserId1", false, "none") + formattableTest6 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L789", "MyTestName5", "Finished", "Passed With Defects", "myUserId2", false, "none") + formattableTest7 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C111", "MyTestName6", "Finished", "Failed", "myUserId1", false, "none") + formattableTest8 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C222", "MyTestName7", "Finished", "UNKNOWN", "myUserId2", false, "none") + formattableTest9 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C333", "MyTestName8", "Finished", "Ignored", "myUserId1", true, "none") //formattableTest10 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L321", "MyTestName9", "UNKNOWN", "", "myUserId2", true) formattableTest = append(formattableTest, formattableTest1, formattableTest2, formattableTest3, formattableTest4, formattableTest5, formattableTest6, formattableTest7, formattableTest8, formattableTest9) @@ -165,13 +163,13 @@ func TestSummaryFormatterMultipleRunsWithLostRunsDoesNotDisplayLostRunsAndCounts assert.Nil(t, err) expectedFormattedOutput := - "submitted-time(UTC) name requestor status result test-name\n" + - "2023-05-04 10:45:29 U123 myUserId1 Finished Passed TestName\n" + - "2023-05-04 10:55:29 L123 myUserId2 UNKNOWN MyTestName3\n" + - "2023-05-04 10:55:29 L456 myUserId1 Building EnvFail MyTestName4\n" + - "2023-05-04 10:55:29 L789 myUserId2 Finished Passed With Defects MyTestName5\n" + - "2023-05-04 10:55:29 C111 myUserId1 Finished Failed MyTestName6\n" + - "2023-05-04 10:55:29 C222 myUserId2 Finished UNKNOWN MyTestName7\n" + + "submitted-time(UTC) name requestor status result test-name group\n" + + "2023-05-04 10:45:29 U123 myUserId1 Finished Passed TestName none\n" + + "2023-05-04 10:55:29 L123 myUserId2 UNKNOWN MyTestName3 none\n" + + "2023-05-04 10:55:29 L456 myUserId1 Building EnvFail MyTestName4 none\n" + + "2023-05-04 10:55:29 L789 myUserId2 Finished Passed With Defects MyTestName5 none\n" + + "2023-05-04 10:55:29 C111 myUserId1 Finished Failed MyTestName6 none\n" + + "2023-05-04 10:55:29 C222 myUserId2 Finished UNKNOWN MyTestName7 none\n" + "\n" + "Total:9 Passed:1 PassedWithDefects:1 Failed:1 Lost:3 EnvFail:1 UNKNOWN:1 Active:1\n" @@ -182,16 +180,16 @@ func TestSummaryFormatterMultipleRunsWithUnknownStatusOfLostRunsDoesNotDisplayLo formatter := NewSummaryFormatter() formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForSummary("2023-05-04T10:45:29.545323Z", "U123", "TestName", "Finished", "Passed", "myUserId1", false) - formattableTest2 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U456", "MyTestName1", "Finished", "Failed", "myUserId2", true) - formattableTest3 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U789", "MyTestName2", "Finished", "EnvFail", "myUserId1", true) - formattableTest4 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L123", "MyTestName3", "UNKNOWN", "", "myUserId2", false) - formattableTest5 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L456", "MyTestName4", "Building", "EnvFail", "myUserId1", false) - formattableTest6 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L789", "MyTestName5", "Finished", "Passed With Defects", "myUserId2", false) - formattableTest7 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C111", "MyTestName6", "Finished", "Failed", "myUserId1", false) - formattableTest8 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C222", "MyTestName7", "Finished", "UNKNOWN", "myUserId2", false) - formattableTest9 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C333", "MyTestName8", "Finished", "Ignored", "myUserId1", true) - formattableTest10 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L321", "MyTestName9", "UNKNOWN", "", "myUserId2", true) + formattableTest1 := createFormattableTestForSummary("2023-05-04T10:45:29.545323Z", "U123", "TestName", "Finished", "Passed", "myUserId1", false, "none") + formattableTest2 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U456", "MyTestName1", "Finished", "Failed", "myUserId2", true, "none") + formattableTest3 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "U789", "MyTestName2", "Finished", "EnvFail", "myUserId1", true, "none") + formattableTest4 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L123", "MyTestName3", "UNKNOWN", "", "myUserId2", false, "none") + formattableTest5 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L456", "MyTestName4", "Building", "EnvFail", "myUserId1", false, "none") + formattableTest6 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L789", "MyTestName5", "Finished", "Passed With Defects", "myUserId2", false, "none") + formattableTest7 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C111", "MyTestName6", "Finished", "Failed", "myUserId1", false, "none") + formattableTest8 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C222", "MyTestName7", "Finished", "UNKNOWN", "myUserId2", false, "none") + formattableTest9 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "C333", "MyTestName8", "Finished", "Ignored", "myUserId1", true, "none") + formattableTest10 := createFormattableTestForSummary("2023-05-04T10:55:29.545323Z", "L321", "MyTestName9", "UNKNOWN", "", "myUserId2", true, "none") formattableTest = append(formattableTest, formattableTest1, formattableTest2, formattableTest3, formattableTest4, formattableTest5, formattableTest6, formattableTest7, formattableTest8, formattableTest9, formattableTest10) // When... @@ -199,13 +197,13 @@ func TestSummaryFormatterMultipleRunsWithUnknownStatusOfLostRunsDoesNotDisplayLo assert.Nil(t, err) expectedFormattedOutput := - "submitted-time(UTC) name requestor status result test-name\n" + - "2023-05-04 10:45:29 U123 myUserId1 Finished Passed TestName\n" + - "2023-05-04 10:55:29 L123 myUserId2 UNKNOWN MyTestName3\n" + - "2023-05-04 10:55:29 L456 myUserId1 Building EnvFail MyTestName4\n" + - "2023-05-04 10:55:29 L789 myUserId2 Finished Passed With Defects MyTestName5\n" + - "2023-05-04 10:55:29 C111 myUserId1 Finished Failed MyTestName6\n" + - "2023-05-04 10:55:29 C222 myUserId2 Finished UNKNOWN MyTestName7\n" + + "submitted-time(UTC) name requestor status result test-name group\n" + + "2023-05-04 10:45:29 U123 myUserId1 Finished Passed TestName none\n" + + "2023-05-04 10:55:29 L123 myUserId2 UNKNOWN MyTestName3 none\n" + + "2023-05-04 10:55:29 L456 myUserId1 Building EnvFail MyTestName4 none\n" + + "2023-05-04 10:55:29 L789 myUserId2 Finished Passed With Defects MyTestName5 none\n" + + "2023-05-04 10:55:29 C111 myUserId1 Finished Failed MyTestName6 none\n" + + "2023-05-04 10:55:29 C222 myUserId2 Finished UNKNOWN MyTestName7 none\n" + "\n" + "Total:10 Passed:1 PassedWithDefects:1 Failed:1 Lost:4 EnvFail:1 UNKNOWN:1 Active:1\n" @@ -216,7 +214,7 @@ func TestSummaryFormatterHasTestWithoutTimeStamps(t *testing.T) { formatter := NewSummaryFormatter() formattableTest := make([]FormattableTest, 0) - formattableTest1 := createFormattableTestForSummary("", "U123", "TestName", "Finished", "Passed", "myUserId1", false) + formattableTest1 := createFormattableTestForSummary("", "U123", "TestName", "Finished", "Passed", "myUserId1", false, "none") formattableTest = append(formattableTest, formattableTest1) // When... @@ -224,8 +222,8 @@ func TestSummaryFormatterHasTestWithoutTimeStamps(t *testing.T) { assert.Nil(t, err) expectedFormattedOutput := - "submitted-time(UTC) name requestor status result test-name\n" + - " U123 myUserId1 Finished Passed TestName\n" + + "submitted-time(UTC) name requestor status result test-name group\n" + + " U123 myUserId1 Finished Passed TestName none\n" + "\n" + "Total:1 Passed:1\n" diff --git a/pkg/secrets/secrets.go b/pkg/secrets/secrets.go index 8a4374d8..c380b760 100644 --- a/pkg/secrets/secrets.go +++ b/pkg/secrets/secrets.go @@ -7,16 +7,17 @@ package secrets import ( - "strings" + "strings" - galasaErrors "github.com/galasa-dev/cli/pkg/errors" + galasaErrors "github.com/galasa-dev/cli/pkg/errors" + "github.com/galasa-dev/cli/pkg/utils" ) func validateSecretName(secretName string) (string, error) { var err error secretName = strings.TrimSpace(secretName) - if secretName == "" || strings.ContainsAny(secretName, " .\n\t") || !isLatin1(secretName) { + if secretName == "" || !utils.IsNameValid(secretName) { err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_INVALID_SECRET_NAME) } return secretName, err @@ -26,21 +27,8 @@ func validateDescription(description string) (string, error) { var err error description = strings.TrimSpace(description) - if description == "" || !isLatin1(description) { + if description == "" || !utils.IsLatin1(description) { err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_INVALID_SECRET_DESCRIPTION) } return description, err } - -// Checks if a given string contains only characters in the Latin-1 character set (codepoints 0-255), -// returning true if so, and false otherwise -func isLatin1(str string) bool { - isValidLatin1 := true - for _, character := range str { - if character > 255 { - isValidLatin1 = false - break - } - } - return isValidLatin1 -} diff --git a/pkg/utils/validationUtils.go b/pkg/utils/validationUtils.go new file mode 100644 index 00000000..158bc51c --- /dev/null +++ b/pkg/utils/validationUtils.go @@ -0,0 +1,55 @@ +/* + * Copyright contributors to the Galasa project + * + * SPDX-License-Identifier: EPL-2.0 + */ +package utils + +// Checks if a given string contains only characters in the Latin-1 character set (codepoints 0-255), +// returning true if so, and false otherwise +func IsLatin1(str string) bool { + isValidLatin1 := true + for _, character := range str { + if character > 255 { + isValidLatin1 = false + break + } + } + return isValidLatin1 +} + +// IsNameValid - Checks if a given string used as a name for a structure (e.g. role, secret, group, etc.) +// only contains the following characters: +// - Alphanumeric characters (a-z, A-Z, 0-9) +// - Dashes (-) +// - Underscores (_) +func IsNameValid(name string) bool { + isValid := true + for _, character := range name { + if !(IsCharacterAlphanumeric(character) || + (character == '-') || + (character == '_')) { + isValid = false + break + } + } + return isValid +} + +// IsAlphanumeric - Checks if a given string contains only alphanumeric characters +func IsAlphanumeric(str string) bool { + isValid := true + for _, character := range str { + if !IsCharacterAlphanumeric(character) { + isValid = false + break + } + } + return isValid +} + +func IsCharacterAlphanumeric(character rune) bool { + return (character >= 'a' && character <= 'z') || + (character >= 'A' && character <= 'Z') || + (character >= '0' && character <= '9') +} diff --git a/test-galasactl-ecosystem.sh b/test-galasactl-ecosystem.sh index 74cd729e..984a072b 100755 --- a/test-galasactl-ecosystem.sh +++ b/test-galasactl-ecosystem.sh @@ -89,14 +89,14 @@ fi info "Running tests against ecosystem bootstrap ${bootstrap}" -#----------------------------------------------------------------------------------------- +#----------------------------------------------------------------------------------------- # Constants -#----------------------------------------------------------------------------------------- +#----------------------------------------------------------------------------------------- export GALASA_TEST_NAME_SHORT="local.CoreLocalJava11Ubuntu" export GALASA_TEST_NAME_LONG="dev.galasa.inttests.core.${GALASA_TEST_NAME_SHORT}" export GALASA_TEST_RUN_GET_EXPECTED_SUMMARY_LINE_COUNT="4" -export GALASA_TEST_RUN_GET_EXPECTED_DETAILS_LINE_COUNT="13" -export GALASA_TEST_RUN_GET_EXPECTED_RAW_PIPE_COUNT="10" +export GALASA_TEST_RUN_GET_EXPECTED_DETAILS_LINE_COUNT="14" +export GALASA_TEST_RUN_GET_EXPECTED_RAW_PIPE_COUNT="11" export GALASA_TEST_RUN_GET_EXPECTED_NUMBER_ARTIFACT_RUNNING_COUNT="10" CALLED_BY_MAIN="true" diff --git a/test-scripts/calculate-galasactl-executables.sh b/test-scripts/calculate-galasactl-executables.sh index 0ea94bfe..a30545f7 100755 --- a/test-scripts/calculate-galasactl-executables.sh +++ b/test-scripts/calculate-galasactl-executables.sh @@ -70,17 +70,6 @@ fi info "Running tests against ecosystem bootstrap ${bootstrap}" -#----------------------------------------------------------------------------------------- -# Constants -#----------------------------------------------------------------------------------------- -export GALASA_TEST_NAME_SHORT="local.CoreLocalJava11Ubuntu" -export GALASA_TEST_NAME_LONG="dev.galasa.inttests.core.${GALASA_TEST_NAME_SHORT}" -export GALASA_TEST_RUN_GET_EXPECTED_SUMMARY_LINE_COUNT="4" -export GALASA_TEST_RUN_GET_EXPECTED_DETAILS_LINE_COUNT="13" -export GALASA_TEST_RUN_GET_EXPECTED_RAW_PIPE_COUNT="10" -export GALASA_TEST_RUN_GET_EXPECTED_NUMBER_ARTIFACT_RUNNING_COUNT="10" - - function calculate_galasactl_executable { h2 "Calculate the name of the galasactl executable for this machine/os" diff --git a/test-scripts/gherkin-runs-tests.sh b/test-scripts/gherkin-runs-tests.sh index bc629263..4035d744 100644 --- a/test-scripts/gherkin-runs-tests.sh +++ b/test-scripts/gherkin-runs-tests.sh @@ -74,17 +74,6 @@ if [[ "$CALLED_BY_MAIN" == "" ]]; then fi info "Running tests against ecosystem bootstrap ${bootstrap}" - - #----------------------------------------------------------------------------------------- - # Constants - #----------------------------------------------------------------------------------------- - export GALASA_TEST_NAME_SHORT="local.CoreLocalJava11Ubuntu" - export GALASA_TEST_NAME_LONG="dev.galasa.inttests.core.${GALASA_TEST_NAME_SHORT}" - export GALASA_TEST_RUN_GET_EXPECTED_SUMMARY_LINE_COUNT="4" - export GALASA_TEST_RUN_GET_EXPECTED_DETAILS_LINE_COUNT="13" - export GALASA_TEST_RUN_GET_EXPECTED_RAW_PIPE_COUNT="10" - export GALASA_TEST_RUN_GET_EXPECTED_NUMBER_ARTIFACT_RUNNING_COUNT="10" - fi function SubmitLocalSimpleGherkinTest { diff --git a/test-scripts/properties-tests.sh b/test-scripts/properties-tests.sh index dd21c289..66c8d6fe 100755 --- a/test-scripts/properties-tests.sh +++ b/test-scripts/properties-tests.sh @@ -74,17 +74,6 @@ if [[ "$CALLED_BY_MAIN" == "" ]]; then fi info "Running tests against ecosystem bootstrap ${bootstrap}" - - #----------------------------------------------------------------------------------------- - # Constants - #----------------------------------------------------------------------------------------- - export GALASA_TEST_NAME_SHORT="local.CoreLocalJava11Ubuntu" - export GALASA_TEST_NAME_LONG="dev.galasa.inttests.core.${GALASA_TEST_NAME_SHORT}" - export GALASA_TEST_RUN_GET_EXPECTED_SUMMARY_LINE_COUNT="4" - export GALASA_TEST_RUN_GET_EXPECTED_DETAILS_LINE_COUNT="13" - export GALASA_TEST_RUN_GET_EXPECTED_RAW_PIPE_COUNT="10" - export GALASA_TEST_RUN_GET_EXPECTED_NUMBER_ARTIFACT_RUNNING_COUNT="10" - fi # generate a random number to append to test names to avoid multiple running at once overriding each other diff --git a/test-scripts/resources-tests.sh b/test-scripts/resources-tests.sh index eaa78fe2..59e327b6 100755 --- a/test-scripts/resources-tests.sh +++ b/test-scripts/resources-tests.sh @@ -74,17 +74,6 @@ if [[ "$CALLED_BY_MAIN" == "" ]]; then fi info "Running tests against ecosystem bootstrap ${bootstrap}" - - #----------------------------------------------------------------------------------------- - # Constants - #----------------------------------------------------------------------------------------- - export GALASA_TEST_NAME_SHORT="local.CoreLocalJava11Ubuntu" - export GALASA_TEST_NAME_LONG="dev.galasa.inttests.core.${GALASA_TEST_NAME_SHORT}" - export GALASA_TEST_RUN_GET_EXPECTED_SUMMARY_LINE_COUNT="4" - export GALASA_TEST_RUN_GET_EXPECTED_DETAILS_LINE_COUNT="13" - export GALASA_TEST_RUN_GET_EXPECTED_RAW_PIPE_COUNT="10" - export GALASA_TEST_RUN_GET_EXPECTED_NUMBER_ARTIFACT_RUNNING_COUNT="10" - fi # generate a random number to append to test names to avoid multiple running at once overriding each other diff --git a/test-scripts/runs-tests.sh b/test-scripts/runs-tests.sh index 79607bd4..f4117a27 100755 --- a/test-scripts/runs-tests.sh +++ b/test-scripts/runs-tests.sh @@ -81,8 +81,8 @@ if [[ "$CALLED_BY_MAIN" == "" ]]; then export GALASA_TEST_NAME_SHORT="local.CoreLocalJava11Ubuntu" export GALASA_TEST_NAME_LONG="dev.galasa.inttests.core.${GALASA_TEST_NAME_SHORT}" export GALASA_TEST_RUN_GET_EXPECTED_SUMMARY_LINE_COUNT="4" - export GALASA_TEST_RUN_GET_EXPECTED_DETAILS_LINE_COUNT="13" - export GALASA_TEST_RUN_GET_EXPECTED_RAW_PIPE_COUNT="10" + export GALASA_TEST_RUN_GET_EXPECTED_DETAILS_LINE_COUNT="14" + export GALASA_TEST_RUN_GET_EXPECTED_RAW_PIPE_COUNT="11" export GALASA_TEST_RUN_GET_EXPECTED_NUMBER_ARTIFACT_RUNNING_COUNT="10" fi @@ -100,6 +100,7 @@ function get_random_property_name_number { #----------------------------------------------------------------------------------------- function launch_test_on_ecosystem_with_portfolio { + group_name=$1 h2 "Building a portfolio..." mkdir -p ${BASEDIR}/temp @@ -134,6 +135,7 @@ function launch_test_on_ecosystem_with_portfolio { --poll 10 \ --progress 1 \ --noexitcodeontestfailures \ + --group ${group_name} \ --log -" info "Command is: $cmd" @@ -587,7 +589,7 @@ function runs_get_check_summary_format_output { fi # Check headers - headers=("submitted-time(UTC)" "name" "status" "result" "test-name") + headers=("submitted-time(UTC)" "name" "status" "result" "test-name" "group") for header in "${headers[@]}" do @@ -653,7 +655,7 @@ function runs_get_check_details_format_output { fi done - #check methods start on line 13 - implies other test details have outputted + #check methods start on line 14 - implies other test details have outputted line_count=$(grep -n "method[[:space:]]*type[[:space:]]*status[[:space:]]*result[[:space:]]*start-time(UTC)[[:space:]]*end-time(UTC)[[:space:]]*duration(ms)" $output_file | head -n1 | sed 's/:.*//') expected_line_count=$GALASA_TEST_RUN_GET_EXPECTED_DETAILS_LINE_COUNT if [[ "${line_count}" != "${expected_line_count}" ]]; then @@ -692,7 +694,7 @@ function runs_get_check_raw_format_output { exit 1 fi - # Check that we got 10 pipes + # Check that we got 11 pipes pipe_count=$(grep -o "|" $output_file | wc -l | xargs) expected_pipe_count=$GALASA_TEST_RUN_GET_EXPECTED_RAW_PIPE_COUNT if [[ "${pipe_count}" != "${expected_pipe_count}" ]]; then @@ -892,6 +894,65 @@ function runs_get_check_result_parameter { success "galasactl runs get with age parameter with just from value and result '$result' returned results okay." } +#-------------------------------------------------------------------------- +function runs_get_test_can_get_runs_by_group { + + group_name=$1 + h2 "Performing runs get with details format providing group name '${group_name}'..." + + cd ${BASEDIR}/temp + + cmd="${BINARY_LOCATION} runs get \ + --group ${group_name} \ + --format details \ + --bootstrap ${bootstrap}" + + info "Command is: $cmd" + + output_file="runs-get-output.txt" + $cmd | tee $output_file + + grep -q "group[ ]*:[ ]*${group_name}" $output_file + + rc=$? + + if [[ "${rc}" != "0" ]]; then + error "Did not find any runs with group name '${group_name}' in output" + exit 1 + fi + + success "galasactl runs get with group name '${group_name}' returned results OK." +} + +#-------------------------------------------------------------------------- +function runs_get_test_non_existant_group_returns_zero { + + group_name="non-existant-group" + h2 "Attempting to get runs by a non-existant group name '${group_name}'..." + + cd ${BASEDIR}/temp + + cmd="${BINARY_LOCATION} runs get \ + --group ${group_name} \ + --bootstrap ${bootstrap}" + + info "Command is: $cmd" + + output_file="runs-get-output.txt" + $cmd | tee $output_file + + grep -q "Total:0" $output_file + + rc=$? + + if [[ "${rc}" != "0" ]]; then + error "Found runs with group name '${group_name}' in output when there should not have been any results" + exit 1 + fi + + success "galasactl runs get with non-existant group name '${group_name}' returned no results as expected." +} + #-------------------------------------------------------------------------- function launch_test_on_ecosystem_without_portfolio { h2 "Launching test on an ecosystem... directly... without a portfolio." @@ -1052,13 +1113,16 @@ function test_runs_commands { launch_test_on_ecosystem_without_portfolio # Launch test on ecosystem from a portfolio ... - launch_test_on_ecosystem_with_portfolio + group_name="cli-ecosystem-tests" + launch_test_on_ecosystem_with_portfolio ${group_name} # Query the result ... setting RUN_NAME to hold the one which galasa allocated get_result_with_runname runs_get_check_summary_format_output $RUN_NAME runs_get_check_details_format_output $RUN_NAME runs_get_check_raw_format_output $RUN_NAME + runs_get_test_can_get_runs_by_group ${group_name} + runs_get_test_non_existant_group_returns_zero # Query the result with the age parameter runs_get_check_raw_format_output_with_from_and_to $RUN_NAME @@ -1072,8 +1136,6 @@ function test_runs_commands { runs_get_check_result_parameter # Unable to test 'to' age because the smallest time unit we support is Hours so would have to query a test that happened over an hour ago - - # Attempt to create a test portfolio with an unknown test ... create_portfolio_with_unknown_test