diff --git a/pkg/runs/runsConverter.go b/pkg/runs/runsConverter.go index 08090c35..3de4ddf7 100644 --- a/pkg/runs/runsConverter.go +++ b/pkg/runs/runsConverter.go @@ -6,6 +6,7 @@ package runs import ( + "log" "sort" "github.com/galasa-dev/cli/pkg/galasaapi" @@ -29,11 +30,17 @@ func orderFormattableTests(formattableTest []runsformatter.FormattableTest) []ru for _, result := range orderedResultLabels { orderedFormattableTest = append(orderedFormattableTest, runsGroupedByResultsMap[result]...) } + + // log.Printf("Returning %v test results\n", len(orderedFormattableTest)) return orderedFormattableTest } +// getAvailableResultLabelsinOrder - returns a slice of all available result labels in the order they should be displayed +// The order is important as it determines how the tests will be displayed on the screen +// The standard labels are shown first, followed by any extra labels present in the test data. +// These laels can be used as columns in the eventual output. func getAvailableResultLabelsinOrder(formattableTest []runsformatter.FormattableTest) []string { - var orderedResultLabels []string + var orderedResultLabels []string = make([]string, 0) orderedResultLabels = append(orderedResultLabels, RESULT_PASSED) orderedResultLabels = append(orderedResultLabels, RESULT_PASSED_WITH_DEFECTS) orderedResultLabels = append(orderedResultLabels, RESULT_FAILED) @@ -41,38 +48,56 @@ func getAvailableResultLabelsinOrder(formattableTest []runsformatter.Formattable orderedResultLabels = append(orderedResultLabels, RESULT_ENVFAIL) //Build a list of standard labels to prevent duplication - var standardResultLabels = make(map[string]struct{}) + var standardResultLabels = make(map[string]struct{}, 0) for _, key := range orderedResultLabels { //'struct{}{}' allocates no storage. In Go 1.19 we can use just '{}' instead standardResultLabels[key] = struct{}{} } + log.Printf("There are %v standard labels: %v\n", len(standardResultLabels), standardResultLabels) + //Gathering custom labels - var customResultLabels []string + var customResultLabels []string = make([]string, 0) + // A map to make sure we never add the same custom label to the list twice. + customResultLabelMap := make(map[string]string, 0) for _, run := range formattableTest { _, isStandardLabel := standardResultLabels[run.Result] if !isStandardLabel { - customResultLabels = append(customResultLabels, run.Result) + + _, isCustomLabelWeAlreadyKnowAbout := customResultLabelMap[run.Result] + if !isCustomLabelWeAlreadyKnowAbout { + log.Printf("Label '%v' is not a standard result label\n", run.Result) + customResultLabels = append(customResultLabels, run.Result) + customResultLabelMap[run.Result] = "known" + } } } sort.Strings(customResultLabels) orderedResultLabels = append(orderedResultLabels, customResultLabels...) + log.Printf("There are %v labels overall: %v", len(orderedResultLabels), orderedResultLabels) + return orderedResultLabels } func FormattableTestFromGalasaApi(runs []galasaapi.Run, apiServerUrl string) []runsformatter.FormattableTest { var formattableTest []runsformatter.FormattableTest + log.Printf("FormattableTestFromGalasaApi: There are %v runs passed\n", len(runs)) + for _, run := range runs { //Get the data for each TestStructure in runs newFormattableTest := getTestStructureData(run, apiServerUrl) formattableTest = append(formattableTest, newFormattableTest) } + log.Printf("FormattableTestFromGalasaApi: There are %v runs to format\n", len(formattableTest)) + orderedFormattableTest := orderFormattableTests(formattableTest) + log.Printf("FormattableTestFromGalasaApi: There are %v runs returned\n", len(orderedFormattableTest)) + return orderedFormattableTest } diff --git a/pkg/runs/runsConverter_test.go b/pkg/runs/runsConverter_test.go index 8c8ed509..81fe5b1c 100644 --- a/pkg/runs/runsConverter_test.go +++ b/pkg/runs/runsConverter_test.go @@ -436,3 +436,41 @@ func TestGherkinRunReturnsCorrectFormattableTestly(t *testing.T) { assert.Equal(t, "Passed", output.Result) assert.Equal(t, "myStatus", output.Status) } + +func TestGetAvailableResultLabelsInOrderWithNo2ExtraLabels(t *testing.T) { + testRun1 := runsformatter.FormattableTest{ + Name: "", + Bundle: "", + Status: "myStatus", + Result: "Passed", + } + testRun2 := runsformatter.FormattableTest{ + Name: "", + Bundle: "", + Status: "myStatus", + Result: "MyWeirdResultCode", + } + testRun3 := runsformatter.FormattableTest{ + Name: "", + Bundle: "", + Status: "myStatus", + Result: "MyWeirdResultalternativeCode", + } + testRun4 := runsformatter.FormattableTest{ + Name: "", + Bundle: "", + Status: "myStatus", + Result: "MyWeirdResultalternativeCode", + } + testRun5 := runsformatter.FormattableTest{ + Name: "", + Bundle: "", + Status: "myStatus", + Result: "MyWeirdResultalternativeCode", + } + testRunsArray := [5]runsformatter.FormattableTest{testRun1, testRun2, testRun3, testRun4, testRun5} + labelsGotBack := getAvailableResultLabelsinOrder(testRunsArray[:]) + + assert.NotEmpty(t, labelsGotBack) + assert.Equal(t, 7, len(labelsGotBack)) +} diff --git a/pkg/runs/runsGet.go b/pkg/runs/runsGet.go index d6fcc745..c37eac2a 100644 --- a/pkg/runs/runsGet.go +++ b/pkg/runs/runsGet.go @@ -89,12 +89,15 @@ func GetRuns( if err == nil { // Some formatters need extra fields filled-in so they can be displayed. if chosenFormatter.IsNeedingMethodDetails() { + log.Println("This type of formatter needs extra detail about each run to display") runJson, err = GetRunDetailsFromRasSearchRuns(runJson, apiClient) } if err == nil { var outputText string + log.Printf("There are %v results to display in total.\n", len(runJson)) + //convert galsaapi.Runs tests into formattable data formattableTest := FormattableTestFromGalasaApi(runJson, apiServerUrl) outputText, err = chosenFormatter.FormatRuns(formattableTest) @@ -179,6 +182,7 @@ func GetRunDetailsFromRasSearchRuns(runs []galasaapi.Run, apiClient *galasaapi.A for _, run := range runs { runid := run.GetRunId() + log.Printf("Getting details for run %v\n", runid) details, httpResponse, err = apiClient.ResultArchiveStoreAPIApi.GetRasRunById(context, runid).ClientApiVersion(restApiVersion).Execute() if err != nil { err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_QUERY_RUNS_FAILED, err.Error()) @@ -267,12 +271,18 @@ func GetRunsFromRestApi( err = galasaErrors.NewGalasaError(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. runsOnThisPage := runData.GetRuns() + log.Printf("runsOnThisPage: %v", len(runsOnThisPage)) + // Add all the runs into our set of results. // Note: The ... syntax means 'all of the array', so they all get appended at once. 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 @@ -285,6 +295,8 @@ func GetRunsFromRestApi( } } + log.Printf("total runs returned: %v", len(results)) + return results, err } diff --git a/pkg/runs/submitter.go b/pkg/runs/submitter.go index 2da5e607..c9096e38 100644 --- a/pkg/runs/submitter.go +++ b/pkg/runs/submitter.go @@ -200,9 +200,9 @@ func (submitter *Submitter) executeSubmitRuns( // Only sleep if there are runs in progress but not yet finished. if len(submittedRuns) > 0 || len(rerunRuns) > 0 { - log.Printf("Sleeping for the poll interval of %v seconds\n", params.PollIntervalSeconds) + // log.Printf("Sleeping for the poll interval of %v seconds\n", params.PollIntervalSeconds) submitter.timedSleeper.Sleep(pollInterval) - log.Printf("Awake from poll interval sleep of %v seconds\n", params.PollIntervalSeconds) + // log.Printf("Awake from poll interval sleep of %v Gathering test results under theseconds\n", params.PollIntervalSeconds) } } diff --git a/pkg/runsformatter/summaryFormatter.go b/pkg/runsformatter/summaryFormatter.go index 3fdf18fc..adaeb572 100644 --- a/pkg/runsformatter/summaryFormatter.go +++ b/pkg/runsformatter/summaryFormatter.go @@ -5,7 +5,10 @@ */ package runsformatter -import "strings" +import ( + "log" + "strings" +) // ----------------------------------------------------- // Summary format. @@ -29,12 +32,14 @@ func (*SummaryFormatter) IsNeedingMethodDetails() bool { } func (*SummaryFormatter) FormatRuns(testResultsData []FormattableTest) (string, error) { - var result string = "" + var result string var err error buff := strings.Builder{} totalResults := len(testResultsData) resultCountsMap := initialiseResultMap() + log.Printf("Formatter passed %v runs to show.\n", len(testResultsData)) + if totalResults > 0 { var table [][]string diff --git a/pkg/utils/timedSleeper.go b/pkg/utils/timedSleeper.go index 3a6fb3d5..08ebd7f9 100644 --- a/pkg/utils/timedSleeper.go +++ b/pkg/utils/timedSleeper.go @@ -40,13 +40,13 @@ func (ts *realTimedSleeper) Interrupt(message string) { // Sleep for a bit. Waking up if anything calls the interrupt method. func (ts *realTimedSleeper) Sleep(duration time.Duration) { - log.Printf("timeService: %v : sleep entered\n", *ts) + // log.Printf("timeService: %v : sleep entered\n", *ts) timer := time.After(duration) select { case msg := <-ts.interruptEventChannel: log.Printf("timeService: %v : received interrupt message %s\n", *ts, msg) case <-timer: - log.Printf("timeService: %v : sleep timed out\n", *ts) + // log.Printf("timeService: %v : sleep timed out\n", *ts) } } diff --git a/test-galasactl-ecosystem.sh b/test-galasactl-ecosystem.sh index f95d3414..74cd729e 100755 --- a/test-galasactl-ecosystem.sh +++ b/test-galasactl-ecosystem.sh @@ -102,9 +102,14 @@ export GALASA_TEST_RUN_GET_EXPECTED_NUMBER_ARTIFACT_RUNNING_COUNT="10" CALLED_BY_MAIN="true" # Bootstrap is in the $bootstrap variable. + + source ${BASEDIR}/test-scripts/calculate-galasactl-executables.sh calculate_galasactl_executable +source ${BASEDIR}/test-scripts/auth-tests.sh --bootstrap "${bootstrap}" +auth_tests + source ${BASEDIR}/test-scripts/runs-tests.sh --bootstrap "${bootstrap}" test_runs_commands @@ -114,8 +119,7 @@ properties_tests source ${BASEDIR}/test-scripts/resources-tests.sh --bootstrap "${bootstrap}" resources_tests -source ${BASEDIR}/test-scripts/auth-tests.sh --bootstrap "${bootstrap}" -auth_tests + # Test the hybrid configuration where the local test runs locally, but # draws it's CPS properties from a remote ecosystem via a REST extension. diff --git a/test-scripts/auth-tests.sh b/test-scripts/auth-tests.sh index 38dd11d3..82c300cf 100755 --- a/test-scripts/auth-tests.sh +++ b/test-scripts/auth-tests.sh @@ -92,7 +92,7 @@ function auth_tokens_get_all_tokens_without_loginId { " info "Command is: $cmd" - + mkdir -p $ORIGINAL_DIR/temp output_file="$ORIGINAL_DIR/temp/auth-get-output.txt" $cmd | tee $output_file rc=$? @@ -110,32 +110,6 @@ function auth_tokens_get_all_tokens_without_loginId { } -function auth_tokens_get_with_missing_loginId_throws_error { - - h2 "Performing auth tokens get with loginId: get..." - loginId="" - - cmd="${BINARY_LOCATION} auth tokens get \ - --user $loginId \ - --bootstrap $bootstrap \ - --log - - " - - info "Command is: $cmd" - - output_file="$ORIGINAL_DIR/temp/auth-get-output.txt" - set -o pipefail # Fail everything if anything in the pipeline fails. Else we are just checking the 'tee' return code. - $cmd | tee $output_file - - rc=$? - if [[ "${rc}" != "1" ]]; then - error "Failed to get access tokens due to missing login ID. Bad Request" - exit 1 - fi - - success "galasactl auth tokens get command correctly threw an error due to missing loginId" - -} function auth_tokens_get_all_tokens_by_loginId { @@ -151,6 +125,7 @@ function auth_tokens_get_all_tokens_by_loginId { " info "Command is: $cmd" + mkdir -p $ORIGINAL_DIR/temp output_file="$ORIGINAL_DIR/temp/auth-get-output.txt" $cmd | tee $output_file @@ -172,7 +147,6 @@ function auth_tokens_get_all_tokens_by_loginId { function auth_tests { auth_tokens_get_all_tokens_without_loginId - auth_tokens_get_with_missing_loginId_throws_error auth_tokens_get_all_tokens_by_loginId } diff --git a/test-scripts/runs-tests.sh b/test-scripts/runs-tests.sh index 85b6c0cc..79607bd4 100755 --- a/test-scripts/runs-tests.sh +++ b/test-scripts/runs-tests.sh @@ -834,7 +834,7 @@ function runs_get_check_raw_format_output_with_older_to_than_from_age { #-------------------------------------------------------------------------- function runs_get_check_requestor_parameter { - requestor="galasadelivery@ibm.com" + requestor="Galasadelivery@ibm.com" h2 "Performing runs get with details format providing a from age and requestor as $requestor..." cd ${BASEDIR}/temp