Skip to content

Commit

Permalink
Merge pull request #310 from galasa-dev/mcobbett-remove-duplicate-res…
Browse files Browse the repository at this point in the history
…ults-formatted

massive amounts of duplicates shown by formatter due to labels being duplicated
  • Loading branch information
techcobweb authored Dec 2, 2024
2 parents 61775d2 + 75e8eec commit 928090f
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 41 deletions.
33 changes: 29 additions & 4 deletions pkg/runs/runsConverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package runs

import (
"log"
"sort"

"github.com/galasa-dev/cli/pkg/galasaapi"
Expand All @@ -29,50 +30,74 @@ 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)
orderedResultLabels = append(orderedResultLabels, RESULT_FAILED_WITH_DEFECTS)
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
}

Expand Down
38 changes: 38 additions & 0 deletions pkg/runs/runsConverter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
12 changes: 12 additions & 0 deletions pkg/runs/runsGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand All @@ -285,6 +295,8 @@ func GetRunsFromRestApi(
}
}

log.Printf("total runs returned: %v", len(results))

return results, err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/runs/submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/runsformatter/summaryFormatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
*/
package runsformatter

import "strings"
import (
"log"
"strings"
)

// -----------------------------------------------------
// Summary format.
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/timedSleeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
8 changes: 6 additions & 2 deletions test-galasactl-ecosystem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
30 changes: 2 additions & 28 deletions test-scripts/auth-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=$?
Expand All @@ -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 {

Expand All @@ -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
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion test-scripts/runs-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 928090f

Please sign in to comment.